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