/[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 3180 by ovitters, Fri Mar 2 21:25:11 2012 UTC revision 3647 by ovitters, Wed Mar 21 16:14:34 2012 UTC
# Line 49  import datetime Line 49  import datetime
49  MEDIA="Core Release Source"  MEDIA="Core Release Source"
50  URL="http://download.gnome.org/sources/"  URL="http://download.gnome.org/sources/"
51  PKGROOT='~/pkgs'  PKGROOT='~/pkgs'
52  SLEEP_INITIAL=300  SLEEP_INITIAL=180
53    SLEEP_REPEAT=30
54    SLEEP_TIMES=20
55    
56  re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*')  re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*')
57  re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')  re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')
# Line 257  class SpecFile(object): Line 259  class SpecFile(object):
259                          else spec.sources()                          else spec.sources()
260          return dict((os.path.basename(name), name) for name, no, flags in srclist)          return dict((os.path.basename(name), name) for name, no, flags in srclist)
261    
262      def update(self, version):      def update(self, version, force=False):
263          """Update specfile (increase version)"""          """Update specfile (increase version)"""
264          cur_version = self.version          cur_version = self.version
265    
# Line 269  class SpecFile(object): Line 271  class SpecFile(object):
271    
272          if judgement < 5:          if judgement < 5:
273              print "WARNING: %s!" % (msg)              print "WARNING: %s!" % (msg)
274              return False              if not force: return False
275    
276          # XXX - os.path.join is hackish          # XXX - os.path.join is hackish
277          if subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')]) != '':          svn_diff_output = subprocess.check_output(["svn", "diff", os.path.join(self.path, '..')])
278            if svn_diff_output != '':
279                print svn_diff_output
280              print >>sys.stderr, "ERROR: Package has uncommitted changes!"              print >>sys.stderr, "ERROR: Package has uncommitted changes!"
281              return False              if not force:
282                    return False
283    
284                # Forcing package submission: revert changes
285                try:
286                    print >>sys.stderr, "WARNING: Force used; reverting svn changes"
287                    subprocess.check_call(["svn", "revert", "-R", os.path.join(self.path, '..')])
288                except subprocess.CalledProcessError:
289                    return False
290    
291          with open(self.path, "rw") as f:          with open(self.path, "rw") as f:
292              data = f.read()              data = f.read()
# Line 302  class SpecFile(object): Line 314  class SpecFile(object):
314              print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version              print "ERROR: Increased version to %s, but RPM doesn't agree!?!" % version
315              return False              return False
316    
317    
318            # Try to download the new tarball various times and wait between attempts
319            tries = 0
320            while tries < SLEEP_TIMES:
321                tries += 1
322                if tries > 1: time.sleep(SLEEP_REPEAT)
323                try:
324                    # Download new tarball
325                    subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd)
326                    # success, so exit loop
327                    break
328                except subprocess.CalledProcessError, e:
329                    # mgarepo sync returns 1 if the tarball cannot be downloaded
330                    if e.returncode != 1:
331                        return False
332            else:
333                return False
334    
335    
336          try:          try:
             # Download new tarball  
             subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd)  
337              # Check patches still apply              # Check patches still apply
338              subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd)              subprocess.check_call(['bm', '-p', '--nodeps'], cwd=self.cwd)
339          except subprocess.CalledProcessError:          except subprocess.CalledProcessError:
340                logfile = os.path.join(os.path.dirname(self.path), 'log.%s' % os.path.splitext(os.path.basename(self.path))[0])
341                if os.path.exists(logfile):
342                    subprocess.call(['tail', '-n', '15', logfile])
343              return False              return False
344    
345          return True          return True
# Line 472  def get_upstream_names(): Line 504  def get_upstream_names():
504  def get_downstream_names():  def get_downstream_names():
505      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]*)$')
506    
507      contents = subprocess.check_output(['urpmf', '--files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines()      contents = subprocess.check_output(['urpmf', '--qf', '%name|%version|%files', '.', "--media", MEDIA], close_fds=True).strip("\n").splitlines()
508    
509      FILES = {}      FILES = {}
510      TARBALLS = {}      TARBALLS = {}
511    
512      for line in  contents:      for line in  contents:
513          try:          try:
514              srpm, filename = line.split(":")              srpm, version, filename = line.split("|")
515          except ValueError:          except ValueError:
516              print >>sys.stderr, line              print >>sys.stderr, line
517              continue              continue
# Line 491  def get_downstream_names(): Line 523  def get_downstream_names():
523                  module = fileinfo['module']                  module = fileinfo['module']
524    
525                  if module not in TARBALLS:                  if module not in TARBALLS:
526                      TARBALLS[module] = set()                      TARBALLS[module] = {}
527                  TARBALLS[module].add(srpm)                  TARBALLS[module][srpm] = version
528    
529          if srpm not in FILES:          if srpm not in FILES:
530              FILES[srpm] = set()              FILES[srpm] = set()
# Line 507  def get_downstream_from_upstream(upstrea Line 539  def get_downstream_from_upstream(upstrea
539      if upstream not in downstream:      if upstream not in downstream:
540          raise ValueError("No packages for upstream name: %s" % upstream)          raise ValueError("No packages for upstream name: %s" % upstream)
541    
542      if len(downstream[upstream]) != 1:      if len(downstream[upstream]) == 1:
543          # XXX - Make it more intelligent          return downstream[upstream].keys()
544          raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream])))  
545        # Directories packages are located in
546        root = os.path.expanduser(PKGROOT)
547    
548        packages = {}
549        for package in downstream[upstream].keys():
550            cwd = os.path.join(root, package)
551    
552            # Checkout package to ensure the checkout reflects the latest changes
553            try:
554                subprocess.check_call(['mgarepo', 'co', package], cwd=root)
555            except subprocess.CalledProcessError:
556                raise ValueError("Multiple packages found and cannot checkout %s" % package)
557    
558            # Determine version from spec file
559            try:
560                packages[package] = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version
561            except subprocess.CalledProcessError:
562                raise ValueError("Multiple packages found and cannot determine version of %s" % package)
563    
564        # Return all packages reflecting the current version
565        matches = [package for package in packages if packages[package] == version]
566        if len(matches):
567            return matches
568    
569        # Return all packages reflecting the version before the current version
570        latest_version = get_latest_version(packages.values(), max_version=version)
571        matches = [package for package in packages if packages[package] == latest_version]
572        if len(matches):
573            return matches
574    
575      return list(downstream[upstream])      # Give up
576        raise ValueError("Multiple packages found and cannot determine package for version %s" % version)
577    
578  def write_file(path, data):  def write_file(path, data):
579      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 520  def write_file(path, data): Line 582  def write_file(path, data):
582          os.rename(fdst.name, path)          os.rename(fdst.name, path)
583    
584  def cmd_co(options, parser):  def cmd_co(options, parser):
585      upstream = get_upstream_names()      root = os.path.expanduser(PKGROOT)
     downstream, downstream_files = get_downstream_names()  
586    
587      cwd = os.path.expanduser(PKGROOT)      for package, module, package_version, spec_version, downstream_files in sorted(join_streams()):
588            print "%s => %s" % (module, package)
589            subprocess.call(['mgarepo', 'co', package], cwd=root)
590    
591      matches = upstream & set(downstream.keys())  def join_streams(show_version=False, only_diff_version=False):
592      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)  
593    
 def join_streams():  
594      upstream = get_upstream_names()      upstream = get_upstream_names()
595      downstream, downstream_files = get_downstream_names()      downstream, downstream_files = get_downstream_names()
596    
597      matches = upstream & set(downstream.keys())      matches = upstream & set(downstream.keys())
598      for module in matches:      for module in matches:
599          for package in downstream[module]:          for package in downstream[module].keys():
600              yield (package, module)              package_version = downstream[module][package]
601                spec_version = None
602                if show_version or only_diff_version:
603                    cwd = os.path.join(root, package)
604                    try:
605                        spec_version = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package)).version
606                    except subprocess.CalledProcessError:
607                        spec_version = 'N/A'
608    
609  def cmd_ls(options, parser):              if only_diff_version and package_version == spec_version:
610      for package, module in sorted(join_streams()):                  continue
         print "\t".join((package, module)) if options.upstream else package  
611    
612  def cmd_patches(options, parser):              yield (package, module, package_version, spec_version, downstream_files[package])
     upstream = get_upstream_names()  
     downstream, downstream_files = get_downstream_names()  
613    
614      path = os.path.expanduser(PKGROOT)  def cmd_ls(options, parser):
615        for package, module, package_version, spec_version, downstream_files in sorted(join_streams(show_version=options.show_version, only_diff_version=options.diff)):
616            print package,"\t",
617            if options.upstream: print module, "\t",
618            if options.show_version: print spec_version, "\t", package_version, "\t",
619            print
620    
621      import pprint  def cmd_patches(options, parser):
622        root = os.path.expanduser(PKGROOT)
623    
624      matches = upstream & set(downstream.keys())      for package, module, package_version, spec_version, downstream_files in sorted(join_streams()):
625      for module in sorted(matches):          for filename in downstream_files:
626          for srpm in downstream[module]:              if '.patch' in filename or '.diff' in filename:
627              for filename in downstream_files[srpm]:  
628                  if '.patch' in filename or '.diff' in filename:                  p = Patch(os.path.join(root, package, "SOURCES", filename), show_path=options.path)
629                    valid = ""
630                      p = Patch(os.path.join(path, srpm, "SOURCES", filename), show_path=options.path)                  forwarded = ""
631                      valid = ""                  if p.dep3['headers']:
632                      forwarded = ""                      forwarded = p.dep3['headers'].get('Forwarded', "no")
633                      if p.dep3['headers']:                      if p.dep3['valid']:
634                          forwarded = p.dep3['headers'].get('Forwarded', "no")                          valid="VALID"
635                          if p.dep3['valid']:                  print "\t".join((module, package, str(p), forwarded, valid))
                             valid="VALID"  
                     print "\t".join((module, srpm, str(p), forwarded, valid))  
636    
637  def cmd_dep3(options, parser):  def cmd_dep3(options, parser):
638      p = Patch(options.patch)      p = Patch(options.patch)
# Line 595  def cmd_package_new_version(options, par Line 662  def cmd_package_new_version(options, par
662      # SpecFile class handles the actual version+release change      # SpecFile class handles the actual version+release change
663      s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package))      s = SpecFile(os.path.join(cwd, "SPECS", "%s.spec" % package))
664      print "%s => %s" % (s.version, options.version)      print "%s => %s" % (s.version, options.version)
665      if not s.update(options.version):      if not s.update(options.version, force=options.force):
666          sys.exit(1)          sys.exit(1)
667    
668      # Check hash, if given      # Check hash, if given
# Line 606  def cmd_package_new_version(options, par Line 673  def cmd_package_new_version(options, par
673              sys.stderr(1)              sys.stderr(1)
674    
675          for filename in sources:          for filename in sources:
676              if not is_valid_hash(os.path.join(cwd, "SOURCES", filename), options.algo, options.hexdigest):              path = os.path.join(cwd, "SOURCES", filename)
677                if not is_valid_hash(path, options.algo, options.hexdigest):
678                  print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path                  print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path
679                  print >>sys.stderr, "ERROR: Reverting changes!"                  print >>sys.stderr, "ERROR: Reverting changes!"
680                  subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd)                  subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd)
# Line 618  def cmd_package_new_version(options, par Line 686  def cmd_package_new_version(options, par
686              # checkin changes              # checkin changes
687              subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd)              subprocess.check_call(['mgarepo', 'ci', '-m', 'new version %s' % options.version], cwd=cwd)
688              # and submit              # and submit
689              subprocess.check_call(['mgarepo', 'submit'], cwd=cwd)              # XXX HACK NOT TO AUTO SUBMIT ATM
690                if options.hexdigest is None:
691                    subprocess.check_call(['mgarepo', 'submit'], cwd=cwd)
692          except subprocess.CalledProcessError:          except subprocess.CalledProcessError:
693              sys.exit(1)              sys.exit(1)
694    
695  def cmd_parse_ftp_release_list(options, parser):  def cmd_parse_ftp_release_list(options, parser):
696      # XXX - not working yet      def _send_reply_mail(contents, orig_msg, to, packages=[], error=False):
     def _send_reply_mail(contents, orig_msg, to, error=False):  
697          """Send an reply email"""          """Send an reply email"""
698          contents.seek(0)          contents.seek(0)
699          msg = MIMEText(contents.read(), _charset='utf-8')          msg = MIMEText(contents.read(), _charset='utf-8')
700          msg['Subject'] = "Re: %s%s" % (orig_msg['Subject'], " (ERROR)" if error else "")  
701            if error:
702                # XXX - ugly
703                contents.seek(0)
704                lastline = contents.read().rstrip().splitlines()[-1]
705                # Remove things like "ERROR: " and so on from the last line
706                lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline)
707                # Remove things like "   - " (youri output from mgarepo submit)
708                lastline = re.sub(r'^\s+-\s+', '', lastline)
709                subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)"
710            else:
711                subjecterror = ""
712    
713            if packages:
714                subject = "%s %s%s" % (", ".join(packages), orig_msg['X-Module-Version'], subjecterror)
715            else:
716                subject = "Re: %s%s" % (orig_msg['Subject'], subjecterror)
717    
718            msg['Subject'] = subject
719          msg['To'] = to          msg['To'] = to
720          msg["In-Reply-To"] = orig_msg["Message-ID"]          msg["In-Reply-To"] = orig_msg["Message-ID"]
721          msg["References"] = orig_msg["Message-ID"]          msg["References"] = orig_msg["Message-ID"]
# Line 652  def cmd_parse_ftp_release_list(options, Line 739  def cmd_parse_ftp_release_list(options,
739          stdout = sys.stdout          stdout = sys.stdout
740          stderr = sys.stderr          stderr = sys.stderr
741    
     version_freeze = datetime.datetime(2012,3,7,23,59,0)  
     now = datetime.datetime.utcnow()  
     if now > version_freeze:  
         print >>stderr, "ERROR: Past version freeze"  
         if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True)  
         sys.exit(1)  
   
742      try:      try:
743          module = msg['X-Module-Name']          module = msg['X-Module-Name']
744          version = msg['X-Module-Version']          version = msg['X-Module-Version']
# Line 679  def cmd_parse_ftp_release_list(options, Line 759  def cmd_parse_ftp_release_list(options,
759          # maildrop aborts and will try to deliver after 5min          # maildrop aborts and will try to deliver after 5min
760          # fork to avoid this          # fork to avoid this
761          if os.fork() != 0: sys.exit(0)          if os.fork() != 0: sys.exit(0)
762          time.sleep(SLEEP_INITIAL)          # wait SLEEP_INITIAL after the message was sent
763            secs = SLEEP_INITIAL
764            t = email.utils.parsedate_tz(msg['Date'])
765            if t is not None:
766                msg_time = email.utils.mktime_tz(t)
767                secs = SLEEP_INITIAL - (time.time() - msg_time)
768    
769            if secs > 0: time.sleep(secs)
770    
771      error = False      error = False
772      for package in packages:      for package in packages:
773          if subprocess.call(['mga-gnome', 'increase', '--submit', '--hash', hexdigest, package, version], stdout=stdout, stderr=stderr):          cmd = ['mga-gnome', 'increase', '--submit', '--hash', hexdigest]
774            if options.force:
775                cmd.append('--force')
776            cmd.extend((package, version))
777            if subprocess.call(cmd, stdout=stdout, stderr=stderr):
778              error = True              error = True
779    
780      if options.mail: _send_reply_mail(stdout, msg, options.mail, error=error)      if options.mail: _send_reply_mail(stdout, msg, options.mail, packages=packages, error=error)
781    
782  def main():  def main():
783      description = """Mageia GNOME commands."""      description = """Mageia GNOME commands."""
# Line 704  def main(): Line 795  def main():
795      subparser = subparsers.add_parser('packages', help='list all GNOME packages')      subparser = subparsers.add_parser('packages', help='list all GNOME packages')
796      subparser.add_argument("-m", "--m", action="store_true", dest="upstream",      subparser.add_argument("-m", "--m", action="store_true", dest="upstream",
797                                         help="Show upstream module")                                         help="Show upstream module")
798        subparser.add_argument(      "--version", action="store_true", dest="show_version",
799                                           help="Show version numbers")
800        subparser.add_argument(      "--diff", action="store_true", dest="diff",
801                                           help="Only show packages with different version")
802      subparser.set_defaults(      subparser.set_defaults(
803          func=cmd_ls, upstream=False          func=cmd_ls, upstream=False, show_version=False, diff=False
804      )      )
805    
806      subparser = subparsers.add_parser('patches', help='list all GNOME patches')      subparser = subparsers.add_parser('patches', help='list all GNOME patches')
# Line 724  def main(): Line 819  def main():
819      subparser = subparsers.add_parser('increase', help='Increase version number')      subparser = subparsers.add_parser('increase', help='Increase version number')
820      subparser.add_argument("package", help="Package name")      subparser.add_argument("package", help="Package name")
821      subparser.add_argument("version", help="Version number")      subparser.add_argument("version", help="Version number")
822        subparser.add_argument("-f", "--force", action="store_true", dest="force",
823                                           help="Override warnings, just do it")
824      subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream",      subparser.add_argument("-u", "--upstream", action="store_true", dest="upstream",
825                                         help="Package name reflects the upstream name")                                         help="Package name reflects the upstream name")
826      subparser.add_argument("-s", "--submit", action="store_true", dest="submit",      subparser.add_argument("-s", "--submit", action="store_true", dest="submit",
# Line 733  def main(): Line 830  def main():
830      subparser.add_argument("--hash", dest="hexdigest",      subparser.add_argument("--hash", dest="hexdigest",
831                                         help="Hexdigest of the hash")                                         help="Hexdigest of the hash")
832      subparser.set_defaults(      subparser.set_defaults(
833          func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256"          func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256",
834            force=False
835      )      )
836    
837      subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email')      subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email')
838      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")
839      subparser.add_argument("-w", "--wait", action="store_true",      subparser.add_argument("-w", "--wait", action="store_true",
840                                   help="Wait before trying to retrieve the new version")                                   help="Wait before trying to retrieve the new version")
841        subparser.add_argument("-f", "--force", action="store_true",
842                                     help="Force submission")
843      subparser.set_defaults(      subparser.set_defaults(
844          func=cmd_parse_ftp_release_list          func=cmd_parse_ftp_release_list, force=False, wait=False
845      )      )
846    
847      if len(sys.argv) == 1:      if len(sys.argv) == 1:
# Line 764  def main(): Line 864  def main():
864          sys.exit(0)          sys.exit(0)
865    
866  if __name__ == "__main__":  if __name__ == "__main__":
867        os.environ['PYTHONUNBUFFERED'] = '1'
868      main()      main()

Legend:
Removed from v.3180  
changed lines
  Added in v.3647

  ViewVC Help
Powered by ViewVC 1.1.30