Add support for --file to import.py and return exit code
This commit is contained in:
parent
866e4dd6d3
commit
af38851e23
57
import.py
57
import.py
|
@ -10,32 +10,20 @@ from elodie.media.video import Video
|
||||||
from elodie.filesystem import FileSystem
|
from elodie.filesystem import FileSystem
|
||||||
from elodie.localstorage import Db
|
from elodie.localstorage import Db
|
||||||
|
|
||||||
def main(argv):
|
|
||||||
args = arguments.parse(argv, None, ['type=','source=','destination='], './import.py --type=<photo or video> --source=<source directory> -destination=<destination directory>')
|
|
||||||
|
|
||||||
db = Db()
|
db = Db()
|
||||||
|
|
||||||
source = args['source']
|
|
||||||
destination = args['destination']
|
|
||||||
|
|
||||||
filesystem = FileSystem()
|
filesystem = FileSystem()
|
||||||
if(args['type'] == 'photo'):
|
|
||||||
media_type = Photo
|
|
||||||
else:
|
|
||||||
media_type = Video
|
|
||||||
|
|
||||||
write_counter = 0
|
def process_file(_file):
|
||||||
for current_file in filesystem.get_all_files(source, media_type.get_valid_extensions()):
|
checksum = db.checksum(_file)
|
||||||
checksum = db.checksum(current_file)
|
|
||||||
if(checksum == None):
|
if(checksum == None):
|
||||||
print 'Could not get checksum for %s. Skipping...' % current_file
|
print 'Could not get checksum for %s. Skipping...' % _file
|
||||||
continue
|
return
|
||||||
|
|
||||||
if(db.check_hash(checksum) == True):
|
if(db.check_hash(checksum) == True):
|
||||||
print '%s already exists at %s. Skipping...' % (current_file, db.get_hash(checksum))
|
print '%s already exists at %s. Skipping...' % (_file, db.get_hash(checksum))
|
||||||
continue
|
return
|
||||||
|
|
||||||
media = media_type(current_file)
|
media = media_type(_file)
|
||||||
|
|
||||||
if(media_type.__name__ == 'Video'):
|
if(media_type.__name__ == 'Video'):
|
||||||
filesystem.set_date_from_path_video(media)
|
filesystem.set_date_from_path_video(media)
|
||||||
|
@ -51,21 +39,42 @@ def main(argv):
|
||||||
|
|
||||||
filesystem.create_directory(dest_directory)
|
filesystem.create_directory(dest_directory)
|
||||||
|
|
||||||
print '%s -> %s' % (current_file, dest_path)
|
print '%s -> %s' % (_file, dest_path)
|
||||||
shutil.copy2(current_file, dest_path)
|
shutil.copy2(_file, dest_path)
|
||||||
#shutil.move(current_file, dest_path)
|
#shutil.move(_file, dest_path)
|
||||||
db.add_hash(checksum, dest_path)
|
db.add_hash(checksum, dest_path)
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
args = arguments.parse(argv, None, ['file=','type=','source=','destination='], './import.py --type=<photo or video> --source=<source directory> -destination=<destination directory>')
|
||||||
|
|
||||||
|
if('destination' not in args):
|
||||||
|
print 'No destination passed in'
|
||||||
|
sys.exit(2)
|
||||||
|
|
||||||
|
destination = args['destination']
|
||||||
|
if('type' in args and args['type'] == 'photo'):
|
||||||
|
media_type = Photo
|
||||||
|
else:
|
||||||
|
media_type = Video
|
||||||
|
|
||||||
|
if('source' in args):
|
||||||
|
source = args['source']
|
||||||
|
|
||||||
|
write_counter = 0
|
||||||
|
for current_file in filesystem.get_all_files(source, media_type.get_valid_extensions()):
|
||||||
|
process_file(current_file)
|
||||||
# Write to the hash database every 10 iterations
|
# Write to the hash database every 10 iterations
|
||||||
write_counter += 1
|
write_counter += 1
|
||||||
if(write_counter % 10 == 0):
|
if(write_counter % 10 == 0):
|
||||||
db.update_hash_db()
|
db.update_hash_db()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# If there's anything we haven't written to the hash database then write it now
|
# If there's anything we haven't written to the hash database then write it now
|
||||||
if(write_counter % 10 != 10):
|
if(write_counter % 10 != 10):
|
||||||
db.update_hash_db()
|
db.update_hash_db()
|
||||||
|
elif('file' in args):
|
||||||
|
process_file(args['file'])
|
||||||
|
db.update_hash_db()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main(sys.argv[1:])
|
main(sys.argv[1:])
|
||||||
|
sys.exit(0)
|
||||||
|
|
Loading…
Reference in New Issue