Add support for directories as argument to update command #178 (#182)

This commit is contained in:
Jaisen Mathai 2017-01-07 21:49:00 -08:00 committed by GitHub
parent 26c9b85457
commit 78880a6020
3 changed files with 46 additions and 3 deletions

View File

@ -54,6 +54,8 @@ You'll notice that the photo was organized into an *Unknown Location* folder. Th
You can view these instructions on the command line by typing `./elodie.py import --help`, `./elodie.py update --help` or `./elodie.py generate-db --help`. You can view these instructions on the command line by typing `./elodie.py import --help`, `./elodie.py update --help` or `./elodie.py generate-db --help`.
### Import photos
``` ```
Usage: elodie.py import [OPTIONS] [PATHS]... Usage: elodie.py import [OPTIONS] [PATHS]...
@ -72,6 +74,8 @@ Options:
--help Show this message and exit. --help Show this message and exit.
``` ```
### Update photos
``` ```
Usage: elodie.py update [OPTIONS] FILES... Usage: elodie.py update [OPTIONS] FILES...
@ -88,6 +92,8 @@ Options:
--help Show this message and exit. --help Show this message and exit.
``` ```
### (Re)Generate checksum database
``` ```
Usage: elodie.py generate-db [OPTIONS] Usage: elodie.py generate-db [OPTIONS]
@ -99,6 +105,12 @@ Options:
--help Show this message and exit. --help Show this message and exit.
``` ```
### Verify library against bit rot / data rot
```
Usage: elodie.py verify
```
Now you're ready to learn more about Elodie. Now you're ready to learn more about Elodie.
<p align="center"><img src ="creative/logo@300x.png" /></p> <p align="center"><img src ="creative/logo@300x.png" /></p>
@ -223,7 +235,7 @@ I use the [Open Street Maps Nominatim reverse geocoding API](http://wiki.openstr
* To have `Sunnyvale`, use `location=%city` * To have `Sunnyvale`, use `location=%city`
* To have `Sunnyvale-CA`, use `location=%city-%state * To have `Sunnyvale-CA`, use `location=%city-%state
Sometimes a location may not have all of the values available. If your format is `%city-%state` and `city` was not returned then the folder name will be `%state`. Take not that I'll strip out extra characters so you don't end up with folders name `-%state` when `city` is not found. Sometimes a location may not have all of the values available. If your format is `%city-%state` and `city` was not returned then the folder name will be `%state`. Take note that I'll strip out extra characters so you don't end up with folders name `-%state` when `city` is not found.
### Reorganize by changing location and dates ### Reorganize by changing location and dates

13
elodie.py Normal file → Executable file
View File

@ -204,12 +204,21 @@ def update_time(media, file_path, time_string):
@click.option('--time', help=('Update the image time. Time should be in ' @click.option('--time', help=('Update the image time. Time should be in '
'YYYY-mm-dd hh:ii:ss or YYYY-mm-dd format.')) 'YYYY-mm-dd hh:ii:ss or YYYY-mm-dd format.'))
@click.option('--title', help='Update the image title.') @click.option('--title', help='Update the image title.')
@click.argument('files', nargs=-1, type=click.Path(dir_okay=False), @click.argument('paths', nargs=-1,
required=True) required=True)
def _update(album, location, time, title, files): def _update(album, location, time, title, paths):
"""Update a file's EXIF. Automatically modifies the file's location and file name accordingly. """Update a file's EXIF. Automatically modifies the file's location and file name accordingly.
""" """
result = Result() result = Result()
files = set()
for path in paths:
path = os.path.expanduser(path)
if os.path.isdir(path):
files.update(FILESYSTEM.get_all_files(path, None))
else:
files.add(path)
for current_file in files: for current_file in files:
if not os.path.exists(current_file): if not os.path.exists(current_file):
if constants.debug: if constants.debug:

View File

@ -389,6 +389,28 @@ def test_update_time_on_video():
assert metadata['date_taken'] != metadata_processed['date_taken'] assert metadata['date_taken'] != metadata_processed['date_taken']
assert metadata_processed['date_taken'] == helper.time_convert((2000, 1, 1, 12, 0, 0, 5, 1, 0)), metadata_processed['date_taken'] assert metadata_processed['date_taken'] == helper.time_convert((2000, 1, 1, 12, 0, 0, 5, 1, 0)), metadata_processed['date_taken']
def test_update_with_directory_passed_in():
temporary_folder, folder = helper.create_working_folder()
temporary_folder_destination, folder_destination = helper.create_working_folder()
origin = '%s/valid.txt' % folder
shutil.copyfile(helper.get_file('valid.txt'), origin)
helper.reset_dbs()
runner = CliRunner()
result = runner.invoke(elodie._import, ['--destination', folder_destination, folder])
runner2 = CliRunner()
result = runner2.invoke(elodie._update, ['--album', 'test', folder_destination])
helper.restore_dbs()
updated_file_path = "{}/2016-04-Apr/test/2016-04-07_11-15-26-valid-sample-title.txt".format(folder_destination)
updated_file_exists = os.path.isfile(updated_file_path)
shutil.rmtree(folder)
shutil.rmtree(folder_destination)
assert updated_file_exists, updated_file_path
def test_regenerate_db_invalid_source(): def test_regenerate_db_invalid_source():
runner = CliRunner() runner = CliRunner()
result = runner.invoke(elodie._generate_db, ['--source', '/invalid/path']) result = runner.invoke(elodie._generate_db, ['--source', '/invalid/path'])