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