Commit b11847ec by Guba Sándor

Merge branch 'feature-md5sum' into 'master'

Feature md5sum

See merge request !6
parents c7e54d3d b55486cb
...@@ -8,7 +8,7 @@ from zipfile import ZipFile, is_zipfile ...@@ -8,7 +8,7 @@ from zipfile import ZipFile, is_zipfile
from zlib import decompressobj, MAX_WBITS from zlib import decompressobj, MAX_WBITS
from bz2 import BZ2Decompressor from bz2 import BZ2Decompressor
from time import sleep from time import sleep
from hashlib import md5
import re import re
import requests import requests
...@@ -52,6 +52,14 @@ class Disk(object): ...@@ -52,6 +52,14 @@ class Disk(object):
self.actual_size = actual_size self.actual_size = actual_size
self.base_name = base_name self.base_name = base_name
@property
def checksum(self, blocksize=65536):
hash = md5()
with open(self.get_path(), "rb") as f:
for block in iter(lambda: f.read(blocksize), ""):
hash.update(block)
return hash.hexdigest()
@classmethod @classmethod
def deserialize(cls, desc): def deserialize(cls, desc):
"""Create cls object from JSON.""" """Create cls object from JSON."""
......
...@@ -37,7 +37,8 @@ class download(AbortableTask): ...@@ -37,7 +37,8 @@ class download(AbortableTask):
disk = Disk.deserialize(disk_desc) disk = Disk.deserialize(disk_desc)
disk.download(self, url, parent_id) disk.download(self, url, parent_id)
return {'size': disk.size, return {'size': disk.size,
'type': disk.format} 'type': disk.format,
'checksum': disk.checksum, }
@celery.task() @celery.task()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment