Updated update_patches.py, and made first patch!

This commit is contained in:
LexManos 2012-08-04 22:50:54 -07:00
parent 0d8940899c
commit 247ff9b737
4 changed files with 35 additions and 33 deletions

View file

@ -0,0 +1,10 @@
--- ../src_base/minecraft/net/minecraft/client/ClientBrandRetriever.java
+++ ../src_work/minecraft/net/minecraft/client/ClientBrandRetriever.java
@@ -4,6 +4,6 @@
{
public static String getClientModName()
{
- return "fml";
+ return "forge,fml";
}
}

View file

@ -1,3 +1,2 @@
@echo off @echo off
set PATH=.\bin;%PATH% ..\runtime\bin\python\python_mcp update_patches.py .. .
..\runtime\bin\python\python_mcp update_patches.py

View file

@ -1,8 +1,9 @@
import os import os
import commands import sys
import fnmatch import fnmatch
import re import shlex
import subprocess, shlex, shutil import difflib
import time
def cmdsplit(args): def cmdsplit(args):
if os.sep == '\\': if os.sep == '\\':
@ -25,25 +26,27 @@ def cleanDirs(path):
os.rmdir(path) os.rmdir(path)
def main(): def main():
print 'Creating patches' print("Creating patches")
base = os.path.normpath(os.path.join('..', 'src_base')) mcp = os.path.normpath(sys.argv[1])
work = os.path.normpath(os.path.join('..', 'src_work')) forge_dir = os.path.normpath(sys.argv[2])
timestamp = re.compile(r'[0-9-]* [0-9:\.]* [+-][0-9]*\r?\n') patchd = os.path.normpath(os.path.join(forge_dir, 'patches'))
base = os.path.normpath(os.path.join(mcp, 'src_base'))
work = os.path.normpath(os.path.join(mcp, 'src_work'))
for path, _, filelist in os.walk(work, followlinks=True): for path, _, filelist in os.walk(work, followlinks=True):
for cur_file in fnmatch.filter(filelist, '*.java'): 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_base = os.path.normpath(os.path.join(base, path[len(work)+1:], cur_file)).replace(os.path.sep, '/')
file_work = os.path.normpath(os.path.join(work, path[12:], cur_file)).replace(os.path.sep, '/') file_work = os.path.normpath(os.path.join(work, path[len(work)+1:], cur_file)).replace(os.path.sep, '/')
patch = ''
cmd = 'diff -u %s %s -r --strip-trailing-cr --new-file' % (file_base, file_work) fromlines = open(file_base, 'U').readlines()
process = subprocess.Popen(cmdsplit(cmd), stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=-1) tolines = open(file_work, 'U').readlines()
patch, _ = process.communicate()
patch_dir = os.path.join('patches', path[12:]) patch = ''.join(difflib.unified_diff(fromlines, tolines, '../' + file_base[len(mcp)+1:], '../' + file_work[len(mcp)+1:], '', '', n=3))
patch_dir = os.path.join(patchd, path[len(work)+1:])
patch_file = os.path.join(patch_dir, cur_file + '.patch') patch_file = os.path.join(patch_dir, cur_file + '.patch')
if len(patch) > 0: if len(patch) > 0:
print patch_file print patch_file[len(patchd)+1:]
patch = timestamp.sub("0000-00-00 00:00:00.000000000 -0000\n", patch)
patch = patch.replace('\r\n', '\n') patch = patch.replace('\r\n', '\n')
if not os.path.exists(patch_dir): if not os.path.exists(patch_dir):
@ -52,21 +55,11 @@ def main():
fh.write(patch) fh.write(patch)
else: else:
if os.path.isfile(patch_file): if os.path.isfile(patch_file):
print 'Deleting empty patch: ' + patch_file print("Deleting empty patch: %s"%(patch_file))
os.remove(patch_file) os.remove(patch_file)
for path, _, filelist in os.walk('patches', followlinks=True):
for cur_file in fnmatch.filter(filelist, '*.patch'): cleanDirs(patchd)
src_file = os.path.normpath(os.path.join(work, path[8:], cur_file[:-6]))
if not os.path.isfile(src_file):
print 'Deleting empty patch: %s' % os.path.join(path, cur_file)
os.remove(os.path.join(path, cur_file))
cleanDirs('patches')
print 'Grabing copy of Conf'
if os.path.exists('conf'):
shutil.rmtree('conf')
shutil.copytree('../conf', './conf/')
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View file

@ -1 +1 @@
python update_patches.py python update_patches.py .. .