summaryrefslogtreecommitdiffstats
path: root/mgagnome
diff options
context:
space:
mode:
authorOlav Vitters <ovitters@mageia.org>2012-02-28 10:23:35 +0000
committerOlav Vitters <ovitters@mageia.org>2012-02-28 10:23:35 +0000
commitf558348edfe897764a30d882b8947ddc76af0e5f (patch)
tree70045c6350e9a6f4f7879908520c24211b35cb11 /mgagnome
parent020a67c246932f1abf52897120b878b406c89f1f (diff)
downloadmgagnome-f558348edfe897764a30d882b8947ddc76af0e5f.tar
mgagnome-f558348edfe897764a30d882b8947ddc76af0e5f.tar.gz
mgagnome-f558348edfe897764a30d882b8947ddc76af0e5f.tar.bz2
mgagnome-f558348edfe897764a30d882b8947ddc76af0e5f.tar.xz
mgagnome-f558348edfe897764a30d882b8947ddc76af0e5f.zip
add ability to check hash of original tarball
Diffstat (limited to 'mgagnome')
-rwxr-xr-xmgagnome44
1 files changed, 43 insertions, 1 deletions
diff --git a/mgagnome b/mgagnome
index 097e991..b9557f5 100755
--- a/mgagnome
+++ b/mgagnome
@@ -33,6 +33,9 @@ from sgmllib import SGMLParser
import urllib2
import urlparse
+# for checking hashes
+import hashlib
+
MEDIA="Core Release Source"
URL="http://download.gnome.org/sources/"
PKGROOT='~/pkgs'
@@ -202,6 +205,20 @@ class XzTarFile(tarfile.TarFile):
if not hasattr(tarfile.TarFile, 'xzopen'):
tarfile.open = XzTarFile.open
+def is_valid_hash(path, algo, hexdigest):
+ if algo not in hashlib.algorithms:
+ raise ValueError("Unknown hash algorithm: %s" % algo)
+
+ local_hash = getattr(hashlib, algo)()
+
+ with open(path, 'rb') as fp:
+ data = fp.read(32768)
+ while data:
+ local_hash.update(data)
+ data = fp.read(32768)
+
+ return local_hash.hexdigest() == hexdigest
+
class SpecFile(object):
re_update_version = re.compile(r'^(?P<pre>Version:\s*)(?P<version>.+)(?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)
@@ -213,6 +230,13 @@ class SpecFile(object):
@property
def version(self):
return subprocess.check_output(["rpm", "--specfile", self.path, "--queryformat", "%{VERSION}\n"]).splitlines()[0]
+ @property
+ def sources(self):
+ ts = rpm.ts()
+ spec = ts.parseSpec(self.path)
+ srclist = spec.sources if isinstance(spec.sources, (list, tuple)) \
+ else spec.sources()
+ return dict((os.path.basename(name), name) for name, no, flags in srclist)
def update(self, version):
"""Update specfile (increase version)"""
@@ -550,6 +574,20 @@ def cmd_package_new_version(options, parser):
if not s.update(options.version):
sys.exit(1)
+ # Check hash, if given
+ if options.hexdigest is not None:
+ sources = [name for name, origname in s.sources.iteritems() if '://' in origname]
+ if not len(sources):
+ print >>sys.stderr, "ERROR: Cannot determine source file (for hash check)!"
+ sys.stderr(1)
+
+ for filename in sources:
+ if not is_valid_hash(os.path.join(cwd, "SOURCES", filename), options.algo, options.hexdigest):
+ print >>sys.stderr, "ERROR: Hash file failed check for %s!" % path
+ print >>sys.stderr, "ERROR: Reverting changes!"
+ subprocess.call(['svn', 'revert', '-R', cwd], cwd=cwd)
+ sys.exit(1)
+
# We can even checkin and submit :-)
if options.submit:
try:
@@ -601,8 +639,12 @@ def main():
help="Package name reflects the upstream name")
subparser.add_argument("-s", "--submit", action="store_true", dest="submit",
help="Commit changes and submit")
+ subparser.add_argument("-a", "--algorithm", choices=hashlib.algorithms, dest="algo",
+ help="Hash algorithm")
+ subparser.add_argument("--hash", dest="hexdigest",
+ help="Hexdigest of the hash")
subparser.set_defaults(
- func=cmd_package_new_version, submit=False, upstream=False
+ func=cmd_package_new_version, submit=False, upstream=False, hexdigest=None, algo="sha256"
)
if len(sys.argv) == 1: