changed lookup function to return json
parent
8864947575
commit
f592f2808a
15
filetags.py
15
filetags.py
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
import sys, hashlib, os, sqlite3, shutil
|
||||
import sys, hashlib, os, sqlite3, shutil, json
|
||||
|
||||
################################################################################
|
||||
# program wide constants
|
||||
|
@ -141,6 +141,7 @@ def load_container_settings(storage_directory):
|
|||
cursor = db.cursor()
|
||||
cursor.execute("SELECT option, value FROM settings")
|
||||
|
||||
#TODO: check container settings properly instead of just assuming default values for things that aren't found
|
||||
# set default values and then read the db, just in case...
|
||||
parity = False
|
||||
parity_bytes = 512
|
||||
|
@ -366,11 +367,10 @@ if __name__ == "__main__":
|
|||
sys.exit(status)
|
||||
|
||||
file_tags_or_hash = sys.argv[3:]
|
||||
lookup_results = {}
|
||||
if not 'tags' in command:
|
||||
if file_hash_or_path_is_known_hash(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)
|
||||
lookup_results[file_tags_or_hash[0]] = get_tags_by_hash(storage_directory, file_tags_or_hash[0])
|
||||
|
||||
if not 'hash' in command:
|
||||
# create a two dimensional array of all the files associated with each individual tag
|
||||
|
@ -386,9 +386,10 @@ if __name__ == "__main__":
|
|||
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)
|
||||
for file_hash in common_file_hashes:
|
||||
lookup_results[file_hash] = get_tags_by_hash(storage_directory, file_hash)
|
||||
|
||||
print(json.dumps(lookup_results))
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue