From 24df1b36ae30467ec809e4861247e8aa01da7967 Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Sun, 10 Nov 2013 12:45:05 +0100 Subject: [PATCH] tag cmd --- papers/commands/__init__.py | 2 +- papers/commands/tag_cmd.py | 28 +++++++++++++--------------- papers/commands/update_cmd.py | 1 - papers/papers_cmd.py | 2 +- 4 files changed, 15 insertions(+), 18 deletions(-) diff --git a/papers/commands/__init__.py b/papers/commands/__init__.py index 3e533a7..e415aa0 100644 --- a/papers/commands/__init__.py +++ b/papers/commands/__init__.py @@ -4,9 +4,9 @@ import list_cmd import open_cmd import websearch_cmd import remove_cmd +import tag_cmd # import import_cmd # import export_cmd # import edit_cmd -# import tag_cmd # import attach_cmd # import update_cmd diff --git a/papers/commands/tag_cmd.py b/papers/commands/tag_cmd.py index cfebd49..2395a9d 100644 --- a/papers/commands/tag_cmd.py +++ b/papers/commands/tag_cmd.py @@ -18,17 +18,16 @@ The different use cases are : """ from ..repo import Repository, InvalidReference -from . import helpers from ..configs import config from ..uis import get_ui +from .. import pretty def parser(subparsers): parser = subparsers.add_parser('tag', help="add, remove and show tags") - parser.add_argument('referenceOrTag', nargs='?', default = None, - help='reference to the paper (citekey or number), or ' - 'tag.') + parser.add_argument('citekeyOrTag', nargs='?', default = None, + help='citekey or tag.') parser.add_argument('tags', nargs='?', default = None, - help='If the previous argument was a reference, then ' + help='If the previous argument was a citekey, then ' 'then a list of tags separated by a +.') # TODO find a way to display clear help for multiple command semantics, # indistinguisable for argparse. (fabien, 201306) @@ -69,19 +68,18 @@ def command(args): """Add, remove and show tags""" ui = get_ui() - referenceOrTag = args.referenceOrTag + citekeyOrTag = args.citekeyOrTag tags = args.tags rp = Repository(config()) - if referenceOrTag is None: + if citekeyOrTag is None: for tag in rp.get_tags(): ui.print_(tag) else: - try: - citekey = rp.ref2citekey(referenceOrTag) - p = rp.get_paper(citekey) + if rp.databroker.exists(citekeyOrTag): + p = rp.pull_paper(citekeyOrTag) if tags is None: ui.print_(' '.join(p.tags)) else: @@ -90,15 +88,15 @@ def command(args): p.add_tag(tag) for tag in remove_tags: p.remove_tag(tag) - rp.save_paper(p) - except InvalidReference: - # case where we want to find paper with specific tags - included, excluded = _tag_groups(_parse_tags(referenceOrTag)) + rp.push_paper(p, overwrite=True) + else: + # case where we want to find papers with specific tags + included, excluded = _tag_groups(_parse_tags(citekeyOrTag)) papers_list = [] for n, p in enumerate(rp.all_papers()): if (p.tags.issuperset(included) and len(p.tags.intersection(excluded)) == 0): papers_list.append((p, n)) - ui.print_('\n'.join(helpers.paper_oneliner(p, n) + ui.print_('\n'.join(pretty.paper_oneliner(p, n) for p, n in papers_list)) diff --git a/papers/commands/update_cmd.py b/papers/commands/update_cmd.py index 312cb63..e693090 100644 --- a/papers/commands/update_cmd.py +++ b/papers/commands/update_cmd.py @@ -44,7 +44,6 @@ def command(args): if repo_version == 2: # update config - print 'bla' cfg_update = [('papers-directory', 'papers_dir'), ('open-cmd', 'open_cmd'), ('edit-cmd', 'edit_cmd'), diff --git a/papers/papers_cmd.py b/papers/papers_cmd.py index 7ab156b..7e5f94d 100644 --- a/papers/papers_cmd.py +++ b/papers/papers_cmd.py @@ -19,10 +19,10 @@ CORE_CMDS = collections.OrderedDict([ ('open', commands.open_cmd), ('websearch', commands.websearch_cmd), ('remove', commands.remove_cmd), + ('tag', commands.tag_cmd), # ('import', commands.import_cmd), # ('export', commands.export_cmd), # ('edit', commands.edit_cmd), - # ('tag', commands.tag_cmd), # ('attach', commands.attach_cmd), # ('update', commands.update_cmd), ])