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