Merge lp:~akshatj/dmedia/quick-id into lp:~jderose/dmedia/trunk

Proposed by Akshat Jain
Status: Merged
Merged at revision: 106
Proposed branch: lp:~akshatj/dmedia/quick-id
Merge into: lp:~jderose/dmedia/trunk
Diff against target: 59 lines (+15/-2)
2 files modified
dmedialib/filestore.py (+9/-0)
dmedialib/tests/test_filestore.py (+6/-2)
To merge this branch: bzr merge lp:~akshatj/dmedia/quick-id
Reviewer Review Type Date Requested Status
Jason Gerard DeRose Pending
Review via email: mp+40800@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'dmedialib/filestore.py'
2--- dmedialib/filestore.py 2010-10-21 04:42:28 +0000
3+++ dmedialib/filestore.py 2010-11-14 03:56:13 +0000
4@@ -1,5 +1,6 @@
5 # Authors:
6 # Jason Gerard DeRose <jderose@jasonderose.org>
7+# Akshat Jain <ssj6akshat1234@gmail.com)
8 #
9 # dmedia: distributed media library
10 # Copyright (C) 2010 Jason Gerard DeRose <jderose@jasonderose.org>
11@@ -36,8 +37,16 @@
12
13
14 CHUNK = 2 ** 20 # Read in chunks of 1 MiB
15+QUICK_ID_CHUNK = 2 ** 20
16 DOTDIR = '.dmedia'
17
18+def quick_id(filename):
19+
20+ hash_ = sha1()
21+ hash_.update(str(path.getsize(filename)))
22+ hash_.update(open(filename, 'rb').read(QUICK_ID_CHUNK))
23+ return b32encode(hash_.digest())
24+
25
26 def normalize_ext(name):
27 """
28
29=== modified file 'dmedialib/tests/test_filestore.py'
30--- dmedialib/tests/test_filestore.py 2010-11-08 00:37:51 +0000
31+++ dmedialib/tests/test_filestore.py 2010-11-14 03:56:13 +0000
32@@ -1,5 +1,6 @@
33 # Authors:
34 # Jason Gerard DeRose <jderose@jasonderose.org>
35+# Akshat Jain <ssj6akshat1234@gmail.com>
36 #
37 # dmedia: distributed media library
38 # Copyright (C) 2010 Jason Gerard DeRose <jderose@jasonderose.org>
39@@ -28,7 +29,7 @@
40 from os import path
41 import hashlib
42 from unittest import TestCase
43-from .helpers import TempDir, TempHome, raises
44+from .helpers import TempDir, TempHome, raises, sample_mov
45 from dmedialib import filestore
46
47
48@@ -45,7 +46,10 @@
49
50
51 class test_functions(TestCase):
52-
53+ def test_quick_id(self):
54+ f = filestore.quick_id
55+ self.assertEqual(f(sample_mov), 'GJ4AQP3BK3DMTXYOLKDK6CW4QIJJGVMN')
56+
57 def test_scanfiles(self):
58 f = filestore.scanfiles
59 tmp = TempDir()

Subscribers

People subscribed via source and target branches