added modifiers 'hash' and 'tags' to subcommand lookup

master
BodgeMaster 2021-12-12 09:40:25 +01:00
parent ebabc961fb
commit 9b836707d3
1 changed files with 26 additions and 22 deletions

View File

@ -344,9 +344,11 @@ if __name__ == "__main__":
# lookup subcommand: return hash and tags of found files
# arguments: <storage directory> <hash|exact tag|set of exact tags>
# modifiers:
# first - only return one file
# first - only return one file
# unique - return error if not found or multiple found
#TODO: modifiers
# hash - perform lookup by hash
# tags - perform lookup by tag or set of tags
#TODO: modifiers: first unique
if command[0] == "lookup":
if len(sys.argv)<4:
print("Too few arguments!", file=sys.stderr)
@ -363,28 +365,30 @@ if __name__ == "__main__":
print("Verifying container settings failed.", file=sys.stderr)
sys.exit(status)
file_tags_or_hash = sys.argv[3:]
if file_is_in_storage(storage_directory, file_tags_or_hash[0], compress):
tags = get_tags_by_hash(storage_directory, file_tags_or_hash[0])
print("Tags for file:")
print(tags)
if not 'tags' in command:
file_tags_or_hash = sys.argv[3:]
if file_is_in_storage(storage_directory, file_tags_or_hash[0], compress):
tags = get_tags_by_hash(storage_directory, file_tags_or_hash[0])
print("Tags for file:")
print(tags)
# create a two dimensional array of all the files associated with each individual tag
file_hash_lists = []
for tag in file_tags_or_hash:
file_hash_lists = file_hash_lists + [get_hashes_by_tag(storage_directory, tag)]
# take the first of the arrays in the two dimensional array
common_file_hashes = file_hash_lists[0]
# iterate over the two dimensional array
for file_hash_list in file_hash_lists:
# check each element in common_file_hashes to ensure it is also in all other arrays in the two dimensional array, remove if it isnt
for file_hash in common_file_hashes:
if not file_hash in file_hash_list:
common_file_hashes.remove(file_hash)
if not 'hash' in command:
# create a two dimensional array of all the files associated with each individual tag
file_hash_lists = []
for tag in file_tags_or_hash:
file_hash_lists = file_hash_lists + [get_hashes_by_tag(storage_directory, tag)]
# take the first of the arrays in the two dimensional array
common_file_hashes = file_hash_lists[0]
# iterate over the two dimensional array
for file_hash_list in file_hash_lists:
# check each element in common_file_hashes to ensure it is also in all other arrays in the two dimensional array, remove if it isnt
for file_hash in common_file_hashes:
if not file_hash in file_hash_list:
common_file_hashes.remove(file_hash)
if not common_file_hashes == []:
print("Files for tag(s):")
print(common_file_hashes)
if not common_file_hashes == []:
print("Files for tag(s):")
print(common_file_hashes)