tag cmd
This commit is contained in:
parent
c6d7300ae3
commit
24df1b36ae
@ -4,9 +4,9 @@ import list_cmd
|
|||||||
import open_cmd
|
import open_cmd
|
||||||
import websearch_cmd
|
import websearch_cmd
|
||||||
import remove_cmd
|
import remove_cmd
|
||||||
|
import tag_cmd
|
||||||
# import import_cmd
|
# import import_cmd
|
||||||
# import export_cmd
|
# import export_cmd
|
||||||
# import edit_cmd
|
# import edit_cmd
|
||||||
# import tag_cmd
|
|
||||||
# import attach_cmd
|
# import attach_cmd
|
||||||
# import update_cmd
|
# import update_cmd
|
||||||
|
@ -18,17 +18,16 @@ The different use cases are :
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from ..repo import Repository, InvalidReference
|
from ..repo import Repository, InvalidReference
|
||||||
from . import helpers
|
|
||||||
from ..configs import config
|
from ..configs import config
|
||||||
from ..uis import get_ui
|
from ..uis import get_ui
|
||||||
|
from .. import pretty
|
||||||
|
|
||||||
def parser(subparsers):
|
def parser(subparsers):
|
||||||
parser = subparsers.add_parser('tag', help="add, remove and show tags")
|
parser = subparsers.add_parser('tag', help="add, remove and show tags")
|
||||||
parser.add_argument('referenceOrTag', nargs='?', default = None,
|
parser.add_argument('citekeyOrTag', nargs='?', default = None,
|
||||||
help='reference to the paper (citekey or number), or '
|
help='citekey or tag.')
|
||||||
'tag.')
|
|
||||||
parser.add_argument('tags', nargs='?', default = None,
|
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 +.')
|
'then a list of tags separated by a +.')
|
||||||
# TODO find a way to display clear help for multiple command semantics,
|
# TODO find a way to display clear help for multiple command semantics,
|
||||||
# indistinguisable for argparse. (fabien, 201306)
|
# indistinguisable for argparse. (fabien, 201306)
|
||||||
@ -69,19 +68,18 @@ def command(args):
|
|||||||
"""Add, remove and show tags"""
|
"""Add, remove and show tags"""
|
||||||
|
|
||||||
ui = get_ui()
|
ui = get_ui()
|
||||||
referenceOrTag = args.referenceOrTag
|
citekeyOrTag = args.citekeyOrTag
|
||||||
tags = args.tags
|
tags = args.tags
|
||||||
|
|
||||||
|
|
||||||
rp = Repository(config())
|
rp = Repository(config())
|
||||||
|
|
||||||
if referenceOrTag is None:
|
if citekeyOrTag is None:
|
||||||
for tag in rp.get_tags():
|
for tag in rp.get_tags():
|
||||||
ui.print_(tag)
|
ui.print_(tag)
|
||||||
else:
|
else:
|
||||||
try:
|
if rp.databroker.exists(citekeyOrTag):
|
||||||
citekey = rp.ref2citekey(referenceOrTag)
|
p = rp.pull_paper(citekeyOrTag)
|
||||||
p = rp.get_paper(citekey)
|
|
||||||
if tags is None:
|
if tags is None:
|
||||||
ui.print_(' '.join(p.tags))
|
ui.print_(' '.join(p.tags))
|
||||||
else:
|
else:
|
||||||
@ -90,15 +88,15 @@ def command(args):
|
|||||||
p.add_tag(tag)
|
p.add_tag(tag)
|
||||||
for tag in remove_tags:
|
for tag in remove_tags:
|
||||||
p.remove_tag(tag)
|
p.remove_tag(tag)
|
||||||
rp.save_paper(p)
|
rp.push_paper(p, overwrite=True)
|
||||||
except InvalidReference:
|
else:
|
||||||
# case where we want to find paper with specific tags
|
# case where we want to find papers with specific tags
|
||||||
included, excluded = _tag_groups(_parse_tags(referenceOrTag))
|
included, excluded = _tag_groups(_parse_tags(citekeyOrTag))
|
||||||
papers_list = []
|
papers_list = []
|
||||||
for n, p in enumerate(rp.all_papers()):
|
for n, p in enumerate(rp.all_papers()):
|
||||||
if (p.tags.issuperset(included) and
|
if (p.tags.issuperset(included) and
|
||||||
len(p.tags.intersection(excluded)) == 0):
|
len(p.tags.intersection(excluded)) == 0):
|
||||||
papers_list.append((p, n))
|
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))
|
for p, n in papers_list))
|
||||||
|
@ -44,7 +44,6 @@ def command(args):
|
|||||||
|
|
||||||
if repo_version == 2:
|
if repo_version == 2:
|
||||||
# update config
|
# update config
|
||||||
print 'bla'
|
|
||||||
cfg_update = [('papers-directory', 'papers_dir'),
|
cfg_update = [('papers-directory', 'papers_dir'),
|
||||||
('open-cmd', 'open_cmd'),
|
('open-cmd', 'open_cmd'),
|
||||||
('edit-cmd', 'edit_cmd'),
|
('edit-cmd', 'edit_cmd'),
|
||||||
|
@ -19,10 +19,10 @@ CORE_CMDS = collections.OrderedDict([
|
|||||||
('open', commands.open_cmd),
|
('open', commands.open_cmd),
|
||||||
('websearch', commands.websearch_cmd),
|
('websearch', commands.websearch_cmd),
|
||||||
('remove', commands.remove_cmd),
|
('remove', commands.remove_cmd),
|
||||||
|
('tag', commands.tag_cmd),
|
||||||
# ('import', commands.import_cmd),
|
# ('import', commands.import_cmd),
|
||||||
# ('export', commands.export_cmd),
|
# ('export', commands.export_cmd),
|
||||||
# ('edit', commands.edit_cmd),
|
# ('edit', commands.edit_cmd),
|
||||||
# ('tag', commands.tag_cmd),
|
|
||||||
# ('attach', commands.attach_cmd),
|
# ('attach', commands.attach_cmd),
|
||||||
# ('update', commands.update_cmd),
|
# ('update', commands.update_cmd),
|
||||||
])
|
])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user