/[soft]/mga-gnome/trunk/mga-gnome
ViewVC logotype

Annotation of /mga-gnome/trunk/mga-gnome

Parent Directory Parent Directory | Revision Log Revision Log


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

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.30