Merges pull request #49 from dedan/remove_single_tags

* remove_single_tags:
  Cleaner syntax and messages
  remove tags that were used only once.
This commit is contained in:
Manuel Ebert 2013-03-04 14:55:30 -08:00
commit 3ecf8e343c

View file

@ -105,7 +105,10 @@ def print_tags(journal):
] ]
# To be read: [for entry in journal.entries: for tag in set(entry.tags): tag] # To be read: [for entry in journal.entries: for tag in set(entry.tags): tag]
tag_counts = {(tags.count(tag), tag) for tag in tags} tag_counts = {(tags.count(tag), tag) for tag in tags}
for n, tag in sorted(tag_counts, reverse=True): if min(tag_counts)[0] == 0:
tag_counts = filter(lambda x: x[0] > 1, tag_counts)
print('[Removed tags that appear only once.]')
for n, tag in sorted(tag_counts, reverse=False):
print("{:20} : {}".format(tag, n)) print("{:20} : {}".format(tag, n))
@ -139,7 +142,7 @@ def cli():
print("According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org.") print("According to your jrnl_conf, your journal is encrypted, however PyCrypto was not found. To open your journal, install the PyCrypto package from http://www.pycrypto.org.")
sys.exit(-1) sys.exit(-1)
args = parse_args() args = parse_args()
# If the first textual argument points to a journal file, # If the first textual argument points to a journal file,
# use this! # use this!
@ -183,7 +186,7 @@ def cli():
print(journal) print(journal)
# Various export modes # Various export modes
elif args.tags: elif args.tags:
print_tags(journal) print_tags(journal)
elif args.json: # export to json elif args.json: # export to json
@ -198,14 +201,14 @@ def cli():
elif args.encrypt is not False: elif args.encrypt is not False:
encrypt(journal, filename=args.encrypt) encrypt(journal, filename=args.encrypt)
# Not encrypting to a separate file: update config! # Not encrypting to a separate file: update config!
if not args.encrypt: if not args.encrypt:
update_config(original_config, {"encrypt": True, "password": ""}, journal_name) update_config(original_config, {"encrypt": True, "password": ""}, journal_name)
install.save_config(original_config, config_path=CONFIG_PATH) install.save_config(original_config, config_path=CONFIG_PATH)
elif args.decrypt is not False: elif args.decrypt is not False:
decrypt(journal, filename=args.decrypt) decrypt(journal, filename=args.decrypt)
# Not decrypting to a separate file: update config! # Not decrypting to a separate file: update config!
if not args.decrypt: if not args.decrypt:
update_config(original_config, {"encrypt": False, "password": ""}, journal_name) update_config(original_config, {"encrypt": False, "password": ""}, journal_name)
install.save_config(original_config, config_path=CONFIG_PATH) install.save_config(original_config, config_path=CONFIG_PATH)
@ -218,4 +221,3 @@ def cli():
if __name__ == "__main__": if __name__ == "__main__":
cli() cli()