diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2010-11-30 22:48:14 -0200 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2010-11-30 22:48:14 -0200 |
commit | 7a3383d518de501c88ef983847e5bf0205c66eba (patch) | |
tree | c60ff12ea64401e2673aa7a0f97247d7437a8891 /g_octave | |
parent | added checksum support to g_octave.description module, with test (diff) | |
download | g-octave-7a3383d518de501c88ef983847e5bf0205c66eba.tar.gz g-octave-7a3383d518de501c88ef983847e5bf0205c66eba.tar.bz2 g-octave-7a3383d518de501c88ef983847e5bf0205c66eba.zip |
added checksum support to package database fetch
Diffstat (limited to 'g_octave')
-rw-r--r-- | g_octave/checksum.py | 27 | ||||
-rw-r--r-- | g_octave/fetch.py | 3 |
2 files changed, 25 insertions, 5 deletions
diff --git a/g_octave/checksum.py b/g_octave/checksum.py index 79fe969..c5ead44 100644 --- a/g_octave/checksum.py +++ b/g_octave/checksum.py @@ -5,7 +5,7 @@ ~~~~~~~~~~~ This module implements functions for compute/generate SHA1 checksums - for files. + for DESCRIPTION files. :copyright: (c) 2010 by Rafael Goncalves Martins :license: GPL-2, see LICENSE for more details. @@ -16,15 +16,34 @@ from __future__ import absolute_import __all__ = [ 'sha1_compute', 'sha1_check', + 'sha1_check_db', ] -from .compat import open from hashlib import sha1 +import json +import os + +from .config import Config +config = Config(True) def sha1_compute(filename): with open(filename) as fp: return sha1(fp.read()).hexdigest() -def sha1_check(filename, checksum): - return sha1_compute(filename) == checksum +def sha1_check(db, p): + description = db[p] + manifest = {} + with open(os.path.join(config.db, 'manifest.json')) as fp: + manifest = json.load(fp) + if p not in manifest: + return False + return manifest[p] == description.sha1sum() + +def sha1_check_db(db): + for cat in db.pkg_list: + for pkg in db.pkg_list[cat]: + p = pkg['name']+'-'+pkg['version'] + if not sha1_check(db, p): + return False + return True diff --git a/g_octave/fetch.py b/g_octave/fetch.py index b8a8d6c..a0d7d5a 100644 --- a/g_octave/fetch.py +++ b/g_octave/fetch.py @@ -20,6 +20,7 @@ __all__ = ['fetch'] from .config import Config conf = Config(True) # fetch phase +from .description_tree import DescriptionTree from .exception import FetchException from .compat import py3k, open as open_ @@ -40,7 +41,7 @@ import tarfile from contextlib import closing def clean_db(): - for f in ['timestamp', 'info.json', 'patches', 'octave-forge']: + for f in ['timestamp', 'info.json', 'patches', 'octave-forge', 'manifest.json']: current = os.path.join(conf.db, f) if os.path.isdir(current): shutil.rmtree(current) |