Merges devlist into list.
This commit is contained in:
parent
245ab0ea4d
commit
2e52c33851
@ -8,5 +8,3 @@ import open_cmd
|
||||
import edit_cmd
|
||||
import remove_cmd
|
||||
import websearch_cmd
|
||||
|
||||
import devlist_cmd
|
||||
|
@ -1,48 +0,0 @@
|
||||
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', nargs='*', help='experimental option "year: 2000 or labels: bite"')
|
||||
return parser
|
||||
|
||||
|
||||
def command(config, ui, cmd):
|
||||
rp = repo.Repository.from_directory(config)
|
||||
|
||||
articles = []
|
||||
for n, p in enumerate(rp.all_papers()):
|
||||
if test_paper(cmd, 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 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
|
@ -3,19 +3,46 @@ from .. import repo
|
||||
|
||||
|
||||
def parser(subparsers, config):
|
||||
parser = subparsers.add_parser('list', help="list all papers")
|
||||
parser = subparsers.add_parser('devlist', help="list papers")
|
||||
parser.add_argument('cmd', nargs='*', help='experimental option "year: 2000 or labels: bite"')
|
||||
return parser
|
||||
|
||||
|
||||
def command(config, ui):
|
||||
def command(config, ui, cmd):
|
||||
rp = repo.Repository.from_directory(config)
|
||||
articles = []
|
||||
for n, p in enumerate(rp.all_papers()):
|
||||
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'))
|
||||
if test_paper(cmd, 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 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 field in p.bibentry.fields:
|
||||
if value not in p.bibentry.fields[field]:
|
||||
return False
|
||||
else:
|
||||
return False
|
||||
return True
|
||||
|
@ -22,8 +22,6 @@ cmds = collections.OrderedDict([
|
||||
('websearch', commands.websearch_cmd)
|
||||
])
|
||||
|
||||
cmds.update(collections.OrderedDict([('devlist', commands.devlist_cmd)]))
|
||||
|
||||
config = configs.read_config()
|
||||
ui = UI(config)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user