Feat: Start to add Directory indexing for file transfers
This commit is contained in:
parent
1ad307a462
commit
aae6a67a3b
@ -18,6 +18,7 @@ INGEST_DIR = filedialog.askdirectory()
|
|||||||
PHOTO_LIBRARY = '//192.168.1.4/photos/photo_library/'
|
PHOTO_LIBRARY = '//192.168.1.4/photos/photo_library/'
|
||||||
# TODO: Add dircectory traversal
|
# TODO: Add dircectory traversal
|
||||||
file_list = []
|
file_list = []
|
||||||
|
dir_list = {}
|
||||||
|
|
||||||
|
|
||||||
def compare_and_move():
|
def compare_and_move():
|
||||||
@ -25,12 +26,14 @@ def compare_and_move():
|
|||||||
for root, d_names, f_names in os.walk(INGEST_DIR, topdown=False):
|
for root, d_names, f_names in os.walk(INGEST_DIR, topdown=False):
|
||||||
for file in f_names:
|
for file in f_names:
|
||||||
file_name = os.path.join(root, file)
|
file_name = os.path.join(root, file)
|
||||||
print(file_name)
|
# print(file_name) # Debugging
|
||||||
file_list.append(file_name)
|
file_list.append(file_name)
|
||||||
print(root, d_names, f_names)
|
# print(root, d_names, f_names) # Debugging
|
||||||
print(file_list)
|
# print(file_list) # Debugging
|
||||||
print(len(file_list))
|
# print(len(file_list)) # Debugging
|
||||||
# process_files(file_list)
|
|
||||||
|
process_files(file_list)
|
||||||
|
print(dir_list.keys())
|
||||||
# remove_empty_directories(INGEST_DIR)
|
# remove_empty_directories(INGEST_DIR)
|
||||||
|
|
||||||
|
|
||||||
@ -67,11 +70,14 @@ def process_files(file_list):
|
|||||||
year = str(parsed_date.year)
|
year = str(parsed_date.year)
|
||||||
month = str(parsed_date.month).zfill(2)
|
month = str(parsed_date.month).zfill(2)
|
||||||
day = str(parsed_date.day).zfill(2)
|
day = str(parsed_date.day).zfill(2)
|
||||||
destination = "%s%s/%s/%s/%s" % (PHOTO_LIBRARY,
|
destination_path = "%s%s/%s" % (PHOTO_LIBRARY, year, month)
|
||||||
year, month, day, filename)
|
destination = "%s/%s" % (destination_path, filename)
|
||||||
|
if not destination in dir_list.keys():
|
||||||
|
dir_list[destination_path] = []
|
||||||
|
dir_list[destination_path].append(cur_file)
|
||||||
# print(destination)
|
# print(destination)
|
||||||
print("We want to move %s to %s%s/%s/%s." %
|
print("We want to move %s to %s%s/%s." %
|
||||||
(filename, PHOTO_LIBRARY, year, month, day))
|
(filename, PHOTO_LIBRARY, year, month))
|
||||||
|
|
||||||
# check if the directory exists
|
# check if the directory exists
|
||||||
if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year))):
|
if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year))):
|
||||||
@ -80,15 +86,15 @@ def process_files(file_list):
|
|||||||
if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month))):
|
if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month))):
|
||||||
print("We couldn't find your directory, matching year and month")
|
print("We couldn't find your directory, matching year and month")
|
||||||
os.makedirs(os.path.join(PHOTO_LIBRARY, str(year), str(month)))
|
os.makedirs(os.path.join(PHOTO_LIBRARY, str(year), str(month)))
|
||||||
if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month), str(day))):
|
# I'm not sure that I care about the day anymore #
|
||||||
print("We couldn't find your directory, matching year month and day")
|
# if not os.path.isdir(os.path.join(PHOTO_LIBRARY, str(year), str(month), str(day))):
|
||||||
os.makedirs(os.path.join(PHOTO_LIBRARY,
|
# print("We couldn't find your directory, matching year month and day")
|
||||||
str(year), str(month), str(day)))
|
# os.makedirs(os.path.join(PHOTO_LIBRARY,
|
||||||
|
# str(year), str(month), str(day)))
|
||||||
|
|
||||||
# We should be copying, creating a source and destination hash
|
# We should be copying, creating a source and destination hash
|
||||||
# comparing the files and then deleting the source
|
# comparing the files and then deleting the source
|
||||||
print()
|
print("\nCopying %s to %s" % (cur_file, destination))
|
||||||
print("Copying %s to %s" % (cur_file, destination))
|
|
||||||
copy2(cur_file, destination)
|
copy2(cur_file, destination)
|
||||||
if filecmp.cmp(cur_file, destination) == True:
|
if filecmp.cmp(cur_file, destination) == True:
|
||||||
print("%s and %s are a match. Time to delete %s" %
|
print("%s and %s are a match. Time to delete %s" %
|
||||||
|
Loading…
Reference in New Issue
Block a user