Code Duplication    Length = 10-19 lines in 2 locations

elodie/localstorage.py 1 location

@@ 112-130 (lines=19) @@
109
        """
110
        return key in self.hash_db
111
112
    def checksum(self, file_path, blocksize=65536):
113
        """Create a hash value for the given file.
114
115
        See http://stackoverflow.com/a/3431835/1318758.
116
117
        :param str file_path: Path to the file to create a hash for.
118
        :param int blocksize: Read blocks of this size from the file when
119
            creating the hash.
120
        :returns: str or None
121
        """
122
        hasher = hashlib.sha256()
123
        with open(file_path, 'rb') as f:
124
            buf = f.read(blocksize)
125
126
            while len(buf) > 0:
127
                hasher.update(buf)
128
                buf = f.read(blocksize)
129
            return hasher.hexdigest()
130
        return None
131
132
    def get_hash(self, key):
133
        """Get the hash value for a given key.

elodie/tests/helper.py 1 location

@@ 20-29 (lines=10) @@
17
from elodie.compatability import _rename
18
from elodie import constants
19
20
def checksum(file_path, blocksize=65536):
21
    hasher = hashlib.sha256()
22
    with open(file_path, 'rb') as f:
23
        buf = f.read(blocksize)
24
25
        while len(buf) > 0:
26
            hasher.update(buf)
27
            buf = f.read(blocksize)
28
        return hasher.hexdigest()
29
    return None
30
31
def create_working_folder(format=None):
32
    temporary_folder = tempfile.gettempdir()