/[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 3555 by ovitters, Sun Mar 18 11:08:07 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  SLEEP_REPEAT=30
54  SLEEP_TIMES=20  SLEEP_TIMES=20
55    
# Line 274  class SpecFile(object): Line 274  class SpecFile(object):
274              if not force: 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 309  class SpecFile(object): Line 319  class SpecFile(object):
319          tries = 0          tries = 0
320          while tries < SLEEP_TIMES:          while tries < SLEEP_TIMES:
321              tries += 1              tries += 1
322                if tries > 1: time.sleep(SLEEP_REPEAT)
323              try:              try:
324                  # Download new tarball                  # Download new tarball
325                  subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd)                  subprocess.check_call(['mgarepo', 'sync', '-d'], cwd=self.cwd)
326                    # success, so exit loop
327                  break                  break
328              except subprocess.CalledProcessError, e:              except subprocess.CalledProcessError, e:
329                  # mgarepo sync returns 1 if the tarball cannot be downloaded                  # mgarepo sync returns 1 if the tarball cannot be downloaded
330                  if e.returncode != 1:                  if e.returncode != 1:
331                      return False                      return False
332            else:
333                return False
334    
                 if tries == SLEEP_TIMES:  
                     return False  
   
                 time.sleep(SLEEP_REPEAT)  
335    
336          try:          try:
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 526  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].keys())))  
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 downstream[upstream].keys()      # 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        # 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 630  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 642  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      def _send_reply_mail(contents, orig_msg, to, error=False):      def _send_reply_mail(contents, orig_msg, to, packages=[], 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    
701          if error:          if error:
702              # XXX - ugly              # XXX - ugly
703              contents.seek(0)              contents.seek(0)
704              lastline = contents.read().splitlines()[-1]              lastline = contents.read().rstrip().splitlines()[-1]
705              # Remove things like "ERROR: " and so on from the last line              # Remove things like "ERROR: " and so on from the last line
706              lastline = re.sub(r'^(?:[^ :]+:\s+)+', '', lastline)              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)"              subjecterror = " (ERROR: %s)" % lastline if lastline else " (ERROR)"
710          else:          else:
711              subjecterror = ""              subjecterror = ""
712          msg['Subject'] = "Re: %s%s" % (orig_msg['Subject'], subjecterror)  
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 704  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 772  def main(): Line 838  def main():
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 796  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.3555  
changed lines
  Added in v.3647

  ViewVC Help
Powered by ViewVC 1.1.30