Changed update_patches script to use python for the bulk, Prevents making 1800 temporary useless files.
This commit is contained in:
parent
aa83f571c2
commit
114c534db4
3 changed files with 68 additions and 62 deletions
|
@ -3,49 +3,16 @@
|
|||
|
||||
set PATH=.\bin;%PATH%
|
||||
|
||||
echo Creating directories
|
||||
for /f %%i in ('find ../src_work -type d') do (
|
||||
set file=%%i
|
||||
set file=!file:~11!
|
||||
rem echo patches!file!
|
||||
"./bin/mkdir.exe" --parents "patches!file!"
|
||||
)
|
||||
echo Creating patches
|
||||
for /f %%i in ('find ../src_work -type f') do (
|
||||
set file=%%i
|
||||
set file=!file:~11!
|
||||
rem echo !file!
|
||||
if "!file:~-1!" NEQ "#" (
|
||||
if "!file:~-1!" NEQ "~" (
|
||||
diff -u ../src_base!file! ../src_work!file! -r --strip-trailing-cr --new-file | sed -e "1,2s/[0-9-]* [0-9:\.]* [+-][0-9]*\b/0000-00-00 00:00:00.000000000 -0000/" | tr -d \r > patches!file!.patch
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
echo Removing empty patches
|
||||
find patches -size 0 -type f -regex .+\.patch -delete
|
||||
for /f %%i in ('find patches -depth -empty -type d') do (
|
||||
set file=%%i
|
||||
if "!file:.svn=!" EQU "!file!" (
|
||||
rmdir "%%i"
|
||||
)
|
||||
)
|
||||
python update_patches.py
|
||||
|
||||
echo Grabbing copy of conf folder
|
||||
for /f %%i in ('find conf -type f') do (
|
||||
set file=%%i
|
||||
if "!file:.svn=!" EQU "!file!" (
|
||||
if %%i NEQ ".gitignore" (
|
||||
del !file:/=\!
|
||||
)
|
||||
)
|
||||
|
||||
for /f %%i in ('find conf -depth -empty -type d') do (
|
||||
set file=%%i
|
||||
if "!file:.svn=!" EQU "!file!" (
|
||||
rmdir "%%i"
|
||||
)
|
||||
)
|
||||
|
||||
xcopy ..\conf conf /E /I /Y
|
||||
tr -d \r < ../conf/mcp.cfg > conf/mcp.cfg
|
||||
tr -d \r < ../conf/patches/Start.java > conf/patches/Start.java
|
||||
|
|
63
forge/update_patches.py
Normal file
63
forge/update_patches.py
Normal file
|
@ -0,0 +1,63 @@
|
|||
import os
|
||||
import commands
|
||||
import fnmatch
|
||||
import re
|
||||
import subprocess, shlex
|
||||
|
||||
def cmdsplit(args):
|
||||
if os.sep == '\\':
|
||||
args = args.replace('\\', '\\\\')
|
||||
return shlex.split(args)
|
||||
|
||||
def cleanDirs(path):
|
||||
if not os.path.isdir(path):
|
||||
return
|
||||
|
||||
files = os.listdir(path)
|
||||
if len(files):
|
||||
for f in files:
|
||||
fullpath = os.path.join(path, f)
|
||||
if os.path.isdir(fullpath):
|
||||
cleanDirs(fullpath)
|
||||
|
||||
files = os.listdir(path)
|
||||
if len(files) == 0:
|
||||
os.rmdir(path)
|
||||
|
||||
def main():
|
||||
print Creating patches
|
||||
base = os.path.normpath(os.path.join('..', 'src_base'))
|
||||
work = os.path.normpath(os.path.join('..', 'src_work'))
|
||||
timestamp = re.compile(r'[0-9-]* [0-9:\.]* [+-][0-9]*\r?\n')
|
||||
|
||||
for path, _, filelist in os.walk(work, followlinks=True):
|
||||
for cur_file in fnmatch.filter(filelist, '*.java'):
|
||||
#print cur_file + " " + path[12:]
|
||||
file_base = os.path.normpath(os.path.join(base, path[12:], cur_file))
|
||||
file_work = os.path.normpath(os.path.join(work, path[12:], cur_file))
|
||||
patch = ''
|
||||
cmd = 'diff -u %s %s -r --strip-trailing-cr --new-file' % (file_base, file_work)
|
||||
process = subprocess.Popen(cmdsplit(cmd), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1)
|
||||
patch, _ = process.communicate()
|
||||
patch_dir = os.path.join('patches', path[12:])
|
||||
patch_file = os.path.join(patch_dir, cur_file + '.patch')
|
||||
|
||||
if len(patch) > 0:
|
||||
print patch_file
|
||||
patch = timestamp.sub("0000-00-00 00:00:00.000000000 -0000\n", patch)
|
||||
patch = patch.replace('\r\n', '\n')
|
||||
|
||||
if not os.path.exists(patch_dir):
|
||||
os.makedirs(patch_dir)
|
||||
with open(patch_file, 'w') as fh:
|
||||
fh.write(patch)
|
||||
else:
|
||||
if os.path.isfile(patch_file):
|
||||
print 'Deleting empty patch: ' + patch_file
|
||||
os.remove(patch_file)
|
||||
|
||||
|
||||
cleanDirs('patches')
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
|
@ -1,36 +1,12 @@
|
|||
echo Creating directories
|
||||
|
||||
fdir=$PWD
|
||||
cd ..
|
||||
|
||||
for i in `find src_work -type d`
|
||||
do
|
||||
mkdir --parents "$fdir/patches${i##src_work}"
|
||||
done
|
||||
|
||||
echo Creating patches
|
||||
|
||||
cd src_work
|
||||
for i in `find ../src_work -type f`
|
||||
do
|
||||
ibase=${i##../src_work}
|
||||
diff -u ../src_base$ibase $i -r --strip-trailing-cr --new-file | sed -e "1,2s/[0-9-]* [0-9:\.]* [+-][0-9]*\b/0000-00-00 00:00:00.000000000 -0000/" | tr -d "\r" > $fdir/patches$ibase.patch
|
||||
done
|
||||
cd ..
|
||||
|
||||
echo Removing empty patches
|
||||
find $fdir/patches -size 0 -type f -name \*.patch -delete
|
||||
for i in `find $fdir/patches -depth -empty -type d | grep -a -v "svn"`
|
||||
do
|
||||
rmdir "$i"
|
||||
done
|
||||
|
||||
python update_patches.py
|
||||
echo Grabbing copy of conf folder
|
||||
for i in `find $fdir/conf -type f | grep -a -v "svn"`
|
||||
for i in `find $fdir/conf -type f | grep -a -v ".gitignore"`
|
||||
do
|
||||
rm $i
|
||||
done
|
||||
for i in `find $fdir/conf -depth -empty -type d | grep -a -v "svn"`
|
||||
for i in `find $fdir/conf -depth -empty -type d | grep -a -v ".git"`
|
||||
do
|
||||
rmdir "$i"
|
||||
done
|
||||
|
|
Loading…
Reference in a new issue