Shell and Python compare different files in the directory

Source: Internet
Author: User
Tags diff git clone

Cat git_tar.py
Import Subprocess,tarfile,os
Def finds ():
tar = Tarfile.open ("test.tar.gz", "W:gz")
Result=subprocess.call (' Git diff 99gw 99gw_old>result.txt ', shell=true)
If Os.path.getsize (' Result.txt ')!=0:
File=open (' Result.txt ', ' R ')
For line in file:
Line=line.strip ()
If Line.startswith ("diff--git A/"):
Files=line.strip ()
Files=files.split () [2]
Files=files[2:]
Tar.add (Files)
File.close ()
Tar.close ()
Else
print ' Git not diff '

If name= = 'main':

finds()

Vim upgrade.sh
#git Clone Code.
Dirname=dirname $0
CD $dirName
[-D 99gw_old] | | echo "Error:99gw_old dir not exist."
git clone [email protected]:banghan/99gw.git

#diff dir 99GW and 99gw_old
Diff-urn 99GW 99gw_old |awk '/^diff-urn/{print $ ' > Diff.txt
For Var in $ (cat diff.txt);d o
dir=${var%/*}
[-D temp] | | Mkdir-p Temp
[-D temp/$dir] | | Mkdir-p temp/$dir
[-F $var] && \cp-p $var temp/$dir
Done

#rsyn diffed files to remote hosts.
Hosts= "
172.19.xx.xx
172.19.xx.xx
"
For host $hosts;d O
Rsync-avz-e ssh temp/99gw/* $host:/tmp/99gw_old/;
Done

#rename local git dir.
t=$ (Date +%y%m%d_%h%m%s)
MV 99GW old99GW$t && mv 99GW 99gw_old
[$?-ne 0] && echo "Directory rename error"

Shell and Python compare different files in the directory

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.