]> git.donarmstrong.com Git - lilypond.git/blob - stepmake/bin/update.py
60521aeae46a3d5e0cc029123b4707bfce7f1ec5
[lilypond.git] / stepmake / bin / update.py
1 #!@PYTHON@
2
3 # update.py -- update current source tree
4
5 # source file of the GNU LilyPond music typesetter
6
7 # (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
8
9 program_name = 'update'
10 version = '0.1'
11
12 import os
13 import sys
14
15 sys.path.append ('@abs-step-bindir@')
16 sys.path.append (os.environ['HOME'] + '/usr/src/lilypond/stepmake/bin')
17
18 import getopt
19 from string import *
20 import regex
21 import regsub
22 import time
23
24 def program_id ():
25     return program_name + ' version ' + version;
26
27 def identify ():
28     sys.stdout.write (program_id () + '\n')
29
30 def help ():
31     sys.stdout.write ("Usage: %s [OPTION]...\n"
32                       "Update sourcetree\n\n"
33                       + "Options:\n"
34                       + "  -f, --file=FILE      specify patch file\n"
35                       + "  -h, --help           print this help\n"
36                       + "  -p, --package=DIR    specify package\n"
37                       + "  -v, --version=VER    specify patch version\n"
38                       % (program_name)
39                       )
40     sys.exit (0)
41
42 identify ()
43 (options, files) = getopt.getopt (
44     sys.argv[1:], 'f:hp:v:', ['file=', 'help', 'package=', 'version='])
45 patch=''
46 ver=''
47 for opt in options:
48     o = opt[0]
49     a = opt[1]
50     if o == '--help' or o == '-h':
51         help ()
52     elif o == '-f' or o == '--file':
53         patch = a
54     elif o == '-p' or o == '--package':
55         topdir = a
56     elif o == '-v' or o == '--version':
57         ver = a
58     else:
59         print o
60         raise getopt.error
61
62 sys.path.append (topdir + '/stepmake/bin')
63 from packagepython import *
64 package = Package (topdir)
65 packager = Packager ()
66
67 from flower import *
68
69 def read_patch_vector (patch):
70     vec = []
71     pipe = os.popen ('gzip -dc ' + patch)
72     line = pipe.readline ()
73     while line and line != '--state\n':
74         line = pipe.readline ()
75     line = pipe.readline ()
76     while line and line != '++state\n':
77         vec.append (line[:len (line)-1])
78         line = pipe.readline ()
79     pipe.close ()
80     return vec 
81     
82 def read_state_vector (states):
83     vec = []
84     file = File (states)
85     while not file.eof ():
86         line = file.readline ()
87         if line:
88             vec.append (line[:len (line)-1])
89     return vec
90
91 def read_relevant_state_vector (states, from_str):
92     vec = read_state_vector (states)
93     for i in range (len (vec)):
94         if vec[i] == from_str:
95             return vec[i:]
96     return []
97
98 def find_revert (states, patch):
99     for i in range (len (state_vector)):
100         for j in doubles:
101             if j in state_vector[:i+1]:
102                 return state_vector[i:]
103     return []
104
105 if patch == '' and ver != '':
106     patch = package.patch_dir + '/' + package.name + '-%s.diff.gz' % ver
107 if patch == '':
108     if 0:
109         files = os.listdir (package.patch_dir)
110         patches = []
111         for i in files:
112             if regex.search (package.name + '-.*.diff.gz', i) == 0:
113                 patches.append (i)
114         # urg: sort
115         patch = package.patch_dir + '/' + patches[len (patches) -1]
116     else:
117         os.chdir (package.patch_dir)
118         pipe = os.popen ('/bin/ls -t1 ' + package.name 
119             + '-*.diff.gz 2> /dev/null')
120         patch = pipe.readline ()
121         patch = patch[:len (patch) -1]
122         pipe.close ()
123         if not patch:
124             raise 'patch not found'
125         patch = package.patch_dir + '/' + patch
126         print patch
127
128 os.chdir (package.topdir)
129 patch_vector = read_patch_vector (patch)
130 print 'patch vector: ' + str (patch_vector)
131 from_str = patch_vector[0]
132 state_vector = read_relevant_state_vector ('make/STATE-VECTOR', from_str)
133 print 'relevant state vector: ' + str (state_vector)
134
135 doubles = []
136 for i in patch_vector[1:]:
137     if i in state_vector:
138         doubles.append (i)
139 print 'doubles: ' + str (doubles)
140
141 revert = find_revert (state_vector, patch_vector)
142 redo = []
143 for i in revert:
144     redo.append (i)
145 revert.reverse ()
146
147 for i in doubles:
148     redo.remove (i)
149
150 if revert or redo or doubles:
151     print 'not smart enough; please do:'
152     print '  * revert: ' + str (revert)
153     print '  * apply: ' + os.path.basename (patch)
154     print '  * redo: ' + str (redo)
155     sys.exit (1)
156
157 status = os.system ('echo "gzip -dc %s | patch -p1 -E --force"' % patch)
158 if status:
159     raise 'apply patch failed'
160
161 sys.stdout.write ('checking...')
162 rejects = my_find (['*.rej'], '.')
163 if len (rejects):
164     print 'rejects found:'
165     for i in rejects:
166         print i
167     sys.exit (1)
168 print 'ok'
169 sys.stdout.write ('cleaning...')
170 origs = my_find (['*.orig'], '.')
171 for i in origs:
172     os.remove (i)
173 print 'ok'