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