Merge pull request #72 from noonat/import-trash

Allow import command to trash imported files
This commit is contained in:
Jaisen Mathai 2016-01-09 18:57:48 -08:00
commit 2ae5ec8443
3 changed files with 9 additions and 4 deletions

View File

@ -7,7 +7,7 @@ before_install:
- "sudo apt-get update -qq" - "sudo apt-get update -qq"
- "sudo apt-get install python-dev python-pip python-pyexiv2 libimage-exiftool-perl -y" - "sudo apt-get install python-dev python-pip python-pyexiv2 libimage-exiftool-perl -y"
install: install:
- "sudo pip install docopt LatLon mock nose requests" - "sudo pip install docopt LatLon mock nose requests send2trash"
# command to run tests # command to run tests
# test mapquest key # test mapquest key
before_script: before_script:

View File

@ -2,4 +2,5 @@ LatLon
docopt docopt
requests requests
mock mock
send2trash
sphinx sphinx

View File

@ -6,6 +6,7 @@ import sys
from datetime import datetime from datetime import datetime
from docopt import docopt from docopt import docopt
from send2trash import send2trash
# Verify that external dependencies are present first, so the user gets a # Verify that external dependencies are present first, so the user gets a
# more user-friendly error instead of an ImportError traceback. # more user-friendly error instead of an ImportError traceback.
@ -27,7 +28,7 @@ def usage():
"""Return usage message """Return usage message
""" """
return """ return """
Usage: elodie.py import --destination=<d> [--source=<s>] [--file=<f>] [--album-from-folder] [INPUT ...] Usage: elodie.py import --destination=<d> [--source=<s>] [--file=<f>] [--album-from-folder] [--trash] [INPUT ...]
elodie.py update [--time=<t>] [--location=<l>] [--album=<a>] [--title=<t>] INPUT ... elodie.py update [--time=<t>] [--location=<l>] [--album=<a>] [--title=<t>] INPUT ...
-h --help show this -h --help show this
@ -37,7 +38,7 @@ DB = Db()
FILESYSTEM = FileSystem() FILESYSTEM = FileSystem()
def import_file(_file, destination, album_from_folder): def import_file(_file, destination, album_from_folder, trash):
"""Set file metadata and move it to destination. """Set file metadata and move it to destination.
""" """
if not os.path.exists(_file): if not os.path.exists(_file):
@ -64,6 +65,8 @@ def import_file(_file, destination, album_from_folder):
media, allowDuplicate=False, move=False) media, allowDuplicate=False, move=False)
if dest_path: if dest_path:
print '%s -> %s' % (_file, dest_path) print '%s -> %s' % (_file, dest_path)
if trash:
send2trash(_file)
def _import(params): def _import(params):
@ -85,7 +88,8 @@ def _import(params):
files.add(path) files.add(path)
for current_file in files: for current_file in files:
import_file(current_file, destination, params['--album-from-folder']) import_file(current_file, destination, params['--album-from-folder'],
params['--trash'])
def update_location(media, file_path, location_name): def update_location(media, file_path, location_name):