A first trial to add queries in list_cmd -> see devlist_cmd.
This commit is contained in:
parent
7b034b6d53
commit
a162f26723
5
TODO
5
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
|
||||
|
@ -10,3 +10,4 @@ import remove_cmd
|
||||
import websearch_cmd
|
||||
|
||||
import devadd_cmd
|
||||
import devlist_cmd
|
||||
|
53
papers/commands/devlist_cmd.py
Normal file
53
papers/commands/devlist_cmd.py
Normal file
@ -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
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user