From 21afe2a2aaf20cc136d4e5c50de185ad9e08874e Mon Sep 17 00:00:00 2001 From: LexManos Date: Mon, 2 Apr 2012 01:09:00 -0700 Subject: [PATCH] Some cleanups to update_patches, should run properly on any system now. --- forge/update_patches.bat | 20 +------ forge/update_patches.py | 126 ++++++++++++++++++++------------------- forge/update_patches.sh | 16 ----- 3 files changed, 65 insertions(+), 97 deletions(-) diff --git a/forge/update_patches.bat b/forge/update_patches.bat index 2664a47eef..adb7ca9aaa 100644 --- a/forge/update_patches.bat +++ b/forge/update_patches.bat @@ -1,21 +1,3 @@ -@setlocal enabledelayedexpansion @echo off - set PATH=.\bin;%PATH% - -python update_patches.py - -echo Grabbing copy of conf folder -for /f %%i in ('find conf -type f') do ( - set file=%%i - if %%i NEQ ".gitignore" ( - del !file:/=\! - ) -) - -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 - -echo Finished -pause +..\runtime\bin\python\python_mcp update_patches.py diff --git a/forge/update_patches.py b/forge/update_patches.py index cb1668aaed..f363c1a739 100644 --- a/forge/update_patches.py +++ b/forge/update_patches.py @@ -1,63 +1,65 @@ -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__': +import os +import commands +import fnmatch +import re +import subprocess, shlex, shutil + +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'): + file_base = os.path.normpath(os.path.join(base, path[12:], cur_file)).replace(os.path.sep, '/') + file_work = os.path.normpath(os.path.join(work, path[12:], cur_file)).replace(os.path.sep, '/') + 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, 'wb') as fh: + fh.write(patch) + else: + if os.path.isfile(patch_file): + print 'Deleting empty patch: ' + patch_file + os.remove(patch_file) + + cleanDirs('patches') + print 'Grabing copy of Conf' + if os.path.exists('conf'): + shutil.rmtree('conf') + shutil.copytree('../conf', './conf/') + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/forge/update_patches.sh b/forge/update_patches.sh index e683c9cf98..738e3d05fa 100755 --- a/forge/update_patches.sh +++ b/forge/update_patches.sh @@ -1,17 +1 @@ -fdir=$PWD - python update_patches.py -echo Grabbing copy of conf folder -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 ".git"` -do - rmdir "$i" -done - -mkdir -p $fdir/conf -cp -r conf/* $fdir/conf - -echo Finished