2012-03-30 17:33:29 +00:00
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import commands
|
|
|
|
import fnmatch
|
|
|
|
import re
|
2012-08-02 07:51:51 +00:00
|
|
|
import subprocess, shlex, shutil
|
2012-03-30 17:33:29 +00:00
|
|
|
|
2012-08-01 13:54:57 +00:00
|
|
|
import difflib, time
|
|
|
|
|
2012-03-30 17:33:29 +00:00
|
|
|
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")
|
2012-08-01 13:54:57 +00:00
|
|
|
mcp = os.path.normpath(sys.argv[1])
|
2012-08-02 07:51:51 +00:00
|
|
|
fml_dir = os.path.normpath(sys.argv[2])
|
|
|
|
patchd = os.path.normpath(os.path.join(fml_dir, 'patches'))
|
2012-04-05 07:09:29 +00:00
|
|
|
base = os.path.normpath(os.path.join(mcp, 'src-base'))
|
|
|
|
work = os.path.normpath(os.path.join(mcp, 'src-work'))
|
2012-03-30 17:33:29 +00:00
|
|
|
|
2012-04-05 07:09:29 +00:00
|
|
|
for path, _, filelist in os.walk(work, followlinks=True):
|
2012-03-30 17:33:29 +00:00
|
|
|
for cur_file in fnmatch.filter(filelist, '*.java'):
|
2012-04-05 07:09:29 +00:00
|
|
|
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[len(work)+1:], cur_file)).replace(os.path.sep, '/')
|
2012-08-01 13:54:57 +00:00
|
|
|
|
|
|
|
fromlines = open(file_base, 'U').readlines()
|
|
|
|
tolines = open(file_work, 'U').readlines()
|
|
|
|
|
|
|
|
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:])
|
2012-03-30 17:33:29 +00:00
|
|
|
patch_file = os.path.join(patch_dir, cur_file + '.patch')
|
|
|
|
|
|
|
|
if len(patch) > 0:
|
2012-08-01 13:54:57 +00:00
|
|
|
print patch_file[len(patchd)+1:]
|
2012-03-30 17:33:29 +00:00
|
|
|
patch = patch.replace('\r\n', '\n')
|
|
|
|
|
|
|
|
if not os.path.exists(patch_dir):
|
|
|
|
os.makedirs(patch_dir)
|
2012-04-05 07:09:29 +00:00
|
|
|
with open(patch_file, 'wb') as fh:
|
2012-03-30 17:33:29 +00:00
|
|
|
fh.write(patch)
|
|
|
|
else:
|
|
|
|
if os.path.isfile(patch_file):
|
|
|
|
print("Deleting empty patch: %s"%(patch_file))
|
|
|
|
os.remove(patch_file)
|
|
|
|
|
|
|
|
|
2012-08-01 13:54:57 +00:00
|
|
|
cleanDirs(patchd)
|
2012-03-30 17:33:29 +00:00
|
|
|
|
2013-06-28 03:48:52 +00:00
|
|
|
backup = os.path.join(mcp, 'runtime', 'commands.py.backup')
|
2012-08-02 07:51:51 +00:00
|
|
|
runtime = os.path.join(mcp, 'runtime', 'commands.py')
|
|
|
|
patch_file = os.path.join(fml_dir, 'commands.patch')
|
|
|
|
|
|
|
|
if not os.path.exists(backup):
|
|
|
|
shutil.copy(runtime, backup)
|
|
|
|
|
|
|
|
patch = ''.join(difflib.unified_diff(open(backup, 'U').readlines(), open(runtime, 'U').readlines(), 'commands.py', 'commands.py', '', '', n=3))
|
|
|
|
if len(patch) > 0:
|
|
|
|
print 'Creating commands.py patch'
|
|
|
|
patch = patch.replace('\r\n', '\n')
|
|
|
|
|
|
|
|
with open(patch_file, 'wb') as fh:
|
|
|
|
fh.write(patch)
|
|
|
|
else:
|
|
|
|
if os.path.isfile(patch_file):
|
|
|
|
print("Deleting empty commands.py patch")
|
|
|
|
os.remove(patch_file)
|
|
|
|
|
2012-03-30 17:33:29 +00:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|