/[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 3654 by ovitters, Wed Mar 21 21:49:09 2012 UTC revision 6244 by ovitters, Tue Oct 16 08:08:09 2012 UTC
# Line 49  import datetime Line 49  import datetime
49  # packages --sort  # packages --sort
50  import itertools  import itertools
51    
52  MEDIA="Core Release Source"  # check-latest
53  URL="http://download.gnome.org/sources/"  import requests
54  PKGROOT='~/pkgs'  
55  SLEEP_INITIAL=180  SLEEP_INITIAL=180
56  SLEEP_REPEAT=30  SLEEP_REPEAT=30
57  SLEEP_TIMES=20  SLEEP_TIMES=20
# Line 82  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 294  class SpecFile(object): Line 305  class SpecFile(object):
305          with open(self.path, "rw") as f:          with open(self.path, "rw") as f:
306              data = f.read()              data = f.read()
307    
308                if data.count("%subrel") != 0:
309                    print >>sys.stderr, "ERROR: %subrel found; don't know what to do!"
310                    return False
311    
312              if data.count("%mkrel") != 1:              if data.count("%mkrel") != 1:
313                  print >>sys.stderr, "ERROR: Multiple %mkrel found; don't know what to do!"                  print >>sys.stderr, "ERROR: Multiple %mkrel found; don't know what to do!"
314                  return False                  return False
# Line 331  class SpecFile(object): Line 346  class SpecFile(object):
346              except subprocess.CalledProcessError, e:              except subprocess.CalledProcessError, e:
347                  # mgarepo sync returns 1 if the tarball cannot be downloaded                  # mgarepo sync returns 1 if the tarball cannot be downloaded
348                  if e.returncode != 1:                  if e.returncode != 1:
349                        subprocess.check_call(["svn", "revert", "-R", os.path.join(self.path, '..')])
350                      return False                      return False
351          else:          else:
352                # failed to download tarball
353                subprocess.check_call(["svn", "revert", "-R", os.path.join(self.path, '..')])
354              return False              return False
355    
356    
# Line 490  class Patch(object): Line 508  class Patch(object):
508    
509  class Upstream(object):  class Upstream(object):
510    
511        URL="http://download.gnome.org/sources/"
512      limit = None      limit = None
513        _cache_versions = {}
514    
515      def __init__(self):      def __init__(self):
516          urlopen = urllib2.build_opener()          urlopen = urllib2.build_opener()
# Line 498  class Upstream(object): Line 518  class Upstream(object):
518          good_dir = re.compile('^[-A-Za-z0-9_+.]+/$')          good_dir = re.compile('^[-A-Za-z0-9_+.]+/$')
519    
520          # Get the files          # Get the files
521          usock = urlopen.open(URL)          usock = urlopen.open(self.URL)
522          parser = urllister()          parser = urllister()
523          parser.feed(usock.read())          parser.feed(usock.read())
524          usock.close()          usock.close()
# Line 511  class Upstream(object): Line 531  class Upstream(object):
531    
532          self.names = tarballs          self.names = tarballs
533    
534        @classmethod
535        def versions(cls, module):
536            # XXX - ugly
537            if module not in cls._cache_versions:
538                versions = None
539    
540                url = '%s%s/cache.json' % (cls.URL, module)
541                r = requests.get(url)
542                j = r.json
543                if j is not None and len(j) > 2 and module in j[2]:
544                    versions = j[2][module]
545    
546                cls._cache_versions[module] = versions
547    
548            return cls._cache_versions[module]
549    
550  class Downstream(object):  class Downstream(object):
551      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]*)$')
552    
553        MEDIA="Core Release Source"
554        PKGROOT='~/pkgs'
555        DISTRO=None
556    
557      def __init__(self):      def __init__(self):
558          contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines()          contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", self.MEDIA], close_fds=True).strip("\n").splitlines()
559    
560          FILES = {}          FILES = {}
561          TARBALLS = {}          TARBALLS = {}
# Line 535  class Downstream(object): Line 575  class Downstream(object):
575    
576                      if module not in TARBALLS:                      if module not in TARBALLS:
577                          TARBALLS[module] = {}                          TARBALLS[module] = {}
578                      TARBALLS[module][srpm] = version  
579                        if srpm in TARBALLS[module]:
580                            # srpm seen before, check if version is newer
581                            if version_cmp(TARBALLS[module][srpm], version) == 1:
582                                TARBALLS[module][srpm] = version
583                        else:
584                            TARBALLS[module][srpm] = version
585    
586              if srpm not in FILES:              if srpm not in FILES:
587                  FILES[srpm] = set()                  FILES[srpm] = set()
# Line 544  class Downstream(object): Line 590  class Downstream(object):
590          self.tarballs = TARBALLS          self.tarballs = TARBALLS
591          self.files = FILES          self.files = FILES
592    
593        @classmethod
594        def co(cls, package, cwd=None):
595            if cwd is None:
596                cwd = os.path.expanduser(cls.PKGROOT)
597    
598            cmd = ['mgarepo', 'co']
599            if cls.DISTRO:
600                cmd.extend(('-d', cls.DISTRO))
601            cmd.append(package)
602            return subprocess.check_call(cmd, cwd=cwd)
603    
604      def get_downstream_from_upstream(self, upstream, version):      def get_downstream_from_upstream(self, upstream, version):
605          if upstream not in self.tarballs:          if upstream not in self.tarballs:
606              raise ValueError("No packages for upstream name: %s" % upstream)              raise ValueError("No packages for upstream name: %s" % upstream)
# Line 552  class Downstream(object): Line 609  class Downstream(object):
609              return self.tarballs[upstream].keys()              return self.tarballs[upstream].keys()
610    
611          # Directories packages are located in          # Directories packages are located in
612          root = os.path.expanduser(PKGROOT)          root = os.path.expanduser(self.PKGROOT)
613    
614          packages = {}          packages = {}
615          for package in self.tarballs[upstream].keys():          for package in self.tarballs[upstream].keys():
# Line 560  class Downstream(object): Line 617  class Downstream(object):
617    
618              # Checkout package to ensure the checkout reflects the latest changes              # Checkout package to ensure the checkout reflects the latest changes
619              try:              try:
620                  subprocess.check_call(['mgarepo', 'co', package], cwd=root)                  self.co(package, cwd=root)
621              except subprocess.CalledProcessError:              except subprocess.CalledProcessError:
622                  raise ValueError("Multiple packages found and cannot checkout %s" % package)                  raise ValueError("Multiple packages found and cannot checkout %s" % package)
623    
# Line 591  def write_file(path, data): Line 648  def write_file(path, data):
648          os.rename(fdst.name, path)          os.rename(fdst.name, path)
649    
650  def cmd_co(options, parser):  def cmd_co(options, parser):
     root = os.path.expanduser(PKGROOT)  
   
651      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()):
652          print "%s => %s" % (module, package)          print "%s => %s" % (module, package)
653          subprocess.call(['mgarepo', 'co', package], cwd=root)          try:
654                Downstream.co(package)
655            except subprocess.CalledProcessError:
656                pass
657    
658  def join_streams(show_version=False, only_diff_version=False):  def join_streams(show_version=False, only_diff_version=False):
659      root = os.path.expanduser(PKGROOT)      root = os.path.expanduser(Downstream.PKGROOT)
660    
661      upstream = Upstream().names      upstream = Upstream().names
662      downstream = Downstream()      downstream = Downstream()
# Line 635  def cmd_ls(options, parser): Line 693  def cmd_ls(options, parser):
693          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))
694          print          print
695    
696    def cmd_check_latest(options, parser):
697        streams = join_streams(show_version=True)
698    
699        for package, module, package_version, spec_version, downstream_files in streams:
700            upgrade=set()
701            sys.stdout.write(package)
702            sys.stdout.write("\t%s\t%s" % (spec_version, package_version))
703    
704            safe_max_version = get_safe_max_version(spec_version)
705    
706            versions = Upstream.versions(module)
707            if versions:
708                latest_version = get_latest_version(versions)
709                safe_version = get_latest_version(versions, safe_max_version)
710    
711                cmp_latest = version_cmp(latest_version, spec_version)
712                if cmp_latest < 0:
713                    latest_version = 'N/A'
714                    upgrade.add('l')
715                elif cmp_latest > 0:
716                    upgrade.add('L')
717    
718                cmp_safe = version_cmp(safe_version, spec_version)
719                if cmp_safe < 0:
720                    safe_version = 'N/A'
721                    upgrade.add('s')
722                elif cmp_safe > 0:
723                    upgrade.add('S')
724    
725                sys.stdout.write("\t%s" % latest_version)
726                sys.stdout.write("\t%s" % safe_version)
727                sys.stdout.write("\t%s" % "".join(sorted(upgrade)))
728    
729            print
730    
731  def cmd_patches(options, parser):  def cmd_patches(options, parser):
732      root = os.path.expanduser(PKGROOT)      root = os.path.expanduser(Downstream.PKGROOT)
733    
734      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()):
735          for filename in downstream_files:          for filename in downstream_files:
# Line 667  def cmd_package_new_version(options, par Line 760  def cmd_package_new_version(options, par
760          package = options.package          package = options.package
761    
762      # Directories packages are located in      # Directories packages are located in
763      root = os.path.expanduser(PKGROOT)      root = os.path.expanduser(Downstream.PKGROOT)
764      cwd = os.path.join(root, package)      cwd = os.path.join(root, package)
765    
766      # Checkout package to ensure the checkout reflects the latest changes      # Checkout package to ensure the checkout reflects the latest changes
767      try:      try:
768          subprocess.check_call(['mgarepo', 'co', package], cwd=root)          Downstream.co(package, cwd=root)
769      except subprocess.CalledProcessError:      except subprocess.CalledProcessError:
770          sys.exit(1)          sys.exit(1)
771    
# Line 689  def cmd_package_new_version(options, par Line 782  def cmd_package_new_version(options, par
782              print >>sys.stderr, "ERROR: Cannot determine source file (for hash check)!"              print >>sys.stderr, "ERROR: Cannot determine source file (for hash check)!"
783              sys.stderr(1)              sys.stderr(1)
784    
785            # If there are multiple sources, try to see if there is a preferred name
786            # --> needed for metacity hash check (multiple tarball sources)
787            if len(sources) > 1:
788                preferred_name = '%s-%s.tar.xz' % (package, options.version)
789                if preferred_name in sources:
790                    sources = [preferred_name]
791    
792          for filename in sources:          for filename in sources:
793              path = os.path.join(cwd, "SOURCES", filename)              path = os.path.join(cwd, "SOURCES", filename)
794              if not is_valid_hash(path, options.algo, options.hexdigest):              if not is_valid_hash(path, options.algo, options.hexdigest):
# Line 703  def cmd_package_new_version(options, par Line 803  def cmd_package_new_version(options, par
803    
804          # Submit is optional          # Submit is optional
805          if options.submit:          if options.submit:
806              subprocess.check_call(['mgarepo', 'submit'], cwd=cwd)              cmd = ['mgarepo', 'submit']
807                if Downstream.DISTRO:
808                    cmd.extend(('--define', 'section=core/updates_testing', '-t', Downstream.DISTRO))
809                subprocess.check_call(cmd, cwd=cwd)
810      except subprocess.CalledProcessError:      except subprocess.CalledProcessError:
811          sys.exit(1)          sys.exit(1)
812    
# Line 803  def main(): Line 906  def main():
906      parser.add_argument("-l", "--limit", type=argparse.FileType('r', 0),      parser.add_argument("-l", "--limit", type=argparse.FileType('r', 0),
907                          dest="limit_upstream", metavar="FILE",                          dest="limit_upstream", metavar="FILE",
908                          help="File containing upstream names")                          help="File containing upstream names")
909        parser.add_argument("-d", "--distro", action="store", dest="distro",
910                                           help="Distribution release")
911    
912      # SUBPARSERS      # SUBPARSERS
913      subparsers = parser.add_subparsers(title='subcommands')      subparsers = parser.add_subparsers(title='subcommands')
# Line 827  def main(): Line 932  def main():
932          func=cmd_ls, upstream=False, show_version=False, diff=False          func=cmd_ls, upstream=False, show_version=False, diff=False
933      )      )
934    
935        subparser = subparsers.add_parser('check-latest', help='check for latest version of packages')
936        subparser.set_defaults(
937            func=cmd_check_latest
938        )
939    
940      subparser = subparsers.add_parser('patches', help='list all GNOME patches')      subparser = subparsers.add_parser('patches', help='list all GNOME patches')
941      subparser.add_argument("-p", "--path", action="store_true", dest="path",      subparser.add_argument("-p", "--path", action="store_true", dest="path",
942                                         help="Show full path to patch")                                         help="Show full path to patch")
# Line 849  def main(): Line 959  def main():
959                                         help="Package name reflects the upstream name")                                         help="Package name reflects the upstream name")
960      subparser.add_argument("-s", "--submit", action="store_true", dest="submit",      subparser.add_argument("-s", "--submit", action="store_true", dest="submit",
961                                         help="Commit changes and submit")                                         help="Commit changes and submit")
962        subparser.add_argument(      "--no-submit", action="store_false", dest="submit",
963                                           help="Do not commit changes and submit")
964      subparser.add_argument("-a", "--algorithm", choices=hashlib.algorithms, dest="algo",      subparser.add_argument("-a", "--algorithm", choices=hashlib.algorithms, dest="algo",
965                                         help="Hash algorithm")                                         help="Hash algorithm")
966      subparser.add_argument("--hash", dest="hexdigest",      subparser.add_argument("--hash", dest="hexdigest",
967                                         help="Hexdigest of the hash")                                         help="Hexdigest of the hash")
968      subparser.set_defaults(      subparser.set_defaults(
969          func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256",          func=cmd_package_new_version, submit=argparse.SUPPRESS, upstream=False, hexdigest=None, algo="sha256",
970          force=False          force=False
971      )      )
972    
# Line 878  def main(): Line 990  def main():
990      if options.limit_upstream:      if options.limit_upstream:
991          Upstream.limit = set(options.limit_upstream.read().strip("\n").splitlines())          Upstream.limit = set(options.limit_upstream.read().strip("\n").splitlines())
992    
993        if not hasattr(options, 'submit'):
994            options.submit = not options.distro
995    
996        if options.distro:
997            Downstream.PKGROOT = os.path.join('~/pkgs', options.distro)
998            Downstream.MEDIA = "Core Release {0} Source,Core {0} Updates Source,Core {0} Updates Testing Source".format(options.distro)
999            Downstream.DISTRO = options.distro
1000    
1001      try:      try:
1002          options.func(options, parser)          options.func(options, parser)
1003      except KeyboardInterrupt:      except KeyboardInterrupt:

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

  ViewVC Help
Powered by ViewVC 1.1.30