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

Diff of /mga-gnome/trunk/mga-gnome

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3088 by ovitters, Mon Feb 27 10:42:33 2012 UTC revision 3654 by ovitters, Wed Mar 21 21:49:09 2012 UTC
# Line 1  Line 1 
1  #!/usr/bin/python  #!/usr/bin/python -u
2    
3  # A lot of the code comes from ftpadmin, see  # A lot of the code comes from ftpadmin, see
4  #   http://git.gnome.org/browse/sysadmin-bin/tree/ftpadmin  #   http://git.gnome.org/browse/sysadmin-bin/tree/ftpadmin
# Line 33  from sgmllib import SGMLParser Line 33  from sgmllib import SGMLParser
33  import urllib2  import urllib2
34  import urlparse  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    # packages --sort
50    import itertools
51    
52  MEDIA="Core Release Source"  MEDIA="Core Release Source"
53  URL="http://download.gnome.org/sources/"  URL="http://download.gnome.org/sources/"
54  PKGROOT='~/pkgs'  PKGROOT='~/pkgs'
55    SLEEP_INITIAL=180
56    SLEEP_REPEAT=30
57    SLEEP_TIMES=20
58    
59    re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*')
60  re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')  re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')
61    
62  def version_cmp(a, b):  def version_cmp(a, b):
# Line 73  def judge_version_increase(version_old, Line 93  def judge_version_increase(version_old,
93          5+: Ok"""          5+: Ok"""
94          versions = (version_old, version_new)          versions = (version_old, version_new)
95    
         print " => ".join(versions)  
   
96          # First do a basic version comparison to ensure version_new is actually newer          # First do a basic version comparison to ensure version_new is actually newer
97          compare = version_cmp(version_new, version_old)          compare = version_cmp(version_new, version_old)
98    
99          if compare == 0:          if compare == 0:
100                # 1.0.0 -> 1.0.1
101              return (-2, "Already at version %s!" % (version_old))              return (-2, "Already at version %s!" % (version_old))
102    
103          if compare != 1:          if compare != 1:
104                # 1.0.1 -> 1.0.0
105              return (-3, "Version %s is older than current version %s!" % (version_new, version_old))              return (-3, "Version %s is older than current version %s!" % (version_new, version_old))
106    
107          # Version is newer, but we don't want to see if it follows the GNOME versioning scheme          # Version is newer, but we don't want to see if it follows the GNOME versioning scheme
# Line 102  def judge_version_increase(version_old, Line 122  def judge_version_increase(version_old,
122          # Major+minor the same? Then go ahead and upgrade!          # Major+minor the same? Then go ahead and upgrade!
123          if majmins[0] == majmins[1]:          if majmins[0] == majmins[1]:
124              # Majmin of both versions are the same, looks good!              # Majmin of both versions are the same, looks good!
125                # 1.1.x -> 1.1.x or 1.0.x -> 1.0.x
126              return (10, None)              return (10, None)
127    
128          # More detailed analysis needed, so figure out the numbers          # More detailed analysis needed, so figure out the numbers
# Line 109  def judge_version_increase(version_old, Line 130  def judge_version_increase(version_old,
130    
131          # Check/ensure major version number is the same          # Check/ensure major version number is the same
132          if majmin_nrs[0][0] != majmin_nrs[1][0]:          if majmin_nrs[0][0] != majmin_nrs[1][0]:
133                # 1.0.x -> 2.0.x
134              return (1, "Major version number increase")              return (1, "Major version number increase")
135    
136          # Minor indicates stable/unstable          # Minor indicates stable/unstable
# Line 117  def judge_version_increase(version_old, Line 139  def judge_version_increase(version_old,
139          # Upgrading to unstable is weird          # Upgrading to unstable is weird
140          if not devstate[1]:          if not devstate[1]:
141              if devstate[0]:              if devstate[0]:
142                    # 1.2.x -> 1.3.x
143                  return (1, "Stable to unstable increase")                  return (1, "Stable to unstable increase")
144    
145                # 1.3.x -> 1.5.x
146              return (4, "Unstable to unstable version increase")              return (4, "Unstable to unstable version increase")
147    
148          # Unstable => stable is always ok          # Unstable => stable is always ok
149          if not devstate[0]:          if not devstate[0]:
150                # 1.1.x -> 1.2.x
151              return (5, "Unstable to stable")              return (5, "Unstable to stable")
152    
153          # Can only be increase of minors from one stable to the next          # Can only be increase of minors from one stable to the next
154            # 1.0.x -> 1.2.x
155          return (6, "Stable version increase")          return (6, "Stable version increase")
156    
157  def line_input (file):  def line_input (file):
# Line 203  class XzTarFile(tarfile.TarFile): Line 229  class XzTarFile(tarfile.TarFile):
229  if not hasattr(tarfile.TarFile, 'xzopen'):  if not hasattr(tarfile.TarFile, 'xzopen'):
230      tarfile.open = XzTarFile.open      tarfile.open = XzTarFile.open
231    
232    def is_valid_hash(path, algo, hexdigest):
233        if algo not in hashlib.algorithms:
234            raise ValueError("Unknown hash algorithm: %s" % algo)
235    
236        local_hash = getattr(hashlib, algo)()
237    
238        with open(path, 'rb') as fp:
239            data = fp.read(32768)
240            while data:
241                local_hash.update(data)
242                data = fp.read(32768)
243    
244        return local_hash.hexdigest() == hexdigest
245    
246  class SpecFile(object):  class SpecFile(object):
247      re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)      re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)
248      re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)      re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)
# Line 214  class SpecFile(object): Line 254  class SpecFile(object):
254      @property      @property
255      def version(self):      def version(self):
256          return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0]          return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0]
257        @property
258        def sources(self):
259            ts = rpm.ts()
260            spec = ts.parseSpec(self.path)
261            srclist = spec.sources if isinstance(spec.sources, (list, tuple)) \
262                            else spec.sources()
263            return dict((os.path.basename(name), name) for name, no, flags in srclist)
264    
265      def update(self, version):      def update(self, version, force=False):
266          """Update specfile (increase version)"""          """Update specfile (increase version)"""
267          cur_version = self.version          cur_version = self.version
268    
# Line 226  class SpecFile(object): Line 273  class SpecFile(object):
273              return False              return False
274    
275          if judgement < 5:          if judgement < 5:
276              print >>sys.stderr, "WARNING: %s!" % (msg)              print "WARNING: %s!" % (msg)
277              return False              if not force: return False
278    
279          # XXX - os.path.join is hackish          # XXX - os.path.join is hackish
280          if subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) != '':          svn_diff_output = subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')])
281            if svn_diff_output != '':
282                print svn_diff_output
283              print >>sys.stderr, "ERROR: Package has uncommitted changes!"              print >>sys.stderr, "ERROR: Package has uncommitted changes!"
284              return False              if not force:
285                    return False
286    
287                # Forcing package submission: revert changes
288                try:
289                    print >>sys.stderr, "WARNING: Force used; reverting svn changes"
290                    subprocess.check_call(["svn", "revert", "-R", os.path.join(self.path, '..')])
291                except subprocess.CalledProcessError:
292                    return False
293    
294          with open(self.path, "rw") as f:          with open(self.path, "rw") as f:
295              data = f.read()              data = f.read()
# Line 260  class SpecFile(object): Line 317  class SpecFile(object):
317              print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version              print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version
318              return False              return False
319    
320    
321            # Try to download the new tarball various times and wait between attempts
322            tries = 0
323            while tries < SLEEP_TIMES:
324                tries += 1
325                if tries > 1: time.sleep(SLEEP_REPEAT)
326                try:
327                    # Download new tarball
328                    subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd)
329                    # success, so exit loop
330                    break
331                except subprocess.CalledProcessError, e:
332                    # mgarepo sync returns 1 if the tarball cannot be downloaded
333                    if e.returncode != 1:
334                        return False
335            else:
336                return False
337    
338    
339          try:          try:
             # Download new tarball  
             subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd)  
340              # Check patches still apply              # Check patches still apply
341              subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd)              subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd)
342          except subprocess.CalledProcessError:          except subprocess.CalledProcessError:
343                logfile = os.path.join(os.path.dirname(self.path), 'log.%s' % os.path.splitext(os.path.basename(self.path))[0])
344                if os.path.exists(logfile):
345                    subprocess.call(['tail', '-n', '15', logfile])
346              return False              return False
347    
348          return True          return True
# Line 410  class Patch(object): Line 487  class Patch(object):
487    
488          return self._svn_author          return self._svn_author
489    
 def get_upstream_names():  
     urlopen = urllib2.build_opener()  
490    
491      good_dir = re.compile('^[-A-Za-z0-9_+.]+/$')  class Upstream(object):
492    
493        limit = None
494    
495        def __init__(self):
496            urlopen = urllib2.build_opener()
497    
498            good_dir = re.compile('^[-A-Za-z0-9_+.]+/$')
499    
500      # Get the files          # Get the files
501      usock = urlopen.open(URL)          usock = urlopen.open(URL)
502      parser = urllister()          parser = urllister()
503      parser.feed(usock.read())          parser.feed(usock.read())
504      usock.close()          usock.close()
505      parser.close()          parser.close()
506      files = parser.urls          files = parser.urls
507    
508      tarballs = set([filename.replace('/', '') for filename in files if good_dir.search(filename)])          tarballs = set([filename.replace('/', '') for filename in files if good_dir.search(filename)])
509            if self.limit is not None:
510                tarballs.intersection_update(self.limit)
511    
512      return tarballs          self.names = tarballs
513    
514  def get_downstream_names():  class Downstream(object):
515      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]*)$')      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]*)$')
516    
517      contents = subprocess.check_output(['urpmf', '--files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines()      def __init__(self):
518            contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines()
519    
520      FILES = {}          FILES = {}
521      TARBALLS = {}          TARBALLS = {}
522    
523      for line in  contents:          for line in  contents:
524          try:              try:
525              srpm, filename = line.split(":")                  srpm, version, filename = line.split("|")
526          except ValueError:              except ValueError:
527              print >>sys.stderr, line                  print >>sys.stderr, line
528              continue                  continue
529    
530                if '.tar' in filename:
531                    r = self.re_file.match(filename)
532                    if r:
533                        fileinfo = r.groupdict()
534                        module = fileinfo['module']
535    
536                        if module not in TARBALLS:
537                            TARBALLS[module] = {}
538                        TARBALLS[module][srpm] = version
539    
540                if srpm not in FILES:
541                    FILES[srpm] = set()
542                FILES[srpm].add(filename)
543    
544            self.tarballs = TARBALLS
545            self.files = FILES
546    
547        def get_downstream_from_upstream(self, upstream, version):
548            if upstream not in self.tarballs:
549                raise ValueError("No packages for upstream name: %s" % upstream)
550    
551            if len(self.tarballs[upstream]) == 1:
552                return self.tarballs[upstream].keys()
553    
554            # Directories packages are located in
555            root = os.path.expanduser(PKGROOT)
556    
557            packages = {}
558            for package in self.tarballs[upstream].keys():
559                cwd = os.path.join(root, package)
560    
561          if '.tar' in filename:              # Checkout package to ensure the checkout reflects the latest changes
562              r = re_file.match(filename)              try:
563              if r:                  subprocess.check_call(['mgarepo', 'co', package], cwd=root)
564                  fileinfo = r.groupdict()              except subprocess.CalledProcessError:
565                  module = fileinfo['module']                  raise ValueError("Multiple packages found and cannot checkout %s" % package)
566    
567                  if module not in TARBALLS:              # Determine version from spec file
568                      TARBALLS[module] = set()              try:
569                  TARBALLS[module].add(srpm)                  packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version
570                except subprocess.CalledProcessError:
571          if srpm not in FILES:                  raise ValueError("Multiple packages found and cannot determine version of %s" % package)
             FILES[srpm] = set()  
         FILES[srpm].add(filename)  
572    
573      return TARBALLS, FILES          # Return all packages reflecting the current version
574            matches = [package for package in packages if packages[package] == version]
575            if len(matches):
576                return matches
577    
578            # Return all packages reflecting the version before the current version
579            latest_version = get_latest_version(packages.values(), max_version=version)
580            matches = [package for package in packages if packages[package] == latest_version]
581            if len(matches):
582                return matches
583    
584            # Give up
585            raise ValueError("Multiple packages found and cannot determine package for version %s" % version)
586    
587  def write_file(path, data):  def write_file(path, data):
588      with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst:      with tempfile.NamedTemporaryFile(dir=os.path.dirname(path), delete=False) as fdst:
# Line 466  def write_file(path, data): Line 591  def write_file(path, data):
591          os.rename(fdst.name, path)          os.rename(fdst.name, path)
592    
593  def cmd_co(options, parser):  def cmd_co(options, parser):
594      upstream = get_upstream_names()      root = os.path.expanduser(PKGROOT)
     downstream, downstream_files = get_downstream_names()  
595    
596      cwd = os.path.expanduser(PKGROOT)      for package, module, package_version, spec_version, downstream_files in sorted(join_streams()):
597            print "%s => %s" % (module, package)
598            subprocess.call(['mgarepo', 'co', package], cwd=root)
599    
600      matches = upstream & set(downstream.keys())  def join_streams(show_version=False, only_diff_version=False):
601      for module in matches:      root = os.path.expanduser(PKGROOT)
         print module, "\t".join(downstream[module])  
         for package in downstream[module]:  
             subprocess.call(['mgarepo', 'co', package], cwd=cwd)  
602    
603  def cmd_ls(options, parser):      upstream = Upstream().names
604      upstream = get_upstream_names()      downstream = Downstream()
     downstream, downstream_files = get_downstream_names()  
605    
606      matches = upstream & set(downstream.keys())      matches = upstream & set(downstream.tarballs.keys())
607      for module in matches:      for module in matches:
608          print "\n".join(sorted(downstream[module]))          for package in downstream.tarballs[module].keys():
609                package_version = downstream.tarballs[module][package]
610                spec_version = None
611                if show_version or only_diff_version:
612                    cwd = os.path.join(root, package)
613                    try:
614                        spec_version = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version
615                    except subprocess.CalledProcessError:
616                        spec_version = 'N/A'
617    
618  def cmd_patches(options, parser):              if only_diff_version and package_version == spec_version:
619      upstream = get_upstream_names()                  continue
620      downstream, downstream_files = get_downstream_names()  
621                yield (package, module, package_version, spec_version, downstream.files[package])
622    
623    def cmd_ls(options, parser):
624        streams = join_streams(show_version=options.show_version, only_diff_version=options.diff)
625        if options.sort:
626            SORT=dict(zip(options.sort.read().splitlines(), itertools.count()))
627    
628            streams = sorted(streams, key=lambda a: (SORT.get(a[1], 9999), a[0]))
629        else:
630            streams = sorted(streams)
631    
632      path = os.path.expanduser(PKGROOT)      for package, module, package_version, spec_version, downstream_files in streams:
633            sys.stdout.write(package)
634            if options.upstream: sys.stdout.write("\t%s" % module)
635            if options.show_version: sys.stdout.write("\t%s\t%s" % (spec_version, package_version))
636            print
637    
638      import pprint  def cmd_patches(options, parser):
639        root = os.path.expanduser(PKGROOT)
640    
641      matches = upstream & set(downstream.keys())      for package, module, package_version, spec_version, downstream_files in sorted(join_streams()):
642      for module in sorted(matches):          for filename in downstream_files:
643          for srpm in downstream[module]:              if '.patch' in filename or '.diff' in filename:
644              for filename in downstream_files[srpm]:  
645                  if '.patch' in filename or '.diff' in filename:                  p = Patch(os.path.join(root, package, "SOURCES", filename), show_path=options.path)
646                    valid = ""
647                      p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path)                  forwarded = ""
648                      valid = ""                  if p.dep3['headers']:
649                      forwarded = ""                      forwarded = p.dep3['headers'].get('Forwarded', "no")
650                      if p.dep3['headers']:                      if p.dep3['valid']:
651                          forwarded = p.dep3['headers'].get('Forwarded', "no")                          valid="VALID"
652                          if p.dep3['valid']:                  print "\t".join((module, package, str(p), forwarded, valid))
                             valid="VALID"  
                     print "\t".join((module, srpm, str(p), forwarded, valid))  
653    
654  def cmd_dep3(options, parser):  def cmd_dep3(options, parser):
655      p = Patch(options.patch)      p = Patch(options.patch)
# Line 515  def cmd_dep3(options, parser): Line 658  def cmd_dep3(options, parser):
658  def cmd_package_new_version(options, parser):  def cmd_package_new_version(options, parser):
659      # Determine the package name      # Determine the package name
660      if options.upstream:      if options.upstream:
661          downstream, downstream_files = get_downstream_names()          try:
662                package = Downstream().get_downstream_from_upstream(options.package, options.version)[0]
663          if options.package not in downstream:          except ValueError, e:
664              print >>sys.stderr, "ERROR: No packages for upstream name: %s" % options.package              print >>sys.stderr, "ERROR: %s" % e
             sys.exit(1)  
   
         if len(downstream[options.package]) != 1:  
             # XXX - Make it more intelligent  
             print >>sys.stderr, "ERROR: Multiple packages found for %s: %s" % (options.package, ", ".join(downstream[options.package]))  
665              sys.exit(1)              sys.exit(1)
   
         package = list(downstream[options.package])[0]  
666      else:      else:
667          package = options.package          package = options.package
668    
# Line 543  def cmd_package_new_version(options, par Line 679  def cmd_package_new_version(options, par
679      # SpecFile class handles the actual version+release change      # SpecFile class handles the actual version+release change
680      s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package))      s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package))
681      print "%s => %s" % (s.version, options.version)      print "%s => %s" % (s.version, options.version)
682      if not s.update(options.version):      if not s.update(options.version, force=options.force):
683          sys.exit(1)          sys.exit(1)
684    
685      # We can even checkin and submit :-)      # Check hash, if given
686      if options.submit:      if options.hexdigest is not None:
687          try:          sources = [name for name, origname in s.sources.iteritems() if '://' in origname]
688              # checkin changes          if not len(sources):
689              subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd)              print >>sys.stderr, "ERROR: Cannot determine source file (for hash check)!"
690              # and submit              sys.stderr(1)
691    
692            for filename in sources:
693                path = os.path.join(cwd, "SOURCES", filename)
694                if not is_valid_hash(path, options.algo, options.hexdigest):
695                    print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path
696                    print >>sys.stderr, "ERROR: Reverting changes!"
697                    subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd)
698                    sys.exit(1)
699    
700        try:
701            # If we made it this far, checkin the changes
702            subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd)
703    
704            # Submit is optional
705            if options.submit:
706              subprocess.check_call(['mgarepo', 'submit'], cwd=cwd)              subprocess.check_call(['mgarepo', 'submit'], cwd=cwd)
707          except subprocess.CalledProcessError:      except subprocess.CalledProcessError:
708              sys.exit(1)          sys.exit(1)
709    
710    def cmd_parse_ftp_release_list(options, parser):
711        def _send_reply_mail(contents, orig_msg, to, packages=[], error=False):
712            """Send an reply email"""
713            contents.seek(0)
714            msg = MIMEText(contents.read(), _charset='utf-8')
715    
716            if error:
717                # XXX - ugly
718                contents.seek(0)
719                lastline = contents.read().rstrip().splitlines()[-1]
720                # Remove things like "ERROR: " and so on from the last line
721                lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline)
722                # Remove things like "   - " (youri output from mgarepo submit)
723                lastline = re.sub(r'^\s+-\s+', '', lastline)
724                subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)"
725            else:
726                subjecterror = ""
727    
728            if packages:
729                subject = "%s %s%s" % (", ".join(packages), orig_msg['X-Module-Version'], subjecterror)
730            else:
731                subject = "Re: %s%s" % (orig_msg['Subject'], subjecterror)
732    
733            msg['Subject'] = subject
734            msg['To'] = to
735            msg["In-Reply-To"] = orig_msg["Message-ID"]
736            msg["References"] = orig_msg["Message-ID"]
737    
738            # Call sendmail program directly so it doesn't matter if the service is running
739            cmd = ['/usr/sbin/sendmail', '-oi', '--']
740            cmd.extend([to])
741            p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
742            p.stdin.write(msg.as_string())
743            p.stdin.flush()
744            p.stdin.close()
745            p.wait()
746    
747    
748        msg = email.email.message_from_file(sys.stdin)
749    
750        if options.mail:
751            stdout = tempfile.TemporaryFile()
752            stderr = stdout
753        else:
754            stdout = sys.stdout
755            stderr = sys.stderr
756    
757        try:
758            module = msg['X-Module-Name']
759            version = msg['X-Module-Version']
760            hexdigest = msg['X-Module-SHA256-tar.xz']
761        except KeyError, e:
762            print >>stderr, "ERROR: %s" % e
763            if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True)
764            sys.exit(1)
765    
766        try:
767            packages = Downstream().get_downstream_from_upstream(module, version)
768        except ValueError, e:
769            print >>stderr, "ERROR: %s" % e
770            if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True)
771            sys.exit(1)
772    
773        if options.wait:
774            # maildrop aborts and will try to deliver after 5min
775            # fork to avoid this
776            if os.fork() != 0: sys.exit(0)
777            # wait SLEEP_INITIAL after the message was sent
778            secs = SLEEP_INITIAL
779            t = email.utils.parsedate_tz(msg['Date'])
780            if t is not None:
781                msg_time = email.utils.mktime_tz(t)
782                secs = SLEEP_INITIAL - (time.time() - msg_time)
783    
784            if secs > 0: time.sleep(secs)
785    
786        error = False
787        for package in packages:
788            cmd = ['mga-gnome', 'increase', '--hash', hexdigest]
789            if options.submit:
790                cmd.append('--submit')
791            if options.force:
792                cmd.append('--force')
793            cmd.extend((package, version))
794            if subprocess.call(cmd, stdout=stdout, stderr=stderr):
795                error = True
796    
797        if options.mail: _send_reply_mail(stdout, msg, options.mail, packages=packages, error=error)
798    
799  def main():  def main():
800      description = """Mageia GNOME commands."""      description = """Mageia GNOME commands."""
801      epilog="""Report bugs to Olav Vitters"""      epilog="""Report bugs to Olav Vitters"""
802      parser = argparse.ArgumentParser(description=description,epilog=epilog)      parser = argparse.ArgumentParser(description=description,epilog=epilog)
803        parser.add_argument("-l", "--limit", type=argparse.FileType('r', 0),
804                            dest="limit_upstream", metavar="FILE",
805                            help="File containing upstream names")
806    
807      # SUBPARSERS      # SUBPARSERS
808      subparsers = parser.add_subparsers(title='subcommands')      subparsers = parser.add_subparsers(title='subcommands')
# Line 571  def main(): Line 813  def main():
813      )      )
814    
815      subparser = subparsers.add_parser('packages', help='list all GNOME packages')      subparser = subparsers.add_parser('packages', help='list all GNOME packages')
816        subparser.add_argument("-m", "--m", action="store_true", dest="upstream",
817                                           help="Show upstream module")
818        subparser.add_argument(      "--version", action="store_true", dest="show_version",
819                                           help="Show version numbers")
820        subparser.add_argument(      "--diff", action="store_true", dest="diff",
821                                           help="Only show packages with different version")
822        subparser.add_argument(      "--sort", type=argparse.FileType('r', 0),
823                            dest="sort", metavar="FILE",
824                            help="Sort packages according to order in given FILE")
825    
826      subparser.set_defaults(      subparser.set_defaults(
827          func=cmd_ls          func=cmd_ls, upstream=False, show_version=False, diff=False
828      )      )
829    
830      subparser = subparsers.add_parser('patches', help='list all GNOME patches')      subparser = subparsers.add_parser('patches', help='list all GNOME patches')
# Line 591  def main(): Line 843  def main():
843      subparser = subparsers.add_parser('increase', help='Increase version number')      subparser = subparsers.add_parser('increase', help='Increase version number')
844      subparser.add_argument("package", help="Package name")      subparser.add_argument("package", help="Package name")
845      subparser.add_argument("version", help="Version number")      subparser.add_argument("version", help="Version number")
846        subparser.add_argument("-f", "--force", action="store_true", dest="force",
847                                           help="Override warnings, just do it")
848      subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream",      subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream",
849                                         help="Package name reflects the upstream name")                                         help="Package name reflects the upstream name")
850      subparser.add_argument("-s", "--submit", action="store_true", dest="submit",      subparser.add_argument("-s", "--submit", action="store_true", dest="submit",
851                                         help="Commit changes and submit")                                         help="Commit changes and submit")
852        subparser.add_argument("-a", "--algorithm", choices=hashlib.algorithms, dest="algo",
853                                           help="Hash algorithm")
854        subparser.add_argument("--hash", dest="hexdigest",
855                                           help="Hexdigest of the hash")
856        subparser.set_defaults(
857            func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256",
858            force=False
859        )
860    
861        subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email')
862        subparser.add_argument("-m", "--mail", help="Email address to send the progress to")
863        subparser.add_argument("-w", "--wait", action="store_true",
864                                     help="Wait before trying to retrieve the new version")
865        subparser.add_argument("-s", "--submit", action="store_true", dest="submit",
866                                           help="Commit changes and submit")
867        subparser.add_argument("-f", "--force", action="store_true",
868                                     help="Force submission")
869      subparser.set_defaults(      subparser.set_defaults(
870          func=cmd_package_new_version, submit=False, upstream=False          func=cmd_parse_ftp_release_list, force=False, wait=False
871      )      )
872    
873      if len(sys.argv) == 1:      if len(sys.argv) == 1:
# Line 604  def main(): Line 875  def main():
875          sys.exit(2)          sys.exit(2)
876    
877      options = parser.parse_args()      options = parser.parse_args()
878        if options.limit_upstream:
879            Upstream.limit = set(options.limit_upstream.read().strip("\n").splitlines())
880    
881      try:      try:
882          options.func(options, parser)          options.func(options, parser)
# Line 619  def main(): Line 892  def main():
892          sys.exit(0)          sys.exit(0)
893    
894  if __name__ == "__main__":  if __name__ == "__main__":
895        os.environ['PYTHONUNBUFFERED'] = '1'
896      main()      main()

Legend:
Removed from v.3088  
changed lines
  Added in v.3654

  ViewVC Help
Powered by ViewVC 1.1.30