summaryrefslogtreecommitdiff
path: root/contrib/mtnpatch.py
diff options
context:
space:
mode:
authorKoen Kooi <koen@openembedded.org>2006-09-06 10:37:33 +0000
committerKoen Kooi <koen@openembedded.org>2006-09-06 10:37:33 +0000
commit80788791c0a9475d9e2ee6c8f39f283584a7f15c (patch)
tree08ed1cd5ccf7d10f7ebb1cbfe98188cd4ed91efb /contrib/mtnpatch.py
parentdbae8df533dc665215286adb3d8dfd99085b5d84 (diff)
parent1b0ec1eeed007033b51b2933905bfb7aa335c2c2 (diff)
merge of '0cc400441946f7a721b718fe50f7bbce5c9ea24f'
and '42be14012b6790df46c62295f3a02286acecbd4f'
Diffstat (limited to 'contrib/mtnpatch.py')
-rwxr-xr-xcontrib/mtnpatch.py54
1 files changed, 54 insertions, 0 deletions
diff --git a/contrib/mtnpatch.py b/contrib/mtnpatch.py
new file mode 100755
index 0000000000..73143dba69
--- /dev/null
+++ b/contrib/mtnpatch.py
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+import sys, os, string, getopt, re
+
+mtncmd = "monotone"
+
+def main(argv = None):
+ if argv is None:
+ argv = sys.argv
+ opts, list = getopt.getopt(sys.argv[1:], ':R')
+ if len(list) < 1:
+ print "You must specify a file"
+ return 2
+ reverse = False
+ for o, a in opts:
+ if o == "-R":
+ reverse = True
+ if os.path.exists(list[0]):
+ input = open(list[0], 'r')
+ renameFrom = ""
+ cmd = ""
+ if reverse:
+ print "patch -R -p0 < %s" % list[0]
+ else:
+ print "patch -p0 < %s" % list[0]
+ for line in input:
+ if len(line) > 0:
+ if line[0] == '#':
+ matches = re.search("#\s+(\w+)\s+\"(.*)\"", line)
+ if matches is not None:
+ cmd = matches.group(1)
+ fileName = matches.group(2)
+ if cmd == "delete_file":
+ if reverse:
+ print "%s add %s" % (mtncmd, fileName)
+ else:
+ print "%s drop -e %s" % (mtncmd, fileName)
+ elif cmd == "add_file":
+ if reverse:
+ print "%s drop -e %s" % (mtncmd, fileName)
+ else:
+ print "%s add %s" % (mtncmd, fileName)
+ elif cmd == "rename_file":
+ renameFrom = fileName
+ elif cmd == "to" and renameFrom != "":
+ if reverse:
+ print "%s rename -e %s %s" % (mtncmd, fileName, renameFrom)
+ else:
+ print "%s rename -e %s %s" % (mtncmd, renameFrom, fileName)
+ renameFrom = ""
+ else:
+ cmd = ""
+
+if __name__ == "__main__":
+ sys.exit(main())