"label" renamed as "tag" in the metadata file (and everywhere else).
Use the update command to update your metadata files. Tags is now a property of the Paper class, so one can use : print(p.tags) p.tags = ['math', 'romance']
This commit is contained in:
parent
4e6b062a64
commit
d30d5f32c4
1
TODO
1
TODO
@ -1,7 +1,6 @@
|
||||
TODO list
|
||||
=========
|
||||
- manage cross-references
|
||||
+ labels
|
||||
- find (authors) duplicates
|
||||
+ remove command
|
||||
- stats command
|
||||
|
@ -45,7 +45,7 @@ def command(config, ui, bibfile, docfile, label, copy):
|
||||
else:
|
||||
p = Paper.load(bibfile)
|
||||
if label is not None:
|
||||
p.metadata['labels'] = label.split()
|
||||
p.tags = set(label.split())
|
||||
# Check if another doc file is specified in bibtex
|
||||
docfile2 = extract_doc_path_from_bibdata(p, ui)
|
||||
if docfile is None:
|
||||
|
@ -9,7 +9,7 @@ def parser(subparsers, config):
|
||||
default=False, dest='citekeys',
|
||||
help='Only returns citekeys of matching papers.')
|
||||
parser.add_argument('query', nargs='*',
|
||||
help='Paper query (e.g. "year: 2000" or "labels: math")')
|
||||
help='Paper query (e.g. "year: 2000" or "tags: math")')
|
||||
return parser
|
||||
|
||||
|
||||
@ -23,12 +23,12 @@ def command(config, ui, citekeys, query):
|
||||
paper_strings = []
|
||||
for n, p in papers:
|
||||
bibdesc = pretty.bib_oneliner(p.bibentry)
|
||||
paper_strings.append((u'{num:d}: [{citekey}] {descr} {labels}'.format(
|
||||
paper_strings.append((u'{num:d}: [{citekey}] {descr} {tags}'.format(
|
||||
num=int(n),
|
||||
citekey=color.dye(p.citekey, color.purple),
|
||||
descr=bibdesc,
|
||||
labels=color.dye(' '.join(p.metadata.get('labels', [])),
|
||||
color.purple, bold=True),
|
||||
tags=color.dye(' '.join(p.tags),
|
||||
color.purple, bold=True),
|
||||
)).encode('utf-8'))
|
||||
ui.print_('\n'.join(paper_strings))
|
||||
|
||||
@ -45,8 +45,8 @@ def test_paper(query_string, p):
|
||||
field = tmp[0]
|
||||
value = tmp[1]
|
||||
|
||||
if field in ['labels', 'l', 'tags', 't']:
|
||||
if value not in p.metadata['labels']:
|
||||
if field in ['tags', 't']:
|
||||
if value not in p.tags:
|
||||
return False
|
||||
elif field in ['author', 'authors', 'a']: # that is the very ugly
|
||||
if not 'author' in p.bibentry.persons:
|
||||
|
@ -9,5 +9,5 @@ def parser(subparsers, config):
|
||||
def command(config, ui):
|
||||
"""List existing tags"""
|
||||
rp = Repository.from_directory(config)
|
||||
for tag in rp.get_labels():
|
||||
for tag in rp.get_tags():
|
||||
ui.print_(tag)
|
||||
|
@ -20,7 +20,7 @@ CITEKEY_EXCLUDE_RE = re.compile('[%s]'
|
||||
|
||||
BASE_META = {
|
||||
'external-document': None,
|
||||
'labels': [],
|
||||
'tags': [],
|
||||
'notes': [],
|
||||
}
|
||||
|
||||
@ -250,7 +250,30 @@ class Paper(object):
|
||||
return papers
|
||||
|
||||
|
||||
class PaperInRepo(Paper):
|
||||
# tags
|
||||
|
||||
@property
|
||||
def tags(self):
|
||||
return self.metadata.setdefault('tags', set())
|
||||
|
||||
@tags.setter
|
||||
def tags(self, value):
|
||||
if not hasattr(value, '__iter__'):
|
||||
raise ValueError, 'tags must be iterables'
|
||||
self.metadata['tags'] = set(value)
|
||||
|
||||
def add_tag(self, tag):
|
||||
self.tags.add(tag)
|
||||
|
||||
def remove_tag(self, tag):
|
||||
"""Remove a tag from a paper. Fails silently."""
|
||||
try:
|
||||
self.tags.pop(tag)
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
|
||||
class PaperInRepo(Paper): # TODO document why this class exists (fabien, 2013/06)
|
||||
|
||||
def __init__(self, repo, *args, **kwargs):
|
||||
Paper.__init__(self, *args, **kwargs)
|
||||
|
@ -198,11 +198,11 @@ class Repository(object):
|
||||
new_doc_file = os.path.join(doc_path, citekey + ext)
|
||||
shutil.copy(doc_file, new_doc_file)
|
||||
|
||||
def get_labels(self):
|
||||
labels = set()
|
||||
def get_tags(self):
|
||||
tags = set()
|
||||
for p in self.all_papers():
|
||||
labels = labels.union(p.metadata.get('labels', []))
|
||||
return labels
|
||||
tags = tags.union(p.tags)
|
||||
return tags
|
||||
|
||||
@classmethod
|
||||
def from_directory(cls, config, papersdir=None):
|
||||
|
@ -24,7 +24,7 @@ entries:
|
||||
META = """
|
||||
external-document: null
|
||||
notes: []
|
||||
labels: []
|
||||
tags: []
|
||||
"""
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user