bt-gps: fix hardcoded paths, fix QA issues, use bindir/datadir variables
[openembedded.git] / contrib / mtnpatch.py
blob4de9ecc460103006074557bc5fb0ea3f7fa6d8f7
1 #!/usr/bin/env python
2 import sys, os, string, getopt, re
4 mtncmd = "mtn"
6 def main(argv = None):
7 if argv is None:
8 argv = sys.argv
9 opts, list = getopt.getopt(sys.argv[1:], ':R')
10 if len(list) < 1:
11 print "You must specify a file"
12 return 2
13 reverse = False
14 for o, a in opts:
15 if o == "-R":
16 reverse = True
17 if os.path.exists(list[0]):
18 input = open(list[0], 'r')
19 renameFrom = ""
20 cmd = ""
21 for line in input:
22 if len(line) > 0:
23 if line[0] == '#':
24 matches = re.search("#\s+(\w+)\s+\"(.*)\"", line)
25 if matches is not None:
26 cmd = matches.group(1)
27 fileName = matches.group(2)
28 if cmd == "delete":
29 if reverse:
30 print "%s add %s" % (mtncmd, fileName)
31 else:
32 print "%s drop -e %s" % (mtncmd, fileName)
33 elif cmd == "add" or cmd == "add_file" or cmd == "add_dir":
34 if reverse:
35 print "%s drop -e %s" % (mtncmd, fileName)
36 else:
37 print "%s add %s" % (mtncmd, fileName)
38 elif cmd == "rename":
39 renameFrom = fileName
40 elif cmd == "to" and renameFrom != "":
41 if reverse:
42 print "%s rename -e %s %s" % (mtncmd, fileName, renameFrom)
43 else:
44 print "%s rename -e %s %s" % (mtncmd, renameFrom, fileName)
45 renameFrom = ""
46 else:
47 cmd = ""
48 if reverse:
49 print "patch -R -p0 < %s" % list[0]
50 else:
51 print "patch -p0 < %s" % list[0]
53 if __name__ == "__main__":
54 sys.exit(main())