lilypond-1.5.13
[lilypond.git] / bin / make-patch.py
blob9909bf9b730be6beebe2095c8603fb0dae979f19
1 #!@PYTHON@
3 import sys
4 import os
6 lilypath =''
7 try:
8 lilypath = os.environ['LILYPOND_SOURCEDIR'] + '/'
9 except KeyError:
10 print 'Please set LILYPOND_SOURCEDIR to the toplevel source, eg LILYPOND_SOURCEDIR=/home/foobar/lilypond-1.2.3/'
11 sys.exit(1)
13 lilypath = lilypath + '/bin/'
14 sys.path.append(lilypath)
17 from lilypython import *
18 import getopt
19 import pipes
22 mp_version = '0.51'
24 class Options:
25 def __init__(self):
26 self.to_version = lilydirs.version_tuple()
27 self.from_version = prev_version(self.to_version)
29 options = Options()
32 def help():
33 sys.stdout.write(
34 'Generate a patch to go to this version.\n'
35 ' -f, --from=FROM old is FROM\n'
36 ' -d, --dir=DIR diff to (or from) directory DIR\n'
37 ' -r, --release diff against latest release\n'
38 ' -t, --to=TO to version TO\n'
41 def untar(fn):
42 # os.system('pwd');
43 sys.stderr.write('untarring ' + fn + '\n')
44 os.system ('gzip --quiet -dc ' + fn + '| tar xf - ')
45 sys.stderr.flush()
48 header = 'Generated by make-patch, old = %s, new = %s\n\
49 \n\
50 usage \n\
51 \n\
52 cd lilypond-source-dir; patch -E -p1 < %s\n\
53 \n\
54 Patches do not contain automatically generated files, \n\
55 i.e. you should rerun autoconf and configure\n\n'
57 # ugh, how to get rid of .tex files generated by lily?
58 # pats = ['*.lsm', 'configure', '*.txt', '.dstreamrc', 'lilypond.spec']
59 pats = ['*.lsm', 'configure', '*.txt', '.dstreamrc', 'lilypond.spec',
60 'AUTHORS', 'INSTALL', 'PATCHES']
62 def remove_automatic(dirnames):
63 files = []
64 files = files + multiple_find(pats, dirnames)
66 for f in files:
67 os.remove(f)
69 def makepatch(fromdir, todir, patfile_nm):
71 remove_automatic([fromdir, todir])
73 os.chdir(todir)
75 f = open(patfile_nm, 'w')
76 f.write(header %\
77 (fromdir, todir, \
78 os.path.basename(patfile_nm)))
79 f.close()
81 sys.stderr.write('diffing to %s... ' % patfile_nm)
82 os.system('pwd')
83 print ('diff -urN ../%s . >> %s' % (fromdir, patfile_nm))
84 os.system('diff -urN ../%s . >> %s' % (fromdir, patfile_nm))
85 os.system('gzip --quiet -9f %s' % patfile_nm)
87 def main():
88 os.environ['GZIP'] = '-q'
89 sys.stderr.write('This is make-patch version %s\n' % mp_version)
90 (cl_options, files) = getopt.getopt(sys.argv[1:],
91 'd:hf:o:rt:', ['output=', 'help', 'from=', 'to='])
92 outfn = ''
93 srcdir = ''
95 # on default, we want to diff tar balls, again :-)
96 from_b=1
97 to_b=1
98 for opt in cl_options:
99 o = opt[0]
100 a = opt[1]
101 if o == '--from' or o == '-f':
102 options.from_version = version_str_to_tuple(a)
103 from_b=1
104 elif o == '--to' or o == '-t':
105 options.to_version = version_str_to_tuple(a)
106 to_b=1
107 elif o == '--dir' or o == '-d':
108 srcdir = a;
109 to_b=0
110 elif o == '--help' or o == '-h':
111 help()
112 return 0;
113 elif o == '--output' or o == '-o':
114 outfn = os.path.join(os.getcwd(), a)
115 elif o == '--release' or o == '-r':
116 # huh?
117 # if options.from_version[3]:
118 # options.from_version[3] = '';
119 options.from_version = (options.from_version[0],
120 options.from_version[1], options.from_version[2], '');
121 else:
122 raise getopt.error
124 if not outfn:
125 pn = 'patch-%s' % version_tuple_to_str(options.to_version)
126 outfn = os.path.join(os.getcwd(), pn)
128 import tempfile
129 prev_cwd = os.getcwd();
131 os.system('rm -rf /tmp/make-patch')
132 try:
133 os.mkdir ('/tmp/make-patch')
134 except:
135 pass
137 fromdir = dirname(options.from_version)
138 todir = dirname(options.to_version)
140 diffdir = ''
141 if srcdir != '':
142 diffdir = '/tmp/make-patch/' + 'lilypond-%s'\
143 % version_tuple_to_str(options.to_version)
145 if from_b != 0 or (from_b == 0 and to_b == 0):
146 os.chdir ('/tmp/make-patch')
147 untar(released_tarball(options.from_version))
148 os.chdir(prev_cwd)
149 else:
150 fromdir = diffdir
151 sys.stderr.write('copying ' + srcdir + ' to ' + diffdir + '\n')
152 # os.system('cp -pr %s %s' % (srcdir, diffdir))
153 os.system('mkdir -p %s '% (diffdir))
154 os.chdir (srcdir)
155 os.system('tar cf - --exclude out . | tar -xf - -C %s'
156 % diffdir)
158 if to_b != 0:
159 os.chdir ('/tmp/make-patch')
160 untar(released_tarball(options.to_version))
161 os.chdir(prev_cwd)
162 else:
163 todir = diffdir
164 sys.stderr.write('copying ' + srcdir + ' to ' + diffdir + '\n')
165 os.system('mkdir -p %s '% (diffdir))
166 # os.system('cp -pr %s %s' (srcdir, diffdir))%
167 os.chdir (srcdir)
168 os.system('tar -cf - --exclude out . | tar -xf - -C %s '
169 % diffdir)
171 os.chdir('/tmp/make-patch')
172 os.chdir(todir)
173 # os.system('rm -f *.aux *.dvi *.midi *.log *.ps *.tex *.ly')
174 os.chdir ('/tmp/make-patch')
176 makepatch(fromdir, todir, outfn)
178 os.chdir('/tmp/make-patch')
179 sys.stderr.write('cleaning ... ')
180 os.system('rm -fr %s %s' % (fromdir, todir))
181 sys.stderr.write('\n')
182 os.chdir(prev_cwd)
184 if __name__ == '__main__':
185 main()