/[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 3114 by ovitters, Tue Feb 28 08:18:12 2012 UTC revision 3115 by ovitters, Tue Feb 28 10:23:35 2012 UTC
# Line 33  from sgmllib import SGMLParser Line 33  from sgmllib import SGMLParser
33  import urllib2  import urllib2
34  import urlparse  import urlparse
35    
36    # for checking hashes
37    import hashlib
38    
39  MEDIA="Core Release Source"  MEDIA="Core Release Source"
40  URL="http://download.gnome.org/sources/"  URL="http://download.gnome.org/sources/"
41  PKGROOT='~/pkgs'  PKGROOT='~/pkgs'
# Line 202  class XzTarFile(tarfile.TarFile): Line 205  class XzTarFile(tarfile.TarFile):
205  if not hasattr(tarfile.TarFile, 'xzopen'):  if not hasattr(tarfile.TarFile, 'xzopen'):
206      tarfile.open = XzTarFile.open      tarfile.open = XzTarFile.open
207    
208    def is_valid_hash(path, algo, hexdigest):
209        if algo not in hashlib.algorithms:
210            raise ValueError("Unknown hash algorithm: %s" % algo)
211    
212        local_hash = getattr(hashlib, algo)()
213    
214        with open(path, 'rb') as fp:
215            data = fp.read(32768)
216            while data:
217                local_hash.update(data)
218                data = fp.read(32768)
219    
220        return local_hash.hexdigest() == hexdigest
221    
222  class SpecFile(object):  class SpecFile(object):
223      re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)      re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)
224      re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)      re_update_release = re.compile(r'^(?P<pre>Release:\s*)(?P<release>%mkrel \d+)(?P<post>\s*)$', re.MULTILINE + re.IGNORECASE)
# Line 213  class SpecFile(object): Line 230  class SpecFile(object):
230      @property      @property
231      def version(self):      def version(self):
232          return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0]          return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0]
233        @property
234        def sources(self):
235            ts = rpm.ts()
236            spec = ts.parseSpec(self.path)
237            srclist = spec.sources if isinstance(spec.sources, (list, tuple)) \
238                            else spec.sources()
239            return dict((os.path.basename(name), name) for name, no, flags in srclist)
240    
241      def update(self, version):      def update(self, version):
242          """Update specfile (increase version)"""          """Update specfile (increase version)"""
# Line 550  def cmd_package_new_version(options, par Line 574  def cmd_package_new_version(options, par
574      if not s.update(options.version):      if not s.update(options.version):
575          sys.exit(1)          sys.exit(1)
576    
577        # Check hash, if given
578        if options.hexdigest is not None:
579            sources = [name for name, origname in s.sources.iteritems() if '://' in origname]
580            if not len(sources):
581                print >>sys.stderr, "ERROR: Cannot determine source file (for hash check)!"
582                sys.stderr(1)
583    
584            for filename in sources:
585                if not is_valid_hash(os.path.join(cwd, "SOURCES", filename), options.algo, options.hexdigest):
586                    print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path
587                    print >>sys.stderr, "ERROR: Reverting changes!"
588                    subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd)
589                    sys.exit(1)
590    
591      # We can even checkin and submit :-)      # We can even checkin and submit :-)
592      if options.submit:      if options.submit:
593          try:          try:
# Line 601  def main(): Line 639  def main():
639                                         help="Package name reflects the upstream name")                                         help="Package name reflects the upstream name")
640      subparser.add_argument("-s", "--submit", action="store_true", dest="submit",      subparser.add_argument("-s", "--submit", action="store_true", dest="submit",
641                                         help="Commit changes and submit")                                         help="Commit changes and submit")
642        subparser.add_argument("-a", "--algorithm", choices=hashlib.algorithms, dest="algo",
643                                           help="Hash algorithm")
644        subparser.add_argument("--hash", dest="hexdigest",
645                                           help="Hexdigest of the hash")
646      subparser.set_defaults(      subparser.set_defaults(
647          func=cmd_package_new_version, submit=False, upstream=False          func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256"
648      )      )
649    
650      if len(sys.argv) == 1:      if len(sys.argv) == 1:

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

  ViewVC Help
Powered by ViewVC 1.1.26