diff --git a/TODO b/TODO index 4956738..7f46939 100644 --- a/TODO +++ b/TODO @@ -5,10 +5,11 @@ TODO list - find (authors) duplicates + remove command - stats command -- add query support to list command (cf beets) ++- add query support to list command (cf beets) - FIX open on ubuntu -- edit bibtex on add ++- edit bibtex on add - option to add tag on add - paths in metadata must be relative - include package data in setup.py (see setup.py for more info) - in the script papers, why do we use a dictionary and not a list? it may be confusing, the key is not the subparser name. The subparser name is defined in the cmd files +- command to output a bibfile from several citekey or even a research results diff --git a/papers/commands/__init__.py b/papers/commands/__init__.py index 074dff3..8d013b5 100644 --- a/papers/commands/__init__.py +++ b/papers/commands/__init__.py @@ -10,3 +10,4 @@ import remove_cmd import websearch_cmd import devadd_cmd +import devlist_cmd diff --git a/papers/commands/devlist_cmd.py b/papers/commands/devlist_cmd.py new file mode 100644 index 0000000..2841877 --- /dev/null +++ b/papers/commands/devlist_cmd.py @@ -0,0 +1,53 @@ +from .. import pretty +from .. import repo + +#TODO how to have an empty case, i.e. cmd is not provided -> list all +#TODO add formatting option so that the output can be piped + +def parser(subparsers, config): + parser = subparsers.add_parser('devlist', help="list papers") + parser.add_argument('cmd', help='experimental option "year: 2000 or labels: bite"') + return parser + + + +def command(config, ui, cmd): + rp = repo.Repository.from_directory(config) + + tests = cmd.split() + + articles = [] + for n, p in enumerate(rp.all_papers()): + if test_paper(tests, p): + bibdesc = pretty.bib_oneliner(p.bibentry, color=ui.color) + articles.append((u'{num:d}: [{citekey}] {descr} {labels}'.format( + num=int(n), + citekey=ui.colored(rp.citekeys[n], 'purple'), + descr=bibdesc, + labels=ui.colored(''.join(p.metadata.get('labels', [])), 'purple'), + )).encode('utf-8')) + ui.print_('\n'.join(articles)) + +#TODO author is not implemented, should we do it by last name only or more complex +#TODO implement search by type of document +def test_paper(tests, p): + for test in tests: + tmp = test.split(':') + if tmp[0] == 'all': + return True + elif len(tmp) != 2: + raise ValueError('command not valid') + + field = tmp[0] + value = tmp[1] + + if field == 'labels': + if value not in p.metadata['labels']: + return False + else: + if p.bibentry.fields.has_key(field): + if value not in p.bibentry.fields[field]: + return False + else: + return False + return True diff --git a/papers/papers b/papers/papers index cc1fe38..d7c08a5 100755 --- a/papers/papers +++ b/papers/papers @@ -23,6 +23,7 @@ cmds = collections.OrderedDict([ ]) cmds.update(collections.OrderedDict([('devadd', commands.devadd_cmd)])) +cmds.update(collections.OrderedDict([('devlist', commands.devlist_cmd)])) config = configs.read_config() ui = UI(config)