1 |
#!/usr/bin/python -u |
2 |
|
3 |
# A lot of the code comes from ftpadmin, see |
4 |
# http://git.gnome.org/browse/sysadmin-bin/tree/ftpadmin |
5 |
# Written by Olav Vitters |
6 |
|
7 |
# basic modules: |
8 |
import os |
9 |
import os.path |
10 |
import sys |
11 |
import re |
12 |
import subprocess |
13 |
|
14 |
# command line parsing, error handling: |
15 |
import argparse |
16 |
import errno |
17 |
|
18 |
# overwriting files by moving them (safer): |
19 |
import tempfile |
20 |
import shutil |
21 |
|
22 |
# version comparison: |
23 |
import rpm |
24 |
|
25 |
# opening tarballs: |
26 |
import tarfile |
27 |
import gzip |
28 |
import bz2 |
29 |
import lzma # pyliblzma |
30 |
|
31 |
# getting links from HTML document: |
32 |
from sgmllib import SGMLParser |
33 |
import urllib2 |
34 |
import urlparse |
35 |
|
36 |
# for checking hashes |
37 |
import hashlib |
38 |
|
39 |
# for parsing ftp-release-list emails |
40 |
import email |
41 |
from email.mime.text import MIMEText |
42 |
|
43 |
# to be able to sleep for a while |
44 |
import time |
45 |
|
46 |
# version freeze |
47 |
import datetime |
48 |
|
49 |
MEDIA="Core Release Source" |
50 |
URL="http://download.gnome.org/sources/" |
51 |
PKGROOT='~/pkgs' |
52 |
SLEEP_INITIAL=300 |
53 |
SLEEP_REPEAT=30 |
54 |
SLEEP_TIMES=20 |
55 |
|
56 |
re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*') |
57 |
re_version = re.compile(r'([-.]|\d+|[^-.\d]+)') |
58 |
|
59 |
def version_cmp(a, b): |
60 |
"""Compares two versions |
61 |
|
62 |
Returns |
63 |
-1 if a < b |
64 |
0 if a == b |
65 |
1 if a > b |
66 |
""" |
67 |
|
68 |
return rpm.labelCompare(('1', a, '1'), ('1', b, '1')) |
69 |
|
70 |
def get_latest_version(versions, max_version=None): |
71 |
"""Gets the latest version number |
72 |
|
73 |
if max_version is specified, gets the latest version number before |
74 |
max_version""" |
75 |
latest = None |
76 |
for version in versions: |
77 |
if ( latest is None or version_cmp(version, latest) > 0 ) \ |
78 |
and ( max_version is None or version_cmp(version, max_version) < 0 ): |
79 |
latest = version |
80 |
return latest |
81 |
|
82 |
def judge_version_increase(version_old, version_new): |
83 |
"""Judge quality of version increase: |
84 |
|
85 |
Returns a tuple containing judgement and message |
86 |
|
87 |
Judgement: |
88 |
Less than 0: Error |
89 |
0 to 4: Better not |
90 |
5+: Ok""" |
91 |
versions = (version_old, version_new) |
92 |
|
93 |
# First do a basic version comparison to ensure version_new is actually newer |
94 |
compare = version_cmp(version_new, version_old) |
95 |
|
96 |
if compare == 0: |
97 |
# 1.0.0 -> 1.0.1 |
98 |
return (-2, "Already at version %s!" % (version_old)) |
99 |
|
100 |
if compare != 1: |
101 |
# 1.0.1 -> 1.0.0 |
102 |
return (-3, "Version %s is older than current version %s!" % (version_new, version_old)) |
103 |
|
104 |
# Version is newer, but we don't want to see if it follows the GNOME versioning scheme |
105 |
majmins = [re_majmin.sub(r'\1', ver) for ver in versions if re_majmin.match(ver) is not None] |
106 |
|
107 |
if len(majmins) == 1: |
108 |
return (-1, "Version number scheme changes: %s" % (", ".join(versions))) |
109 |
|
110 |
if len(majmins) == 0: |
111 |
return (0, "Unsupported version numbers: %s" % (", ".join(versions))) |
112 |
|
113 |
# Follows GNOME versioning scheme |
114 |
# Meaning: x.y.z |
115 |
# x = major |
116 |
# y = minor : even if stable |
117 |
# z = micro |
118 |
|
119 |
# Major+minor the same? Then go ahead and upgrade! |
120 |
if majmins[0] == majmins[1]: |
121 |
# Majmin of both versions are the same, looks good! |
122 |
# 1.1.x -> 1.1.x or 1.0.x -> 1.0.x |
123 |
return (10, None) |
124 |
|
125 |
# More detailed analysis needed, so figure out the numbers |
126 |
majmin_nrs = [map(long, ver.split('.')) for ver in majmins] |
127 |
|
128 |
# Check/ensure major version number is the same |
129 |
if majmin_nrs[0][0] != majmin_nrs[1][0]: |
130 |
# 1.0.x -> 2.0.x |
131 |
return (1, "Major version number increase") |
132 |
|
133 |
# Minor indicates stable/unstable |
134 |
devstate = (majmin_nrs[0][1] % 2 == 0, majmin_nrs[1][1] % 2 == 0) |
135 |
|
136 |
# Upgrading to unstable is weird |
137 |
if not devstate[1]: |
138 |
if devstate[0]: |
139 |
# 1.2.x -> 1.3.x |
140 |
return (1, "Stable to unstable increase") |
141 |
|
142 |
# 1.3.x -> 1.5.x |
143 |
return (4, "Unstable to unstable version increase") |
144 |
|
145 |
# Unstable => stable is always ok |
146 |
if not devstate[0]: |
147 |
# 1.1.x -> 1.2.x |
148 |
return (5, "Unstable to stable") |
149 |
|
150 |
# Can only be increase of minors from one stable to the next |
151 |
# 1.0.x -> 1.2.x |
152 |
return (6, "Stable version increase") |
153 |
|
154 |
def line_input (file): |
155 |
for line in file: |
156 |
if line[-1] == '\n': |
157 |
yield line[:-1] |
158 |
else: |
159 |
yield line |
160 |
|
161 |
def call_editor(filename): |
162 |
"""Return a sequence of possible editor binaries for the current platform""" |
163 |
|
164 |
editors = [] |
165 |
|
166 |
for varname in 'VISUAL', 'EDITOR': |
167 |
if varname in os.environ: |
168 |
editors.append(os.environ[varname]) |
169 |
|
170 |
editors.extend(('/usr/bin/editor', 'vi', 'pico', 'nano', 'joe')) |
171 |
|
172 |
for editor in editors: |
173 |
try: |
174 |
ret = subprocess.call([editor, filename]) |
175 |
except OSError, e: |
176 |
if e.errno == 2: |
177 |
continue |
178 |
raise |
179 |
|
180 |
if ret == 127: |
181 |
continue |
182 |
|
183 |
return True |
184 |
|
185 |
class urllister(SGMLParser): |
186 |
def reset(self): |
187 |
SGMLParser.reset(self) |
188 |
self.urls = [] |
189 |
|
190 |
def start_a(self, attrs): |
191 |
href = [v for k, v in attrs if k=='href'] |
192 |
if href: |
193 |
self.urls.extend(href) |
194 |
|
195 |
class XzTarFile(tarfile.TarFile): |
196 |
|
197 |
OPEN_METH = tarfile.TarFile.OPEN_METH.copy() |
198 |
OPEN_METH["xz"] = "xzopen" |
199 |
|
200 |
@classmethod |
201 |
def xzopen(cls, name, mode="r", fileobj=None, **kwargs): |
202 |
"""Open gzip compressed tar archive name for reading or writing. |
203 |
Appending is not allowed. |
204 |
""" |
205 |
if len(mode) > 1 or mode not in "rw": |
206 |
raise ValueError("mode must be 'r' or 'w'") |
207 |
|
208 |
if fileobj is not None: |
209 |
fileobj = _LMZAProxy(fileobj, mode) |
210 |
else: |
211 |
fileobj = lzma.LZMAFile(name, mode) |
212 |
|
213 |
try: |
214 |
# lzma doesn't immediately return an error |
215 |
# try and read a bit of data to determine if it is a valid xz file |
216 |
fileobj.read(_LZMAProxy.blocksize) |
217 |
fileobj.seek(0) |
218 |
t = cls.taropen(name, mode, fileobj, **kwargs) |
219 |
except IOError: |
220 |
raise tarfile.ReadError("not a xz file") |
221 |
except lzma.error: |
222 |
raise tarfile.ReadError("not a xz file") |
223 |
t._extfileobj = False |
224 |
return t |
225 |
|
226 |
if not hasattr(tarfile.TarFile, 'xzopen'): |
227 |
tarfile.open = XzTarFile.open |
228 |
|
229 |
def is_valid_hash(path, algo, hexdigest): |
230 |
if algo not in hashlib.algorithms: |
231 |
raise ValueError("Unknown hash algorithm: %s" % algo) |
232 |
|
233 |
local_hash = getattr(hashlib, algo)() |
234 |
|
235 |
with open(path, 'rb') as fp: |
236 |
data = fp.read(32768) |
237 |
while data: |
238 |
local_hash.update(data) |
239 |
data = fp.read(32768) |
240 |
|
241 |
return local_hash.hexdigest() == hexdigest |
242 |
|
243 |
class SpecFile(object): |
244 |
re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
245 |
re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE) |
246 |
|
247 |
def __init__(self, path): |
248 |
self.path = path |
249 |
self.cwd = os.path.dirname(path) |
250 |
|
251 |
@property |
252 |
def version(self): |
253 |
return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0] |
254 |
@property |
255 |
def sources(self): |
256 |
ts = rpm.ts() |
257 |
spec = ts.parseSpec(self.path) |
258 |
srclist = spec.sources if isinstance(spec.sources, (list, tuple)) \ |
259 |
else spec.sources() |
260 |
return dict((os.path.basename(name), name) for name, no, flags in srclist) |
261 |
|
262 |
def update(self, version, force=False): |
263 |
"""Update specfile (increase version)""" |
264 |
cur_version = self.version |
265 |
|
266 |
(judgement, msg) = judge_version_increase(cur_version, version) |
267 |
|
268 |
if judgement < 0: |
269 |
print >>sys.stderr, "ERROR: %s!" % (msg) |
270 |
return False |
271 |
|
272 |
if judgement < 5: |
273 |
print "WARNING: %s!" % (msg) |
274 |
if not force: return False |
275 |
|
276 |
# XXX - os.path.join is hackish |
277 |
if subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) != '': |
278 |
print >>sys.stderr, "ERROR: Package has uncommitted changes!" |
279 |
return False |
280 |
|
281 |
with open(self.path, "rw") as f: |
282 |
data = f.read() |
283 |
|
284 |
if data.count("%mkrel") != 1: |
285 |
print >>sys.stderr, "ERROR: Multiple %mkrel found; don't know what to do!" |
286 |
return False |
287 |
|
288 |
data, nr = self.re_update_version.subn(r'\g<pre>%s\g<post>' % version, data, 1) |
289 |
if nr != 1: |
290 |
print >>sys.stderr, "ERROR: Could not increase version!" |
291 |
return False |
292 |
|
293 |
data, nr = self.re_update_release.subn(r'\g<pre>%mkrel 1\g<post>', data, 1) |
294 |
if nr != 1: |
295 |
print >>sys.stderr, "ERROR: Could not reset release!" |
296 |
return False |
297 |
|
298 |
# Overwrite file with new version number |
299 |
write_file(self.path, data) |
300 |
|
301 |
|
302 |
# Verify that RPM also agrees that version number has changed |
303 |
if self.version != version: |
304 |
print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version |
305 |
return False |
306 |
|
307 |
|
308 |
# Try to download the new tarball various times and wait between attempts |
309 |
tries = 0 |
310 |
while tries < SLEEP_TIMES: |
311 |
tries += 1 |
312 |
try: |
313 |
# Download new tarball |
314 |
subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd) |
315 |
break |
316 |
except subprocess.CalledProcessError, e: |
317 |
# mgarepo sync returns 1 if the tarball cannot be downloaded |
318 |
if e.returncode != 1: |
319 |
return False |
320 |
|
321 |
if tries == SLEEP_TIMES: |
322 |
return False |
323 |
|
324 |
time.sleep(SLEEP_REPEAT) |
325 |
|
326 |
try: |
327 |
# Check patches still apply |
328 |
subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd) |
329 |
except subprocess.CalledProcessError: |
330 |
return False |
331 |
|
332 |
return True |
333 |
|
334 |
class Patch(object): |
335 |
"""Do things with patches""" |
336 |
|
337 |
re_dep3 = re.compile(r'^(?:#\s*)?(?P<header>[-A-Za-z0-9]+?):\s*(?P<data>.*)$') |
338 |
re_dep3_cont = re.compile(r'^#?\s+(?P<data>.*)$') |
339 |
|
340 |
def __init__(self, path, show_path=False): |
341 |
"""Path: path to patch (might not exist)""" |
342 |
self.path = path |
343 |
self.show_path = show_path |
344 |
|
345 |
def __str__(self): |
346 |
return self.path if self.show_path else os.path.basename(self.path) |
347 |
|
348 |
def add_dep3(self): |
349 |
"""Add DEP-3 headers to a patch file""" |
350 |
if self.dep3['valid']: |
351 |
return False |
352 |
|
353 |
new_headers = ( |
354 |
('Author', self.svn_author), |
355 |
('Subject', ''), |
356 |
('Applied-Upstream', ''), |
357 |
('Forwarded', ''), |
358 |
('Bug', ''), |
359 |
) |
360 |
|
361 |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(self.path), delete=False) as fdst: |
362 |
with open(self.path, "r") as fsrc: |
363 |
# Start with any existing DEP3 headers |
364 |
for i in range(self.dep3['last_nr']): |
365 |
fdst.write(fsrc.read()) |
366 |
|
367 |
# After that add the DEP3 headers |
368 |
add_line = False |
369 |
for header, data in new_headers: |
370 |
if header in self.dep3['headers']: |
371 |
continue |
372 |
|
373 |
# XXX - wrap this at 80 chars |
374 |
add_line = True |
375 |
print >>fdst, "%s: %s" % (header, "" if data is None else data) |
376 |
|
377 |
if add_line: print >>fdst, "" |
378 |
# Now copy any other data and the patch |
379 |
shutil.copyfileobj(fsrc, fdst) |
380 |
|
381 |
fdst.flush() |
382 |
os.rename(fdst.name, self.path) |
383 |
|
384 |
call_editor(self.path) |
385 |
|
386 |
#Author: fwang |
387 |
#Subject: Build fix: Fix glib header inclusion |
388 |
#Applied-Upstream: commit:30602 |
389 |
#Forwarded: yes |
390 |
#Bug: http://bugzilla.abisource.com/show_bug.cgi?id=13247 |
391 |
|
392 |
def _read_dep3(self): |
393 |
"""Read DEP-3 headers from an existing patch file |
394 |
|
395 |
This will also parse git headers""" |
396 |
dep3 = {} |
397 |
headers = {} |
398 |
|
399 |
last_header = None |
400 |
last_nr = 0 |
401 |
nr = 0 |
402 |
try: |
403 |
with open(self.path, "r") as f: |
404 |
for line in line_input(f): |
405 |
nr += 1 |
406 |
# stop trying to parse when real patch begins |
407 |
if line == '---': |
408 |
break |
409 |
|
410 |
r = self.re_dep3.match(line) |
411 |
if r: |
412 |
info = r.groupdict() |
413 |
|
414 |
# Avoid matching URLS |
415 |
if info['data'].startswith('//') and info['header'].lower () == info['header']: |
416 |
continue |
417 |
|
418 |
headers[info['header']] = info['data'] |
419 |
last_header = info['header'] |
420 |
last_nr = nr |
421 |
continue |
422 |
|
423 |
r = self.re_dep3_cont.match(line) |
424 |
if r: |
425 |
info = r.groupdict() |
426 |
if last_header: |
427 |
headers[last_header] = " ".join((headers[last_header], info['data'])) |
428 |
last_nr = nr |
429 |
continue |
430 |
|
431 |
last_header = None |
432 |
except IOError: |
433 |
pass |
434 |
|
435 |
dep3['valid'] = \ |
436 |
(('Description' in headers and headers['Description'].strip() != '') |
437 |
or ('Subject' in headers and headers['Subject'].strip() != '')) \ |
438 |
and (('Origin' in headers and headers['Origin'].strip() != '') \ |
439 |
or ('Author' in headers and headers['Author'].strip() != '') \ |
440 |
or ('From' in headers and headers['From'].strip() != '')) |
441 |
dep3['last_nr'] = last_nr |
442 |
dep3['headers'] = headers |
443 |
|
444 |
self._dep3 = dep3 |
445 |
|
446 |
@property |
447 |
def dep3(self): |
448 |
if not hasattr(self, '_dep3'): |
449 |
self._read_dep3() |
450 |
|
451 |
return self._dep3 |
452 |
|
453 |
@property |
454 |
def svn_author(self): |
455 |
if not hasattr(self, '_svn_author'): |
456 |
try: |
457 |
contents = subprocess.check_output(['svn', 'log', '-q', "--", self.path], close_fds=True).strip("\n").splitlines() |
458 |
|
459 |
for line in contents: |
460 |
if ' | ' not in line: |
461 |
continue |
462 |
|
463 |
fields = line.split(' | ') |
464 |
if len(fields) >= 3: |
465 |
self._svn_author = fields[1] |
466 |
except subprocess.CalledProcessError: |
467 |
pass |
468 |
|
469 |
if not hasattr(self, '_svn_author'): |
470 |
return None |
471 |
|
472 |
return self._svn_author |
473 |
|
474 |
def get_upstream_names(): |
475 |
urlopen = urllib2.build_opener() |
476 |
|
477 |
good_dir = re.compile('^[-A-Za-z0-9_+.]+/$') |
478 |
|
479 |
# Get the files |
480 |
usock = urlopen.open(URL) |
481 |
parser = urllister() |
482 |
parser.feed(usock.read()) |
483 |
usock.close() |
484 |
parser.close() |
485 |
files = parser.urls |
486 |
|
487 |
tarballs = set([filename.replace('/', '') for filename in files if good_dir.search(filename)]) |
488 |
|
489 |
return tarballs |
490 |
|
491 |
def get_downstream_names(): |
492 |
re_file = re.compile(r'^(?P<module>.*?)[_-](?:(?P<oldversion>([0-9]+[\.])*[0-9]+)-)?(?P<version>([0-9]+[\.\-])*[0-9]+)\.(?P<format>(?:tar\.|diff\.)?[a-z][a-z0-9]*)$') |
493 |
|
494 |
contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines() |
495 |
|
496 |
FILES = {} |
497 |
TARBALLS = {} |
498 |
|
499 |
for line in contents: |
500 |
try: |
501 |
srpm, version, filename = line.split("|") |
502 |
except ValueError: |
503 |
print >>sys.stderr, line |
504 |
continue |
505 |
|
506 |
if '.tar' in filename: |
507 |
r = re_file.match(filename) |
508 |
if r: |
509 |
fileinfo = r.groupdict() |
510 |
module = fileinfo['module'] |
511 |
|
512 |
if module not in TARBALLS: |
513 |
TARBALLS[module] = {} |
514 |
TARBALLS[module][srpm] = version |
515 |
|
516 |
if srpm not in FILES: |
517 |
FILES[srpm] = set() |
518 |
FILES[srpm].add(filename) |
519 |
|
520 |
return TARBALLS, FILES |
521 |
|
522 |
def get_downstream_from_upstream(upstream, version): |
523 |
# Determine the package name |
524 |
downstream, downstream_files = get_downstream_names() |
525 |
|
526 |
if upstream not in downstream: |
527 |
raise ValueError("No packages for upstream name: %s" % upstream) |
528 |
|
529 |
if len(downstream[upstream]) != 1: |
530 |
# XXX - Make it more intelligent |
531 |
raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream].keys()))) |
532 |
|
533 |
return downstream[upstream].keys() |
534 |
|
535 |
def write_file(path, data): |
536 |
with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst: |
537 |
fdst.write(data) |
538 |
fdst.flush() |
539 |
os.rename(fdst.name, path) |
540 |
|
541 |
def cmd_co(options, parser): |
542 |
root = os.path.expanduser(PKGROOT) |
543 |
|
544 |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
545 |
print "%s => %s" % (module, package) |
546 |
subprocess.call(['mgarepo', 'co', package], cwd=root) |
547 |
|
548 |
def join_streams(show_version=False, only_diff_version=False): |
549 |
root = os.path.expanduser(PKGROOT) |
550 |
|
551 |
upstream = get_upstream_names() |
552 |
downstream, downstream_files = get_downstream_names() |
553 |
|
554 |
matches = upstream & set(downstream.keys()) |
555 |
for module in matches: |
556 |
for package in downstream[module].keys(): |
557 |
package_version = downstream[module][package] |
558 |
spec_version = None |
559 |
if show_version or only_diff_version: |
560 |
cwd = os.path.join(root, package) |
561 |
try: |
562 |
spec_version = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version |
563 |
except subprocess.CalledProcessError: |
564 |
spec_version = 'N/A' |
565 |
|
566 |
if only_diff_version and package_version == spec_version: |
567 |
continue |
568 |
|
569 |
yield (package, module, package_version, spec_version, downstream_files[package]) |
570 |
|
571 |
def cmd_ls(options, parser): |
572 |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams(show_version=options.show_version, only_diff_version=options.diff)): |
573 |
print package,"\t", |
574 |
if options.upstream: print module, "\t", |
575 |
if options.show_version: print spec_version, "\t", package_version, "\t", |
576 |
print |
577 |
|
578 |
def cmd_patches(options, parser): |
579 |
root = os.path.expanduser(PKGROOT) |
580 |
|
581 |
for package, module, package_version, spec_version, downstream_files in sorted(join_streams()): |
582 |
for filename in downstream_files: |
583 |
if '.patch' in filename or '.diff' in filename: |
584 |
|
585 |
p = Patch(os.path.join(root, package, "SOURCES", filename), show_path=options.path) |
586 |
valid = "" |
587 |
forwarded = "" |
588 |
if p.dep3['headers']: |
589 |
forwarded = p.dep3['headers'].get('Forwarded', "no") |
590 |
if p.dep3['valid']: |
591 |
valid="VALID" |
592 |
print "\t".join((module, package, str(p), forwarded, valid)) |
593 |
|
594 |
def cmd_dep3(options, parser): |
595 |
p = Patch(options.patch) |
596 |
p.add_dep3() |
597 |
|
598 |
def cmd_package_new_version(options, parser): |
599 |
# Determine the package name |
600 |
if options.upstream: |
601 |
try: |
602 |
package = get_downstream_from_upstream(options.package, options.version)[0] |
603 |
except ValueError, e: |
604 |
print >>sys.stderr, "ERROR: %s" % e |
605 |
sys.exit(1) |
606 |
else: |
607 |
package = options.package |
608 |
|
609 |
# Directories packages are located in |
610 |
root = os.path.expanduser(PKGROOT) |
611 |
cwd = os.path.join(root, package) |
612 |
|
613 |
# Checkout package to ensure the checkout reflects the latest changes |
614 |
try: |
615 |
subprocess.check_call(['mgarepo', 'co', package], cwd=root) |
616 |
except subprocess.CalledProcessError: |
617 |
sys.exit(1) |
618 |
|
619 |
# SpecFile class handles the actual version+release change |
620 |
s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)) |
621 |
print "%s => %s" % (s.version, options.version) |
622 |
if not s.update(options.version, force=options.force): |
623 |
sys.exit(1) |
624 |
|
625 |
# Check hash, if given |
626 |
if options.hexdigest is not None: |
627 |
sources = [name for name, origname in s.sources.iteritems() if '://' in origname] |
628 |
if not len(sources): |
629 |
print >>sys.stderr, "ERROR: Cannot determine source file (for hash check)!" |
630 |
sys.stderr(1) |
631 |
|
632 |
for filename in sources: |
633 |
if not is_valid_hash(os.path.join(cwd, "SOURCES", filename), options.algo, options.hexdigest): |
634 |
print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path |
635 |
print >>sys.stderr, "ERROR: Reverting changes!" |
636 |
subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd) |
637 |
sys.exit(1) |
638 |
|
639 |
# We can even checkin and submit :-) |
640 |
if options.submit: |
641 |
try: |
642 |
# checkin changes |
643 |
subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd) |
644 |
# and submit |
645 |
subprocess.check_call(['mgarepo', 'submit'], cwd=cwd) |
646 |
except subprocess.CalledProcessError: |
647 |
sys.exit(1) |
648 |
|
649 |
def cmd_parse_ftp_release_list(options, parser): |
650 |
def _send_reply_mail(contents, orig_msg, to, error=False): |
651 |
"""Send an reply email""" |
652 |
contents.seek(0) |
653 |
msg = MIMEText(contents.read(), _charset='utf-8') |
654 |
if error: |
655 |
# XXX - ugly |
656 |
contents.seek(0) |
657 |
lastline = contents.read().splitlines()[-1] |
658 |
# Remove things like "ERROR: " and so on from the last line |
659 |
lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline) |
660 |
subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)" |
661 |
else: |
662 |
subjecterror = "" |
663 |
msg['Subject'] = "Re: %s%s" % (orig_msg['Subject'], subjecterror) |
664 |
msg['To'] = to |
665 |
msg["In-Reply-To"] = orig_msg["Message-ID"] |
666 |
msg["References"] = orig_msg["Message-ID"] |
667 |
|
668 |
# Call sendmail program directly so it doesn't matter if the service is running |
669 |
cmd = ['/usr/sbin/sendmail', '-oi', '--'] |
670 |
cmd.extend([to]) |
671 |
p = subprocess.Popen(cmd, stdin=subprocess.PIPE) |
672 |
p.stdin.write(msg.as_string()) |
673 |
p.stdin.flush() |
674 |
p.stdin.close() |
675 |
p.wait() |
676 |
|
677 |
|
678 |
msg = email.email.message_from_file(sys.stdin) |
679 |
|
680 |
if options.mail: |
681 |
stdout = tempfile.TemporaryFile() |
682 |
stderr = stdout |
683 |
else: |
684 |
stdout = sys.stdout |
685 |
stderr = sys.stderr |
686 |
|
687 |
try: |
688 |
module = msg['X-Module-Name'] |
689 |
version = msg['X-Module-Version'] |
690 |
hexdigest = msg['X-Module-SHA256-tar.xz'] |
691 |
except KeyError, e: |
692 |
print >>stderr, "ERROR: %s" % e |
693 |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
694 |
sys.exit(1) |
695 |
|
696 |
try: |
697 |
packages = get_downstream_from_upstream(module, version) |
698 |
except ValueError, e: |
699 |
print >>stderr, "ERROR: %s" % e |
700 |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True) |
701 |
sys.exit(1) |
702 |
|
703 |
if options.wait: |
704 |
# maildrop aborts and will try to deliver after 5min |
705 |
# fork to avoid this |
706 |
if os.fork() != 0: sys.exit(0) |
707 |
time.sleep(SLEEP_INITIAL) |
708 |
|
709 |
error = False |
710 |
for package in packages: |
711 |
if subprocess.call(['mga-gnome', 'increase', '--submit', '--hash', hexdigest, package, version], stdout=stdout, stderr=stderr): |
712 |
error = True |
713 |
|
714 |
if options.mail: _send_reply_mail(stdout, msg, options.mail, error=error) |
715 |
|
716 |
def main(): |
717 |
description = """Mageia GNOME commands.""" |
718 |
epilog="""Report bugs to Olav Vitters""" |
719 |
parser = argparse.ArgumentParser(description=description,epilog=epilog) |
720 |
|
721 |
# SUBPARSERS |
722 |
subparsers = parser.add_subparsers(title='subcommands') |
723 |
# install |
724 |
subparser = subparsers.add_parser('co', help='checkout all GNOME modules') |
725 |
subparser.set_defaults( |
726 |
func=cmd_co |
727 |
) |
728 |
|
729 |
subparser = subparsers.add_parser('packages', help='list all GNOME packages') |
730 |
subparser.add_argument("-m", "--m", action="store_true", dest="upstream", |
731 |
help="Show upstream module") |
732 |
subparser.add_argument( "--version", action="store_true", dest="show_version", |
733 |
help="Show version numbers") |
734 |
subparser.add_argument( "--diff", action="store_true", dest="diff", |
735 |
help="Only show packages with different version") |
736 |
subparser.set_defaults( |
737 |
func=cmd_ls, upstream=False, show_version=False, diff=False |
738 |
) |
739 |
|
740 |
subparser = subparsers.add_parser('patches', help='list all GNOME patches') |
741 |
subparser.add_argument("-p", "--path", action="store_true", dest="path", |
742 |
help="Show full path to patch") |
743 |
subparser.set_defaults( |
744 |
func=cmd_patches, path=False |
745 |
) |
746 |
|
747 |
subparser = subparsers.add_parser('dep3', help='Add dep3 headers') |
748 |
subparser.add_argument("patch", help="Patch") |
749 |
subparser.set_defaults( |
750 |
func=cmd_dep3, path=False |
751 |
) |
752 |
|
753 |
subparser = subparsers.add_parser('increase', help='Increase version number') |
754 |
subparser.add_argument("package", help="Package name") |
755 |
subparser.add_argument("version", help="Version number") |
756 |
subparser.add_argument("-f", "--force", action="store_true", dest="force", |
757 |
help="Override warnings, just do it") |
758 |
subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream", |
759 |
help="Package name reflects the upstream name") |
760 |
subparser.add_argument("-s", "--submit", action="store_true", dest="submit", |
761 |
help="Commit changes and submit") |
762 |
subparser.add_argument("-a", "--algorithm", choices=hashlib.algorithms, dest="algo", |
763 |
help="Hash algorithm") |
764 |
subparser.add_argument("--hash", dest="hexdigest", |
765 |
help="Hexdigest of the hash") |
766 |
subparser.set_defaults( |
767 |
func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256", |
768 |
force=False |
769 |
) |
770 |
|
771 |
subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email') |
772 |
subparser.add_argument("-m", "--mail", help="Email address to send the progress to") |
773 |
subparser.add_argument("-w", "--wait", action="store_true", |
774 |
help="Wait before trying to retrieve the new version") |
775 |
subparser.set_defaults( |
776 |
func=cmd_parse_ftp_release_list |
777 |
) |
778 |
|
779 |
if len(sys.argv) == 1: |
780 |
parser.print_help() |
781 |
sys.exit(2) |
782 |
|
783 |
options = parser.parse_args() |
784 |
|
785 |
try: |
786 |
options.func(options, parser) |
787 |
except KeyboardInterrupt: |
788 |
print('Interrupted') |
789 |
sys.exit(1) |
790 |
except EOFError: |
791 |
print('EOF') |
792 |
sys.exit(1) |
793 |
except IOError, e: |
794 |
if e.errno != errno.EPIPE: |
795 |
raise |
796 |
sys.exit(0) |
797 |
|
798 |
if __name__ == "__main__": |
799 |
main() |