| 1 |
# Copyright (c) 2012-2013 Paul Tagliamonte <[email protected]> |
| 2 |
# Copyright (c) 2014 Jon Severinsson <[email protected]> |
| 3 |
# |
| 4 |
# Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
# copy of this software and associated documentation files (the "Software"), |
| 6 |
# to deal in the Software without restriction, including without limitation |
| 7 |
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
# and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
# Software is furnished to do so, subject to the following conditions: |
| 10 |
# |
| 11 |
# The above copyright notice and this permission notice shall be included in |
| 12 |
# all copies or substantial portions of the Software. |
| 13 |
# |
| 14 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 18 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 19 |
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 20 |
# DEALINGS IN THE SOFTWARE. |
| 21 |
|
| 22 |
import os |
| 23 |
import hashlib |
| 24 |
|
| 25 |
from debian.deb822 import Changes as Changes_ |
| 26 |
from debian.deb822 import _gpg_multivalued |
| 27 |
|
| 28 |
|
| 29 |
# Copy of debian.deb822.Dsc with Package-List: support added. |
| 30 |
class Dsc(_gpg_multivalued): |
| 31 |
_multivalued_fields = { |
| 32 |
"package-list": ["name", "type", "section", "priority"], |
| 33 |
"files": ["md5sum", "size", "name"], |
| 34 |
"checksums-sha1": ["sha1", "size", "name"], |
| 35 |
"checksums-sha256": ["sha256", "size", "name"], |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
# Extention to debian.deb822.Changes with add_file() support |
| 40 |
# Also useful for Debile *.dud files. |
| 41 |
class Changes(Changes_): |
| 42 |
def add_file(self, fp): |
| 43 |
statinfo = os.stat(fp) |
| 44 |
size = statinfo.st_size |
| 45 |
|
| 46 |
algos = { |
| 47 |
"Files": "md5", |
| 48 |
"Checksums-Sha1": "sha1", |
| 49 |
"Checksums-Sha256": "sha256", |
| 50 |
} |
| 51 |
|
| 52 |
for key, algo in algos.items(): |
| 53 |
if key not in self: |
| 54 |
self[key] = [] |
| 55 |
|
| 56 |
m = hashlib.new(algo) |
| 57 |
with open(fp, "rb") as fd: |
| 58 |
for chunk in iter((lambda fd=fd, m=m: fd.read(128 * m.block_size)), b''): |
| 59 |
m.update(chunk) |
| 60 |
|
| 61 |
if key != "Files": |
| 62 |
self[key].append({algo: m.hexdigest(), "size": size, "name": fp}) |
| 63 |
else: |
| 64 |
self[key].append( |
| 65 |
{ |
| 66 |
"md5sum": m.hexdigest(), |
| 67 |
"size": size, |
| 68 |
"section": 'spark', |
| 69 |
"priority": 'spark', |
| 70 |
"name": fp, |
| 71 |
} |
| 72 |
) |