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