lilypond-1.3.25
[lilypond.git] / bin / makepatch.py
blob0d7ecfc08286116da78e5bbd870a4491da6abd4a
1 #!@PYTHON@
2 from lilypython import *
3 import getopt
4 import pipes
7 mp_version = '2'
9 class Options:
10 def __init__(self):
11 self.to_version = lilydirs.version_tuple()
12 self.from_version = prev_version(self.to_version)
14 options = Options()
17 def help():
18 sys.stdout.write(
19 'Generate a patch to go to this version.\n'
20 ' --from=FROM, -f FROM old is FROM\n'
21 ' --to=TO, -t TO to version TO\n'
24 sys.exit();
28 def untar(fn):
29 sys.stderr.write('untarring ' + fn)
30 os.system ('tar xzf ' + fn)
31 sys.stderr.write('\n')
32 sys.stderr.flush()
35 header = 'Generated by make-patch, old = %s, new = %s\n\
36 \n\
37 usage \n\
38 \n\
39 cd lilypond-source-dir; patch -E -p0 < %s\n\
40 \n\
41 Patches do not contain automatically generated files, \n\
42 i.e. you should rerun configure\n\n'
44 import fnmatch
45 import os
47 _debug = 0
49 _prune = ['(*)']
52 def my_find(patterns, dir = os.curdir):
53 list = []
54 names = os.listdir(dir)
55 names.sort()
56 for name in names:
57 if name in (os.curdir, os.pardir):
58 continue
59 fullname = os.path.join(dir, name)
60 for pat in patterns:
61 if fnmatch.fnmatch(name, pat):
62 list.append(fullname)
63 if os.path.isdir(fullname) and not os.path.islink(fullname):
64 for p in _prune:
65 if fnmatch.fnmatch(name, p):
66 if _debug: print "skip", `fullname`
67 break
68 else:
69 if _debug: print "descend into", `fullname`
70 found = my_find(patterns, fullname)
71 if found:
72 list = list + found
73 return list
75 def multiple_find(pats, dirnames):
76 from find import find
77 l = []
78 for d in dirnames:
79 l = l + my_find(pats, d)
80 return l
82 pats = ['*.lsm', 'configure', '*.text', 'lilypond.spec']
83 def remove_automatic(dirnames):
84 files = []
85 files = files + multiple_find(pats, dirnames)
87 for f in files:
88 os.remove(f)
90 def makepatch(fv, tv, patfile_nm):
91 import tempfile
92 prev_cwd = os.getcwd();
93 os.chdir ('/tmp')
94 untar(released_tarball(fv))
95 untar(released_tarball(tv))
96 remove_automatic([dirname(fv), dirname(tv)])
98 os.chdir(dirname(tv))
100 if not patfile_nm:
101 patfile_nm = '../patch-%s' % version_tuple_to_str(tv)
103 f = open(patfile_nm, 'w')
104 f.write(header %\
105 (version_tuple_to_str(fv), version_tuple_to_str(tv), \
106 os.path.basename(patfile_nm)))
107 f.close()
109 sys.stderr.write('diffing to %s... ' % patfile_nm)
110 os.system('diff -urN ../%s . >> %s' % (dirname(fv), patfile_nm))
111 #os.system('gzip -9f %s' % patfile_nm)
112 os.chdir('/tmp')
114 sys.stderr.write('cleaning ... ')
115 os.system('rm -fr %s %s' % (dirname(tv), dirname(fv)))
116 sys.stderr.write('\n')
117 os.chdir(prev_cwd)
119 def main():
120 sys.stderr.write('This is make-patch version %s\n' % mp_version)
121 (cl_options, files) = getopt.getopt(sys.argv[1:],
122 'hf:o:t:', ['output=', 'help', 'from=', 'to='])
123 outfn = ''
124 for opt in cl_options:
125 o = opt[0]
126 a = opt[1]
127 if o == '--from' or o == '-f':
128 options.from_version = version_str_to_tuple(a)
129 elif o == '--to' or o == '-t':
130 options.to_version = version_str_to_tuple(a)
131 elif o== '--help' or o == '-h':
132 help()
133 elif o == '--output' or o == '-o':
134 outfn = os.path.join(os.getcwd(), a)
135 else:
136 raise getopt.error
138 if not outfn:
139 pn = 'patch-%s' % version_tuple_to_str(options.to_version)
140 outfn = os.path.join(os.getcwd(), pn)
142 makepatch(options.from_version, options.to_version, outfn)
144 if __name__ == '__main__':
145 main()