blob: 22e47d2ae6a3876df6dd48921c976d488a0b4534 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# -*- coding: utf-8 -*-
"""
checksum.py
~~~~~~~~~~~
This module implements functions for compute/generate SHA1 checksums
for DESCRIPTION files.
:copyright: (c) 2010 by Rafael Goncalves Martins
:license: GPL-2, see LICENSE for more details.
"""
from __future__ import absolute_import
__all__ = [
'sha1_compute',
'sha1_check',
'sha1_check_db',
]
from hashlib import sha1
import json
import os
from .config import Config
from .compat import py3k
config = Config()
def sha1_compute(filename):
with open(filename) as fp:
content = fp.read()
if py3k:
content = bytes(content, 'utf-8')
return sha1(content).hexdigest()
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
|