/[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 3176 by ovitters, Fri Mar 2 13:53:22 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  MEDIA="Core Release Source"  MEDIA="Core Release Source"
47  URL="http://download.gnome.org/sources/"  URL="http://download.gnome.org/sources/"
48  PKGROOT='~/pkgs'  PKGROOT='~/pkgs'
49    SLEEP_INITIAL=300
50    
51  re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*')  re_majmin = re.compile(r'^([0-9]+\.[0-9]+).*')
52  re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')  re_version = re.compile(r'([-.]|\d+|[^-.\d]+)')
# Line 81  def judge_version_increase(version_old, Line 89  def judge_version_increase(version_old,
89          compare = version_cmp(version_new, version_old)          compare = version_cmp(version_new, version_old)
90    
91          if compare == 0:          if compare == 0:
92                # 1.0.0 -> 1.0.1
93              return (-2, "Already at version %s!" % (version_old))              return (-2, "Already at version %s!" % (version_old))
94    
95          if compare != 1:          if compare != 1:
96                # 1.0.1 -> 1.0.0
97              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))
98    
99          # 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 114  def judge_version_increase(version_old,
114          # Major+minor the same? Then go ahead and upgrade!          # Major+minor the same? Then go ahead and upgrade!
115          if majmins[0] == majmins[1]:          if majmins[0] == majmins[1]:
116              # Majmin of both versions are the same, looks good!              # Majmin of both versions are the same, looks good!
117                # 1.1.x -> 1.1.x or 1.0.x -> 1.0.x
118              return (10, None)              return (10, None)
119    
120          # 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 122  def judge_version_increase(version_old,
122    
123          # Check/ensure major version number is the same          # Check/ensure major version number is the same
124          if majmin_nrs[0][0] != majmin_nrs[1][0]:          if majmin_nrs[0][0] != majmin_nrs[1][0]:
125                # 1.0.x -> 2.0.x
126              return (1, "Major version number increase")              return (1, "Major version number increase")
127    
128          # Minor indicates stable/unstable          # Minor indicates stable/unstable
# Line 119  def judge_version_increase(version_old, Line 131  def judge_version_increase(version_old,
131          # Upgrading to unstable is weird          # Upgrading to unstable is weird
132          if not devstate[1]:          if not devstate[1]:
133              if devstate[0]:              if devstate[0]:
134                    # 1.2.x -> 1.3.x
135                  return (1, "Stable to unstable increase")                  return (1, "Stable to unstable increase")
136    
137                # 1.3.x -> 1.5.x
138              return (4, "Unstable to unstable version increase")              return (4, "Unstable to unstable version increase")
139    
140          # Unstable => stable is always ok          # Unstable => stable is always ok
141          if not devstate[0]:          if not devstate[0]:
142                # 1.1.x -> 1.2.x
143              return (5, "Unstable to stable")              return (5, "Unstable to stable")
144    
145          # Can only be increase of minors from one stable to the next          # Can only be increase of minors from one stable to the next
146            # 1.0.x -> 1.2.x
147          return (6, "Stable version increase")          return (6, "Stable version increase")
148    
149  def line_input (file):  def line_input (file):
# Line 481  def get_downstream_names(): Line 497  def get_downstream_names():
497    
498      return TARBALLS, FILES      return TARBALLS, FILES
499    
500    def get_downstream_from_upstream(upstream, version):
501        # Determine the package name
502        downstream, downstream_files = get_downstream_names()
503    
504        if upstream not in downstream:
505            raise ValueError("No packages for upstream name: %s" % upstream)
506    
507        if len(downstream[upstream]) != 1:
508            # XXX - Make it more intelligent
509            raise ValueError("Multiple packages found for %s: %s" % (upstream, ", ".join(downstream[upstream])))
510    
511        return list(downstream[upstream])
512    
513  def write_file(path, data):  def write_file(path, data):
514      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 543  def cmd_dep3(options, parser): Line 571  def cmd_dep3(options, parser):
571  def cmd_package_new_version(options, parser):  def cmd_package_new_version(options, parser):
572      # Determine the package name      # Determine the package name
573      if options.upstream:      if options.upstream:
574          downstream, downstream_files = get_downstream_names()          try:
575                package = get_downstream_from_upstream(options.package, options.version)[0]
576          if options.package not in downstream:          except ValueError, e:
577              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]))  
578              sys.exit(1)              sys.exit(1)
   
         package = list(downstream[options.package])[0]  
579      else:      else:
580          package = options.package          package = options.package
581    
# Line 598  def cmd_package_new_version(options, par Line 619  def cmd_package_new_version(options, par
619          except subprocess.CalledProcessError:          except subprocess.CalledProcessError:
620              sys.exit(1)              sys.exit(1)
621    
622    def cmd_parse_ftp_release_list(options, parser):
623        # XXX - not working yet
624        def _send_reply_mail(contents, orig_msg, to):
625            """Send an reply email"""
626            contents.seek(0)
627            msg = MIMEText(contents.read(), _charset='utf-8')
628            msg['Subject'] = "Re: %s" % orig_msg['Subject']
629            msg['To'] = to
630            msg["In-Reply-To"] = orig_msg["Message-ID"]
631            msg["References"] = orig_msg["Message-ID"]
632    
633            # Call sendmail program directly so it doesn't matter if the service is running
634            cmd = ['/usr/sbin/sendmail', '-oi', '--']
635            cmd.extend([to])
636            p = subprocess.Popen(cmd, stdin=subprocess.PIPE)
637            p.stdin.write(msg.as_string())
638            p.stdin.flush()
639            p.stdin.close()
640            p.wait()
641    
642    
643        msg = email.email.message_from_file(sys.stdin)
644    
645        if options.mail:
646            stdout = tempfile.TemporaryFile()
647            stderr = stdout
648        else:
649            stdout = sys.stdout
650            stderr = sys.stderr
651    
652        try:
653            module = msg['X-Module-Name']
654            version = msg['X-Module-Version']
655            hexdigest = msg['X-Module-SHA256-tar.xz']
656        except KeyError, e:
657            print >>stderr, "ERROR: %s" % e
658            if options.mail: _send_reply_mail(stdout, msg, options.mail)
659            sys.exit(1)
660    
661        try:
662            packages = get_downstream_from_upstream(module, version)
663        except ValueError, e:
664            print >>stderr, "ERROR: %s" % e
665            if options.mail: _send_reply_mail(stdout, msg, options.mail)
666            sys.exit(1)
667    
668        if options.wait:
669            # maildrop aborts and will try to deliver after 5min
670            # fork to avoid this
671            if os.fork() != 0: sys.exit(0)
672            time.sleep(SLEEP_INITIAL)
673    
674        for package in packages:
675            subprocess.call(['mga-gnome', 'increase', '--submit', '--hash', hexdigest, package, version], stdout=stdout, stderr=stderr)
676    
677        if options.mail: _send_reply_mail(stdout, msg, options.mail)
678    
679  def main():  def main():
680      description = """Mageia GNOME commands."""      description = """Mageia GNOME commands."""
# Line 647  def main(): Line 724  def main():
724          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"
725      )      )
726    
727        subparser = subparsers.add_parser('gnome-release-email', help='Submit packages based on GNOME ftp-release-list email')
728        subparser.add_argument("-m", "--mail", help="Email address to send the progress to")
729        subparser.add_argument("-w", "--wait", action="store_true",
730                                     help="Wait before trying to retrieve the new version")
731        subparser.set_defaults(
732            func=cmd_parse_ftp_release_list
733        )
734    
735      if len(sys.argv) == 1:      if len(sys.argv) == 1:
736          parser.print_help()          parser.print_help()
737          sys.exit(2)          sys.exit(2)

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

  ViewVC Help
Powered by ViewVC 1.1.30