Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolved two issues: added support for MKV files and clarified "error" printed output #461

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
3 changes: 0 additions & 3 deletions elodie/filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,6 @@ def parse_mask_for_location(self, mask, location_parts, place_name):
def process_checksum(self, _file, allow_duplicate):
db = Db()
checksum = db.checksum(_file)
if(checksum is None):
log.info('Could not get checksum for %s.' % _file)
return None

# If duplicates are not allowed then we check if we've seen this file
# before via checksum. We also check that the file exists at the
Expand Down
1 change: 0 additions & 1 deletion elodie/localstorage.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ def checksum(self, file_path, blocksize=65536):
hasher.update(buf)
buf = f.read(blocksize)
return hasher.hexdigest()
return None

def get_hash(self, key):
"""Get the hash value for a given key.
Expand Down
2 changes: 1 addition & 1 deletion elodie/media/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Audio(Video):
__name__ = 'Audio'

#: Valid extensions for audio files.
extensions = ('m4a',)
extensions = ('m4a', 'mp3', 'opus', 'ogg', 'flac')

def __init__(self, source=None):
super(Audio, self).__init__(source)
2 changes: 1 addition & 1 deletion elodie/media/photo.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Photo(Media):
__name__ = 'Photo'

#: Valid extensions for photo files.
extensions = ('arw', 'cr2', 'dng', 'gif', 'heic', 'jpeg', 'jpg', 'nef', 'png', 'rw2')
extensions = ('arw', 'cr2', 'dng', 'gif', 'heic', 'jpeg', 'jpg', 'nef', 'png', 'rw2', 'webp', 'svg')

def __init__(self, source=None):
super(Photo, self).__init__(source)
Expand Down
2 changes: 1 addition & 1 deletion elodie/media/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Video(Media):
__name__ = 'Video'

#: Valid extensions for video files.
extensions = ('avi', 'm4v', 'mov', 'mp4', 'mpg', 'mpeg', '3gp', 'mts')
extensions = ('avi', 'm4v', 'mov', 'mp4', 'mpg', 'mpeg', '3gp', 'mts', 'mkv', 'webm')

def __init__(self, source=None):
super(Video, self).__init__(source)
Expand Down
18 changes: 18 additions & 0 deletions elodie/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ def __init__(self):
self.success = 0
self.error = 0
self.error_items = []
self.duplicate = 0
self.duplicate_items = []

def append(self, row):
id, status = row

# status can only be True, False, or None
if status:
self.success += 1
elif status is None: # status is only ever None if file checksum matched an existing file checksum and is therefore a duplicate file
self.duplicate += 1
self.duplicate_items.append(id)
else:
self.error += 1
self.error_items.append(id)

def write(self):
print("\n")
if self.error > 0:
error_headers = ["File"]
error_result = []
Expand All @@ -29,10 +36,21 @@ def write(self):
print(tabulate(error_result, headers=error_headers))
print("\n")

if self.duplicate > 0:
duplicate_headers = ["File"]
duplicate_result = []
for id in self.duplicate_items:
duplicate_result.append([id])

print("****** DUPLICATE (NOT IMPORTED) DETAILS ******")
print(tabulate(duplicate_result, headers=duplicate_headers))
print("\n")

headers = ["Metric", "Count"]
result = [
["Success", self.success],
["Error", self.error],
["Duplicate, not imported", self.duplicate]
]

print("****** SUMMARY ******")
Expand Down
45 changes: 28 additions & 17 deletions elodie/tests/elodie_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,9 @@ def test_import_file_with_single_exclude():
runner = CliRunner()
result = runner.invoke(elodie._import, ['--destination', folder_destination, '--exclude-regex', origin_valid[0:5], '--allow-duplicates', origin_valid])

assert 'Success 0' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Success 0' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Duplicate, not imported 0' in result.output, result.output

def test_import_file_with_multiple_exclude():
temporary_folder, folder = helper.create_working_folder()
Expand All @@ -313,8 +314,9 @@ def test_import_file_with_multiple_exclude():
runner = CliRunner()
result = runner.invoke(elodie._import, ['--destination', folder_destination, '--exclude-regex', 'does not exist in path', '--exclude-regex', origin_valid[0:5], '--allow-duplicates', origin_valid])

assert 'Success 0' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Success 0' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Duplicate, not imported 0' in result.output, result.output

def test_import_file_with_non_matching_exclude():
temporary_folder, folder = helper.create_working_folder()
Expand All @@ -326,8 +328,10 @@ def test_import_file_with_non_matching_exclude():
runner = CliRunner()
result = runner.invoke(elodie._import, ['--destination', folder_destination, '--exclude-regex', 'does not exist in path', '--allow-duplicates', origin_valid])

assert 'Success 1' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Success 1' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Duplicate, not imported 0' in result.output, result.output


def test_import_directory_with_matching_exclude():
temporary_folder, folder = helper.create_working_folder()
Expand All @@ -339,8 +343,9 @@ def test_import_directory_with_matching_exclude():
runner = CliRunner()
result = runner.invoke(elodie._import, ['--destination', folder_destination, '--source', folder, '--exclude-regex', folder[1:5], '--allow-duplicates'])

assert 'Success 0' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Success 0' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Duplicate, not imported 0' in result.output, result.output

def test_import_directory_with_non_matching_exclude():
temporary_folder, folder = helper.create_working_folder()
Expand All @@ -352,8 +357,10 @@ def test_import_directory_with_non_matching_exclude():
runner = CliRunner()
result = runner.invoke(elodie._import, ['--destination', folder_destination, '--source', folder, '--exclude-regex', 'non-matching', '--allow-duplicates'])

assert 'Success 1' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Success 1' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Duplicate, not imported 0' in result.output, result.output


@mock.patch('elodie.config.config_file', '%s/config.ini-import-file-with-single-config-exclude' % gettempdir())
def test_import_file_with_single_config_exclude():
Expand All @@ -379,8 +386,9 @@ def test_import_file_with_single_config_exclude():
if hasattr(load_config, 'config'):
del load_config.config

assert 'Success 0' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Success 0' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Duplicate, not imported 0' in result.output, result.output

@mock.patch('elodie.config.config_file', '%s/config.ini-import-file-with-multiple-config-exclude' % gettempdir())
def test_import_file_with_multiple_config_exclude():
Expand All @@ -407,8 +415,9 @@ def test_import_file_with_multiple_config_exclude():
if hasattr(load_config, 'config'):
del load_config.config

assert 'Success 0' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Success 0' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Duplicate, not imported 0' in result.output, result.output

def test_update_location_on_audio():
temporary_folder, folder = helper.create_working_folder()
Expand Down Expand Up @@ -705,8 +714,9 @@ def test_verify_ok():

shutil.rmtree(folder)

assert 'Success 1' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Success 1' in result.output, result.output
assert 'Error 0' in result.output, result.output
assert 'Duplicate, not imported 0' in result.output, result.output

def test_verify_error():
temporary_folder, folder = helper.create_working_folder()
Expand All @@ -725,7 +735,8 @@ def test_verify_error():
shutil.rmtree(folder)

assert origin in result.output, result.output
assert 'Error 1' in result.output, result.output
assert 'Error 1' in result.output, result.output
assert 'Duplicate, not imported 0' in result.output, result.output

@mock.patch('elodie.config.config_file', '%s/config.ini-cli-batch-plugin-googlephotos' % gettempdir())
def test_cli_batch_plugin_googlephotos():
Expand Down
27 changes: 15 additions & 12 deletions elodie/tests/result_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ def call_result_and_assert(result, expected):

def test_add_multiple_rows_with_success():
expected = """****** SUMMARY ******
Metric Count
-------- -------
Success 2
Error 0"""
Metric Count
----------------------- -------
Success 2
Error 0
Duplicate, not imported 0"""
result = Result()
result.append(('id1', '/some/path/1'))
result.append(('id2', '/some/path/2'))
Expand All @@ -48,10 +49,11 @@ def test_add_multiple_rows_with_failure():


****** SUMMARY ******
Metric Count
-------- -------
Success 0
Error 2"""
Metric Count
----------------------- -------
Success 0
Error 2
Duplicate, not imported 0"""
result = Result()
result.append(('id1', False))
result.append(('id2', False))
Expand All @@ -65,10 +67,11 @@ def test_add_multiple_rows_with_failure_and_success():


****** SUMMARY ******
Metric Count
-------- -------
Success 1
Error 1"""
Metric Count
----------------------- -------
Success 1
Error 1
Duplicate, not imported 0"""
result = Result()
result.append(('id1', False))
result.append(('id2', '/some/path'))
Expand Down