/[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 3650 by ovitters, Wed Mar 21 19:34:00 2012 UTC revision 3653 by ovitters, Wed Mar 21 19:53:09 2012 UTC
# Line 46  import time Line 46  import time
46  # version freeze  # version freeze
47  import datetime  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'
# Line 541  class Downstream(object): Line 544  class Downstream(object):
544          self.tarballs = TARBALLS          self.tarballs = TARBALLS
545          self.files = FILES          self.files = FILES
546    
547  def get_downstream_from_upstream(upstream, version):      def get_downstream_from_upstream(self, upstream, version):
548      # Determine the package name          if upstream not in self.tarballs:
549      downstream = Downstream()              raise ValueError("No packages for upstream name: %s" % upstream)
 #    downstream, downstream_files = get_downstream_names()  
550    
551      if upstream not in downstream:          if len(self.tarballs[upstream]) == 1:
552          raise ValueError("No packages for upstream name: %s" % upstream)              return self.tarballs[upstream].keys()
553    
554      if len(downstream.tarballs[upstream]) == 1:          # Directories packages are located in
555          return downstream.tarballs[upstream].keys()          root = os.path.expanduser(PKGROOT)
556    
557      # Directories packages are located in          packages = {}
558      root = os.path.expanduser(PKGROOT)          for package in self.tarballs[upstream].keys():
559                cwd = os.path.join(root, package)
560    
561      packages = {}              # Checkout package to ensure the checkout reflects the latest changes
562      for package in downstream.tarballs[upstream].keys():              try:
563          cwd = os.path.join(root, package)                  subprocess.check_call(['mgarepo', 'co', package], cwd=root)
564                except subprocess.CalledProcessError:
565          # Checkout package to ensure the checkout reflects the latest changes                  raise ValueError("Multiple packages found and cannot checkout %s" % package)
         try:  
             subprocess.check_call(['mgarepo', 'co', package], cwd=root)  
         except subprocess.CalledProcessError:  
             raise ValueError("Multiple packages found and cannot checkout %s" % package)  
566    
567          # Determine version from spec file              # Determine version from spec file
568          try:              try:
569              packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version                  packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version
570          except subprocess.CalledProcessError:              except subprocess.CalledProcessError:
571              raise ValueError("Multiple packages found and cannot determine version of %s" % package)                  raise ValueError("Multiple packages found and cannot determine version of %s" % package)
572    
573      # Return all packages reflecting the current version          # Return all packages reflecting the current version
574      matches = [package for package in packages if packages[package] == version]          matches = [package for package in packages if packages[package] == version]
575      if len(matches):          if len(matches):
576          return matches              return matches
577    
578      # Return all packages reflecting the version before the current version          # Return all packages reflecting the version before the current version
579      latest_version = get_latest_version(packages.values(), max_version=version)          latest_version = get_latest_version(packages.values(), max_version=version)
580      matches = [package for package in packages if packages[package] == latest_version]          matches = [package for package in packages if packages[package] == latest_version]
581      if len(matches):          if len(matches):
582          return matches              return matches
583    
584      # Give up          # Give up
585      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)
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 622  def join_streams(show_version=False, onl Line 621  def join_streams(show_version=False, onl
621              yield (package, module, package_version, spec_version, downstream.files[package])              yield (package, module, package_version, spec_version, downstream.files[package])
622    
623  def cmd_ls(options, parser):  def cmd_ls(options, parser):
624      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)
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        for package, module, package_version, spec_version, downstream_files in streams:
633          sys.stdout.write(package)          sys.stdout.write(package)
634          if options.upstream: sys.stdout.write("\t%s" % module)          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))          if options.show_version: sys.stdout.write("\t%s\t%s" % (spec_version, package_version))
# Line 652  def cmd_package_new_version(options, par Line 659  def cmd_package_new_version(options, par
659      # Determine the package name      # Determine the package name
660      if options.upstream:      if options.upstream:
661          try:          try:
662              package = get_downstream_from_upstream(options.package, options.version)[0]              package = Downstream().get_downstream_from_upstream(options.package, options.version)[0]
663          except ValueError, e:          except ValueError, e:
664              print >>sys.stderr, "ERROR: %s" % e              print >>sys.stderr, "ERROR: %s" % e
665              sys.exit(1)              sys.exit(1)
# Line 759  def cmd_parse_ftp_release_list(options, Line 766  def cmd_parse_ftp_release_list(options,
766          sys.exit(1)          sys.exit(1)
767    
768      try:      try:
769          packages = get_downstream_from_upstream(module, version)          packages = Downstream().get_downstream_from_upstream(module, version)
770      except ValueError, e:      except ValueError, e:
771          print >>stderr, "ERROR: %s" % e          print >>stderr, "ERROR: %s" % e
772          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 812  def main(): Line 819  def main():
819                                         help="Show version numbers")                                         help="Show version numbers")
820      subparser.add_argument(      "--diff", action="store_true", dest="diff",      subparser.add_argument(      "--diff", action="store_true", dest="diff",
821                                         help="Only show packages with different version")                                         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, upstream=False, show_version=False, diff=False          func=cmd_ls, upstream=False, show_version=False, diff=False
828      )      )

Legend:
Removed from v.3650  
changed lines
  Added in v.3653

  ViewVC Help
Powered by ViewVC 1.1.30