parent
7b034b6d53
commit
a162f26723
@ -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
|
Loading…
Reference in new issue