/[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 3115 by ovitters, Tue Feb 28 10:23:35 2012 UTC revision 3498 by ovitters, Thu Mar 15 13:08:18 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 36  import urlparse Line 36  import urlparse
36  # for checking hashes  # for checking hashes
37  import hashlib  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  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
53    
54  re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*')  re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*')
55  re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')  re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')
# Line 81  def judge_version_increase(version_old, Line 92  def judge_version_increase(version_old,
92          compare = version_cmp(version_new, version_old)          compare = version_cmp(version_new, version_old)
93    
94          if compare == 0:          if compare == 0:
95                # 1.0.0 -> 1.0.1
96              return (-2, "Already at version %s!" % (version_old))              return (-2, "Already at version %s!" % (version_old))
97    
98          if compare != 1:          if compare != 1:
99                # 1.0.1 -> 1.0.0
100              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))
101    
102          # 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 104  def judge_version_increase(version_old, Line 117  def judge_version_increase(version_old,
117          # Major+minor the same? Then go ahead and upgrade!          # Major+minor the same? Then go ahead and upgrade!
118          if majmins[0] == majmins[1]:          if majmins[0] == majmins[1]:
119              # Majmin of both versions are the same, looks good!              # Majmin of both versions are the same, looks good!
120                # 1.1.x -> 1.1.x or 1.0.x -> 1.0.x
121              return (10, None)              return (10, None)
122    
123          # More detailed analysis needed, so figure out the numbers          # More detailed analysis needed, so figure out the numbers
# Line 111  def judge_version_increase(version_old, Line 125  def judge_version_increase(version_old,
125    
126          # Check/ensure major version number is the same          # Check/ensure major version number is the same
127          if majmin_nrs[0][0] != majmin_nrs[1][0]:          if majmin_nrs[0][0] != majmin_nrs[1][0]:
128                # 1.0.x -> 2.0.x
129              return (1, "Major version number increase")              return (1, "Major version number increase")
130    
131          # Minor indicates stable/unstable          # Minor indicates stable/unstable
# Line 119  def judge_version_increase(version_old, Line 134  def judge_version_increase(version_old,
134          # Upgrading to unstable is weird          # Upgrading to unstable is weird
135          if not devstate[1]:          if not devstate[1]:
136              if devstate[0]:              if devstate[0]:
137                    # 1.2.x -> 1.3.x
138                  return (1, "Stable to unstable increase")                  return (1, "Stable to unstable increase")
139    
140                # 1.3.x -> 1.5.x
141              return (4, "Unstable to unstable version increase")              return (4, "Unstable to unstable version increase")
142    
143          # Unstable => stable is always ok          # Unstable => stable is always ok
144          if not devstate[0]:          if not devstate[0]:
145                # 1.1.x -> 1.2.x
146              return (5, "Unstable to stable")              return (5, "Unstable to stable")
147    
148          # Can only be increase of minors from one stable to the next          # Can only be increase of minors from one stable to the next
149            # 1.0.x -> 1.2.x
150          return (6, "Stable version increase")          return (6, "Stable version increase")
151    
152  def line_input (file):  def line_input (file):
# Line 453  def get_upstream_names(): Line 472  def get_upstream_names():
472  def get_downstream_names():  def get_downstream_names():
473      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]*)$')
474    
475      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()
476    
477      FILES = {}      FILES = {}
478      TARBALLS = {}      TARBALLS = {}
479    
480      for line in  contents:      for line in  contents:
481          try:          try:
482              srpm, filename = line.split(":")              srpm, version, filename = line.split("|")
483          except ValueError:          except ValueError:
484              print >>sys.stderr, line              print >>sys.stderr, line
485              continue              continue
# Line 472  def get_downstream_names(): Line 491  def get_downstream_names():
491                  module = fileinfo['module']                  module = fileinfo['module']
492    
493                  if module not in TARBALLS:                  if module not in TARBALLS:
494                      TARBALLS[module] = set()                      TARBALLS[module] = {}
495                  TARBALLS[module].add(srpm)                  TARBALLS[module][srpm] = version
496    
497          if srpm not in FILES:          if srpm not in FILES:
498              FILES[srpm] = set()              FILES[srpm] = set()
# Line 481  def get_downstream_names(): Line 500  def get_downstream_names():
500    
501      return TARBALLS, FILES      return TARBALLS, FILES
502    
503    def get_downstream_from_upstream(upstream, version):
504        # Determine the package name
505        downstream, downstream_files = get_downstream_names()
506    
507        if upstream not in downstream:
508            raise ValueError("No packages for upstream name: %s" % upstream)
509    
510        if len(downstream[upstream]) != 1:
511            # XXX - Make it more intelligent
512            raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream].keys())))
513    
514        return downstream[upstream].keys()
515    
516  def write_file(path, data):  def write_file(path, data):
517      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 496  def cmd_co(options, parser): Line 527  def cmd_co(options, parser):
527    
528      matches = upstream & set(downstream.keys())      matches = upstream & set(downstream.keys())
529      for module in matches:      for module in matches:
530          print module, "\t".join(downstream[module])          print module, "\t".join(downstream[module].keys())
531          for package in downstream[module]:          for package in downstream[module].keys():
532              subprocess.call(['mgarepo', 'co', package], cwd=cwd)              subprocess.call(['mgarepo', 'co', package], cwd=cwd)
533    
534  def join_streams():  def join_streams():
# Line 506  def join_streams(): Line 537  def join_streams():
537    
538      matches = upstream & set(downstream.keys())      matches = upstream & set(downstream.keys())
539      for module in matches:      for module in matches:
540          for package in downstream[module]:          for package in downstream[module].keys():
541              yield (package, module)              yield (package, module)
542    
543  def cmd_ls(options, parser):  def cmd_ls(options, parser):
# Line 523  def cmd_patches(options, parser): Line 554  def cmd_patches(options, parser):
554    
555      matches = upstream & set(downstream.keys())      matches = upstream & set(downstream.keys())
556      for module in sorted(matches):      for module in sorted(matches):
557          for srpm in downstream[module]:          for srpm in downstream[module].keys():
558              for filename in downstream_files[srpm]:              for filename in downstream_files[srpm]:
559                  if '.patch' in filename or '.diff' in filename:                  if '.patch' in filename or '.diff' in filename:
560    
# Line 543  def cmd_dep3(options, parser): Line 574  def cmd_dep3(options, parser):
574  def cmd_package_new_version(options, parser):  def cmd_package_new_version(options, parser):
575      # Determine the package name      # Determine the package name
576      if options.upstream:      if options.upstream:
577          downstream, downstream_files = get_downstream_names()          try:
578                package = get_downstream_from_upstream(options.package, options.version)[0]
579          if options.package not in downstream:          except ValueError, e:
580              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]))  
581              sys.exit(1)              sys.exit(1)
   
         package = list(downstream[options.package])[0]  
582      else:      else:
583          package = options.package          package = options.package
584    
# Line 598  def cmd_package_new_version(options, par Line 622  def cmd_package_new_version(options, par
622          except subprocess.CalledProcessError:          except subprocess.CalledProcessError:
623              sys.exit(1)              sys.exit(1)
624    
625    def cmd_parse_ftp_release_list(options, parser):
626        # XXX - not working yet
627        def _send_reply_mail(contents, orig_msg, to, error=False):
628            """Send an reply email"""
629            contents.seek(0)
630            msg = MIMEText(contents.read(), _charset='utf-8')
631            if error:
632                # XXX - ugly
633                contents.seek(0)
634                lastline = contents.read().splitlines()[-1]
635                # Remove things like "ERROR: " and so on from the last line
636                lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline)
637                subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)"
638            else:
639                subjecterror = ""
640            msg['Subject'] = "Re: %s%s" % (orig_msg['Subject'], subjecterror)
641            msg['To'] = to
642            msg["In-Reply-To"] = orig_msg["Message-ID"]
643            msg["References"] = orig_msg["Message-ID"]
644    
645            # Call sendmail program directly so it doesn't matter if the service is running
646            cmd = ['/usr/sbin/sendmail', '-oi', '--']
647            cmd.extend([to])
648            p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
649            p.stdin.write(msg.as_string())
650            p.stdin.flush()
651            p.stdin.close()
652            p.wait()
653    
654    
655        msg = email.email.message_from_file(sys.stdin)
656    
657        if options.mail:
658            stdout = tempfile.TemporaryFile()
659            stderr = stdout
660        else:
661            stdout = sys.stdout
662            stderr = sys.stderr
663    
664        try:
665            module = msg['X-Module-Name']
666            version = msg['X-Module-Version']
667            hexdigest = msg['X-Module-SHA256-tar.xz']
668        except KeyError, e:
669            print >>stderr, "ERROR: %s" % e
670            if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True)
671            sys.exit(1)
672    
673        try:
674            packages = get_downstream_from_upstream(module, version)
675        except ValueError, e:
676            print >>stderr, "ERROR: %s" % e
677            if options.mail: _send_reply_mail(stdout, msg, options.mail, error=True)
678            sys.exit(1)
679    
680        if options.wait:
681            # maildrop aborts and will try to deliver after 5min
682            # fork to avoid this
683            if os.fork() != 0: sys.exit(0)
684            time.sleep(SLEEP_INITIAL)
685    
686        error = False
687        for package in packages:
688            if subprocess.call(['mga-gnome', 'increase', '--submit', '--hash', hexdigest, package, version], stdout=stdout, stderr=stderr):
689                error = True
690    
691        if options.mail: _send_reply_mail(stdout, msg, options.mail, error=error)
692    
693  def main():  def main():
694      description = """Mageia GNOME commands."""      description = """Mageia GNOME commands."""
# Line 647  def main(): Line 738  def main():
738          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"
739      )      )
740    
741        subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email')
742        subparser.add_argument("-m", "--mail", help="Email address to send the progress to")
743        subparser.add_argument("-w", "--wait", action="store_true",
744                                     help="Wait before trying to retrieve the new version")
745        subparser.set_defaults(
746            func=cmd_parse_ftp_release_list
747        )
748    
749      if len(sys.argv) == 1:      if len(sys.argv) == 1:
750          parser.print_help()          parser.print_help()
751          sys.exit(2)          sys.exit(2)

Legend:
Removed from v.3115  
changed lines
  Added in v.3498

  ViewVC Help
Powered by ViewVC 1.1.30