/[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 3649 by ovitters, Wed Mar 21 19:17:35 2012 UTC revision 5289 by ovitters, Sat Aug 4 18:36:28 2012 UTC
# Line 46  import time Line 46  import time
46  # version freeze  # version freeze
47  import datetime  import datetime
48    
49  MEDIA="Core Release Source"  # packages --sort
50  URL="http://download.gnome.org/sources/"  import itertools
51  PKGROOT='~/pkgs'  
52    # check-latest
53    import requests
54    
55  SLEEP_INITIAL=180  SLEEP_INITIAL=180
56  SLEEP_REPEAT=30  SLEEP_REPEAT=30
57  SLEEP_TIMES=20  SLEEP_TIMES=20
# Line 79  def get_latest_version(versions, max_ver Line 82  def get_latest_version(versions, max_ver
82              latest = version              latest = version
83      return latest      return latest
84    
85    def get_safe_max_version(version):
86        if not re_majmin.match(version):
87            return None
88    
89        majmin_nr = map(long, re_majmin.sub(r'\1', version).split('.'))
90    
91        if majmin_nr[1] % 2 == 0:
92            return "%d.%d" % (majmin_nr[0], majmin_nr[1] + 1)
93        else:
94            return "%d.%d" % (majmin_nr[0], majmin_nr[1] + 2)
95    
96  def judge_version_increase(version_old, version_new):  def judge_version_increase(version_old, version_new):
97          """Judge quality of version increase:          """Judge quality of version increase:
98    
# Line 487  class Patch(object): Line 501  class Patch(object):
501    
502  class Upstream(object):  class Upstream(object):
503    
504        URL="http://download.gnome.org/sources/"
505      limit = None      limit = None
506        _cache_versions = {}
507    
508      def __init__(self):      def __init__(self):
509          urlopen = urllib2.build_opener()          urlopen = urllib2.build_opener()
# Line 495  class Upstream(object): Line 511  class Upstream(object):
511          good_dir = re.compile('^[-A-Za-z0-9_+.]+/$')          good_dir = re.compile('^[-A-Za-z0-9_+.]+/$')
512    
513          # Get the files          # Get the files
514          usock = urlopen.open(URL)          usock = urlopen.open(self.URL)
515          parser = urllister()          parser = urllister()
516          parser.feed(usock.read())          parser.feed(usock.read())
517          usock.close()          usock.close()
# Line 508  class Upstream(object): Line 524  class Upstream(object):
524    
525          self.names = tarballs          self.names = tarballs
526    
527  def get_downstream_names():      @classmethod
528      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]*)$')      def versions(cls, module):
529            # XXX - ugly
530            if module not in cls._cache_versions:
531                versions = None
532    
533                url = '%s%s/cache.json' % (cls.URL, module)
534                r = requests.get(url)
535                j = r.json
536                if j is not None and len(j) > 2 and module in j[2]:
537                    versions = j[2][module]
538    
539      contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines()              cls._cache_versions[module] = versions
540    
541      FILES = {}          return cls._cache_versions[module]
     TARBALLS = {}  
542    
543      for line in  contents:  class Downstream(object):
544          try:      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]*)$')
             srpm, version, filename = line.split("|")  
         except ValueError:  
             print >>sys.stderr, line  
             continue  
545    
546          if '.tar' in filename:      MEDIA="Core Release Source"
547              r = re_file.match(filename)      PKGROOT='~/pkgs'
548              if r:      DISTRO=None
                 fileinfo = r.groupdict()  
                 module = fileinfo['module']  
   
                 if module not in TARBALLS:  
                     TARBALLS[module] = {}  
                 TARBALLS[module][srpm] = version  
   
         if srpm not in FILES:  
             FILES[srpm] = set()  
         FILES[srpm].add(filename)  
549    
550      return TARBALLS, FILES      def __init__(self):
551            contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", self.MEDIA], close_fds=True).strip("\n").splitlines()
552    
553  def get_downstream_from_upstream(upstream, version):          FILES = {}
554      # Determine the package name          TARBALLS = {}
     downstream, downstream_files = get_downstream_names()  
555    
556      if upstream not in downstream:          for line in  contents:
557          raise ValueError("No packages for upstream name: %s" % upstream)              try:
558                    srpm, version, filename = line.split("|")
559                except ValueError:
560                    print >>sys.stderr, line
561                    continue
562    
563      if len(downstream[upstream]) == 1:              if '.tar' in filename:
564          return downstream[upstream].keys()                  r = self.re_file.match(filename)
565                    if r:
566                        fileinfo = r.groupdict()
567                        module = fileinfo['module']
568    
569                        if module not in TARBALLS:
570                            TARBALLS[module] = {}
571                        TARBALLS[module][srpm] = version
572    
573                if srpm not in FILES:
574                    FILES[srpm] = set()
575                FILES[srpm].add(filename)
576    
577      # Directories packages are located in          self.tarballs = TARBALLS
578      root = os.path.expanduser(PKGROOT)          self.files = FILES
579    
580      packages = {}      @classmethod
581      for package in downstream[upstream].keys():      def co(cls, package, cwd=None):
582          cwd = os.path.join(root, package)          if cwd is None:
583                cwd = os.path.expanduser(cls.PKGROOT)
584    
585            cmd = ['mgarepo', 'co']
586            if cls.DISTRO:
587                cmd.extend(('-d', cls.DISTRO))
588            cmd.append(package)
589            return subprocess.check_call(cmd, cwd=cwd)
590    
591        def get_downstream_from_upstream(self, upstream, version):
592            if upstream not in self.tarballs:
593                raise ValueError("No packages for upstream name: %s" % upstream)
594    
595            if len(self.tarballs[upstream]) == 1:
596                return self.tarballs[upstream].keys()
597    
598            # Directories packages are located in
599            root = os.path.expanduser(self.PKGROOT)
600    
601            packages = {}
602            for package in self.tarballs[upstream].keys():
603                cwd = os.path.join(root, package)
604    
605          # Checkout package to ensure the checkout reflects the latest changes              # Checkout package to ensure the checkout reflects the latest changes
606          try:              try:
607              subprocess.check_call(['mgarepo', 'co', package], cwd=root)                  self.co(package, cwd=root)
608          except subprocess.CalledProcessError:              except subprocess.CalledProcessError:
609              raise ValueError("Multiple packages found and cannot checkout %s" % package)                  raise ValueError("Multiple packages found and cannot checkout %s" % package)
610    
611          # Determine version from spec file              # Determine version from spec file
612          try:              try:
613              packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version                  packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version
614          except subprocess.CalledProcessError:              except subprocess.CalledProcessError:
615              raise ValueError("Multiple packages found and cannot determine version of %s" % package)                  raise ValueError("Multiple packages found and cannot determine version of %s" % package)
616    
617      # Return all packages reflecting the current version          # Return all packages reflecting the current version
618      matches = [package for package in packages if packages[package] == version]          matches = [package for package in packages if packages[package] == version]
619      if len(matches):          if len(matches):
620          return matches              return matches
621    
622      # Return all packages reflecting the version before the current version          # Return all packages reflecting the version before the current version
623      latest_version = get_latest_version(packages.values(), max_version=version)          latest_version = get_latest_version(packages.values(), max_version=version)
624      matches = [package for package in packages if packages[package] == latest_version]          matches = [package for package in packages if packages[package] == latest_version]
625      if len(matches):          if len(matches):
626          return matches              return matches
627    
628      # Give up          # Give up
629      raise ValueError("Multiple packages found and cannot determine package for version %s" % version)          raise ValueError("Multiple packages found and cannot determine package for version %s" % version)
630    
631  def write_file(path, data):  def write_file(path, data):
632      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 589  def write_file(path, data): Line 635  def write_file(path, data):
635          os.rename(fdst.name, path)          os.rename(fdst.name, path)
636    
637  def cmd_co(options, parser):  def cmd_co(options, parser):
     root = os.path.expanduser(PKGROOT)  
   
638      for package, module, package_version, spec_version, downstream_files in sorted(join_streams()):      for package, module, package_version, spec_version, downstream_files in sorted(join_streams()):
639          print "%s => %s" % (module, package)          print "%s => %s" % (module, package)
640          subprocess.call(['mgarepo', 'co', package], cwd=root)          try:
641                Downstream.co(package)
642            except subprocess.CalledProcessError:
643                pass
644    
645  def join_streams(show_version=False, only_diff_version=False):  def join_streams(show_version=False, only_diff_version=False):
646      root = os.path.expanduser(PKGROOT)      root = os.path.expanduser(Downstream.PKGROOT)
647    
648      upstream = Upstream().names      upstream = Upstream().names
649      downstream, downstream_files = get_downstream_names()      downstream = Downstream()
650    
651      matches = upstream & set(downstream.keys())      matches = upstream & set(downstream.tarballs.keys())
652      for module in matches:      for module in matches:
653          for package in downstream[module].keys():          for package in downstream.tarballs[module].keys():
654              package_version = downstream[module][package]              package_version = downstream.tarballs[module][package]
655              spec_version = None              spec_version = None
656              if show_version or only_diff_version:              if show_version or only_diff_version:
657                  cwd = os.path.join(root, package)                  cwd = os.path.join(root, package)
# Line 616  def join_streams(show_version=False, onl Line 663  def join_streams(show_version=False, onl
663              if only_diff_version and package_version == spec_version:              if only_diff_version and package_version == spec_version:
664                  continue                  continue
665    
666              yield (package, module, package_version, spec_version, downstream_files[package])              yield (package, module, package_version, spec_version, downstream.files[package])
667    
668  def cmd_ls(options, parser):  def cmd_ls(options, parser):
669      for package, module, package_version, spec_version, downstream_files in sorted(join_streams(show_version=options.show_version, only_diff_version=options.diff)):      streams = join_streams(show_version=options.show_version, only_diff_version=options.diff)
670        if options.sort:
671            SORT=dict(zip(options.sort.read().splitlines(), itertools.count()))
672    
673            streams = sorted(streams, key=lambda a: (SORT.get(a[1], 9999), a[0]))
674        else:
675            streams = sorted(streams)
676    
677        for package, module, package_version, spec_version, downstream_files in streams:
678          sys.stdout.write(package)          sys.stdout.write(package)
679          if options.upstream: sys.stdout.write("\t%s" % module)          if options.upstream: sys.stdout.write("\t%s" % module)
680          if options.show_version: sys.stdout.write("\t%s\t%s" % (spec_version, package_version))          if options.show_version: sys.stdout.write("\t%s\t%s" % (spec_version, package_version))
681          print          print
682    
683    def cmd_check_latest(options, parser):
684        streams = join_streams(show_version=True)
685    
686        for package, module, package_version, spec_version, downstream_files in streams:
687            sys.stdout.write(package)
688            sys.stdout.write("\t%s\t%s" % (spec_version, package_version))
689    
690            safe_max_version = get_safe_max_version(spec_version)
691    
692            versions = Upstream.versions(module)
693            if versions:
694                latest_version = get_latest_version(versions)
695                safe_version = get_latest_version(versions, safe_max_version)
696    
697                if version_cmp(latest_version, spec_version) < 0: latest_version = 'N/A'
698                if version_cmp(safe_version, spec_version) < 0: safe_version = 'N/A'
699    
700                sys.stdout.write("\t%s" % latest_version)
701                sys.stdout.write("\t%s" % safe_version)
702            print
703    
704  def cmd_patches(options, parser):  def cmd_patches(options, parser):
705      root = os.path.expanduser(PKGROOT)      root = os.path.expanduser(Downstream.PKGROOT)
706    
707      for package, module, package_version, spec_version, downstream_files in sorted(join_streams()):      for package, module, package_version, spec_version, downstream_files in sorted(join_streams()):
708          for filename in downstream_files:          for filename in downstream_files:
# Line 649  def cmd_package_new_version(options, par Line 725  def cmd_package_new_version(options, par
725      # Determine the package name      # Determine the package name
726      if options.upstream:      if options.upstream:
727          try:          try:
728              package = get_downstream_from_upstream(options.package, options.version)[0]              package = Downstream().get_downstream_from_upstream(options.package, options.version)[0]
729          except ValueError, e:          except ValueError, e:
730              print >>sys.stderr, "ERROR: %s" % e              print >>sys.stderr, "ERROR: %s" % e
731              sys.exit(1)              sys.exit(1)
# Line 657  def cmd_package_new_version(options, par Line 733  def cmd_package_new_version(options, par
733          package = options.package          package = options.package
734    
735      # Directories packages are located in      # Directories packages are located in
736      root = os.path.expanduser(PKGROOT)      root = os.path.expanduser(Downstream.PKGROOT)
737      cwd = os.path.join(root, package)      cwd = os.path.join(root, package)
738    
739      # Checkout package to ensure the checkout reflects the latest changes      # Checkout package to ensure the checkout reflects the latest changes
740      try:      try:
741          subprocess.check_call(['mgarepo', 'co', package], cwd=root)          Downstream.co(package, cwd=root)
742      except subprocess.CalledProcessError:      except subprocess.CalledProcessError:
743          sys.exit(1)          sys.exit(1)
744    
# Line 687  def cmd_package_new_version(options, par Line 763  def cmd_package_new_version(options, par
763                  subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd)                  subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd)
764                  sys.exit(1)                  sys.exit(1)
765    
766      # We can even checkin and submit :-)      try:
767      if options.submit:          # If we made it this far, checkin the changes
768          try:          subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd)
769              # checkin changes  
770              subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd)          # Submit is optional
771              # and submit          if options.submit:
772              # XXX HACK NOT TO AUTO SUBMIT ATM              cmd = ['mgarepo', 'submit']
773              if options.hexdigest is None:              if Downstream.DISTRO:
774                  subprocess.check_call(['mgarepo', 'submit'], cwd=cwd)                  cmd.extend(('--define', 'section=core/updates_testing', '-t', Downstream.DISTRO))
775          except subprocess.CalledProcessError:              subprocess.check_call(cmd, cwd=cwd)
776              sys.exit(1)      except subprocess.CalledProcessError:
777            sys.exit(1)
778    
779  def cmd_parse_ftp_release_list(options, parser):  def cmd_parse_ftp_release_list(options, parser):
780      def _send_reply_mail(contents, orig_msg, to, packages=[], error=False):      def _send_reply_mail(contents, orig_msg, to, packages=[], error=False):
# Line 756  def cmd_parse_ftp_release_list(options, Line 833  def cmd_parse_ftp_release_list(options,
833          sys.exit(1)          sys.exit(1)
834    
835      try:      try:
836          packages = get_downstream_from_upstream(module, version)          packages = Downstream().get_downstream_from_upstream(module, version)
837      except ValueError, e:      except ValueError, e:
838          print >>stderr, "ERROR: %s" % e          print >>stderr, "ERROR: %s" % e
839          if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True)          if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True)
# Line 777  def cmd_parse_ftp_release_list(options, Line 854  def cmd_parse_ftp_release_list(options,
854    
855      error = False      error = False
856      for package in packages:      for package in packages:
857          cmd = ['mga-gnome', 'increase', '--submit', '--hash', hexdigest]          cmd = ['mga-gnome', 'increase', '--hash', hexdigest]
858            if options.submit:
859                cmd.append('--submit')
860          if options.force:          if options.force:
861              cmd.append('--force')              cmd.append('--force')
862          cmd.extend((package, version))          cmd.extend((package, version))
# Line 793  def main(): Line 872  def main():
872      parser.add_argument("-l", "--limit", type=argparse.FileType('r', 0),      parser.add_argument("-l", "--limit", type=argparse.FileType('r', 0),
873                          dest="limit_upstream", metavar="FILE",                          dest="limit_upstream", metavar="FILE",
874                          help="File containing upstream names")                          help="File containing upstream names")
875        parser.add_argument("-d", "--distro", action="store", dest="distro",
876                                           help="Distribution release")
877    
878      # SUBPARSERS      # SUBPARSERS
879      subparsers = parser.add_subparsers(title='subcommands')      subparsers = parser.add_subparsers(title='subcommands')
# Line 809  def main(): Line 890  def main():
890                                         help="Show version numbers")                                         help="Show version numbers")
891      subparser.add_argument(      "--diff", action="store_true", dest="diff",      subparser.add_argument(      "--diff", action="store_true", dest="diff",
892                                         help="Only show packages with different version")                                         help="Only show packages with different version")
893        subparser.add_argument(      "--sort", type=argparse.FileType('r', 0),
894                            dest="sort", metavar="FILE",
895                            help="Sort packages according to order in given FILE")
896    
897      subparser.set_defaults(      subparser.set_defaults(
898          func=cmd_ls, upstream=False, show_version=False, diff=False          func=cmd_ls, upstream=False, show_version=False, diff=False
899      )      )
900    
901        subparser = subparsers.add_parser('check-latest', help='check for latest version of packages')
902        subparser.set_defaults(
903            func=cmd_check_latest
904        )
905    
906      subparser = subparsers.add_parser('patches', help='list all GNOME patches')      subparser = subparsers.add_parser('patches', help='list all GNOME patches')
907      subparser.add_argument("-p", "--path", action="store_true", dest="path",      subparser.add_argument("-p", "--path", action="store_true", dest="path",
908                                         help="Show full path to patch")                                         help="Show full path to patch")
# Line 840  def main(): Line 930  def main():
930      subparser.add_argument("--hash", dest="hexdigest",      subparser.add_argument("--hash", dest="hexdigest",
931                                         help="Hexdigest of the hash")                                         help="Hexdigest of the hash")
932      subparser.set_defaults(      subparser.set_defaults(
933          func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256",          func=cmd_package_new_version, submit=True, upstream=False, hexdigest=None, algo="sha256",
934          force=False          force=False
935      )      )
936    
# Line 848  def main(): Line 938  def main():
938      subparser.add_argument("-m", "--mail", help="Email address to send the progress to")      subparser.add_argument("-m", "--mail", help="Email address to send the progress to")
939      subparser.add_argument("-w", "--wait", action="store_true",      subparser.add_argument("-w", "--wait", action="store_true",
940                                   help="Wait before trying to retrieve the new version")                                   help="Wait before trying to retrieve the new version")
941        subparser.add_argument("-s", "--submit", action="store_true", dest="submit",
942                                           help="Commit changes and submit")
943      subparser.add_argument("-f", "--force", action="store_true",      subparser.add_argument("-f", "--force", action="store_true",
944                                   help="Force submission")                                   help="Force submission")
945      subparser.set_defaults(      subparser.set_defaults(
# Line 862  def main(): Line 954  def main():
954      if options.limit_upstream:      if options.limit_upstream:
955          Upstream.limit = set(options.limit_upstream.read().strip("\n").splitlines())          Upstream.limit = set(options.limit_upstream.read().strip("\n").splitlines())
956    
957        if options.distro:
958            Downstream.PKGROOT = os.path.join('~/pkgs', options.distro)
959            Downstream.MEDIA = "Core Release %s Source" % options.distro
960            Downstream.DISTRO = options.distro
961    
962      try:      try:
963          options.func(options, parser)          options.func(options, parser)
964      except KeyboardInterrupt:      except KeyboardInterrupt:

Legend:
Removed from v.3649  
changed lines
  Added in v.5289

  ViewVC Help
Powered by ViewVC 1.1.30