Add arguments module and turn import.py into proper script with arguments

This commit is contained in:
Jaisen Mathai 2015-10-06 22:35:11 -07:00
parent a03c9c1d42
commit 0d471e0b4f
4 changed files with 64 additions and 34 deletions

View File

@ -1,33 +0,0 @@
#!/usr/bin/env python
import os
import shutil
import sys
from elodie.media.video import Video
from elodie.filesystem import FileSystem
destination = '%s/tmp' % os.path.expanduser('~')
filesystem = FileSystem()
for video_file in filesystem.get_all_files('/Users/jaisenmathai/Pictures/Videos/', Video.get_valid_extensions()):
video = Video(video_file)
filesystem.set_date_from_path_video(video)
metadata = video.get_metadata()
directory_name = filesystem.get_folder_name_by_date(metadata['date_taken'])
dest_directory = '%s/%s' % (destination, directory_name)
# TODO remove the day prefix of the file that was there prior to the crawl
file_name = filesystem.get_file_name_for_video(video)
dest_path = '%s/%s' % (dest_directory, file_name)
filesystem.create_directory(dest_directory)
print '%s -> %s' % (video_file, dest_path)
shutil.copy2(video_file, dest_path)

24
elodie/arguments.py Normal file
View File

@ -0,0 +1,24 @@
"""
"""
import sys, getopt
from re import sub
def parse(argv, options, long_options, usage):
def help():
print 'Usage: %s' % usage
try:
opts, args = getopt.getopt(argv, options, long_options)
except getopt.GetoptError:
print 'Unknown arguments'
help()
sys.exit(2)
return_arguments = {}
for opt, arg in opts:
if opt == '-h':
help()
sys.exit()
else:
return_arguments[sub('^-+', '', opt)] = arg
return return_arguments

View File

@ -60,7 +60,7 @@ class FileSystem:
return None return None
file_name = '%s-%s.%s' % (time.strftime('%Y-%m-%d_%H-%M-%S', metadata['date_taken']), metadata['base_name'], metadata['extension']) file_name = '%s-%s.%s' % (time.strftime('%Y-%m-%d_%H-%M-%S', metadata['date_taken']), metadata['base_name'], metadata['extension'])
return file_name return file_name.lower()
""" """
Get date based folder name. Get date based folder name.

39
import.py Executable file
View File

@ -0,0 +1,39 @@
#!/usr/bin/env python
import os
import shutil
import sys
from elodie import arguments
from elodie.media.video import Video
from elodie.filesystem import FileSystem
def main(argv):
args = arguments.parse(argv, None, ['source=','destination='], './import.py --source=<source directory> -destination=<destination directory>')
source = args['source']
destination = args['destination']
filesystem = FileSystem()
for video_file in filesystem.get_all_files(source, Video.get_valid_extensions()):
video = Video(video_file)
filesystem.set_date_from_path_video(video)
metadata = video.get_metadata()
directory_name = filesystem.get_folder_name_by_date(metadata['date_taken'])
dest_directory = '%s/%s' % (destination, directory_name)
# TODO remove the day prefix of the file that was there prior to the crawl
file_name = filesystem.get_file_name_for_video(video)
dest_path = '%s/%s' % (dest_directory, file_name)
filesystem.create_directory(dest_directory)
print '%s -> %s' % (video_file, dest_path)
shutil.copy2(video_file, dest_path)
if __name__ == '__main__':
main(sys.argv[1:])