3 # update.py -- update current source tree
5 # source file of the GNU LilyPond music typesetter
7 # (c) 1998 Jan Nieuwenhuizen <janneke@gnu.org>
9 program_name = 'update'
15 sys.path.append ('@abs-step-bindir@')
16 sys.path.append (os.environ['HOME'] + '/usr/src/lilypond/stepmake/bin')
25 return program_name + ' version ' + version;
28 sys.stdout.write (program_id () + '\n')
31 sys.stdout.write ("Usage: %s [OPTION]...\n"
32 "Update sourcetree\n\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"
43 (options, files) = getopt.getopt (
44 sys.argv[1:], 'f:hp:v:', ['file=', 'help', 'package=', 'version='])
50 if o == '--help' or o == '-h':
52 elif o == '-f' or o == '--file':
54 elif o == '-p' or o == '--package':
56 elif o == '-v' or o == '--version':
62 sys.path.append (topdir + '/stepmake/bin')
63 from packagepython import *
64 package = Package (topdir)
65 packager = Packager ()
69 def read_patch_vector (patch):
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 ()
82 def read_state_vector (states):
85 while not file.eof ():
86 line = file.readline ()
88 vec.append (line[:len (line)-1])
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:
98 def find_revert (states, patch):
99 for i in range (len (state_vector)):
101 if j in state_vector[:i+1]:
102 return state_vector[i:]
105 if patch == '' and ver != '':
106 patch = package.patch_dir + '/' + package.name + '-%s.diff.gz' % ver
109 files = os.listdir (package.patch_dir)
112 if regex.search (package.name + '-.*.diff.gz', i) == 0:
115 patch = package.patch_dir + '/' + patches[len (patches) -1]
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]
124 raise 'patch not found'
125 patch = package.patch_dir + '/' + patch
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)
136 for i in patch_vector[1:]:
137 if i in state_vector:
139 print 'doubles: ' + str (doubles)
141 revert = find_revert (state_vector, patch_vector)
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)
157 status = os.system ('echo "gzip -dc %s | patch -p1 -E --force"' % patch)
159 raise 'apply patch failed'
161 sys.stdout.write ('checking...')
162 rejects = my_find (['*.rej'], '.')
164 print 'rejects found:'
169 sys.stdout.write ('cleaning...')
170 origs = my_find (['*.orig'], '.')