"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
|
TODO list
|
||||||
=========
|
=========
|
||||||
- manage cross-references
|
- manage cross-references
|
||||||
+ labels
|
|
||||||
- find (authors) duplicates
|
- find (authors) duplicates
|
||||||
+ remove command
|
+ remove command
|
||||||
- stats command
|
- stats command
|
||||||
|
@ -45,7 +45,7 @@ def command(config, ui, bibfile, docfile, label, copy):
|
|||||||
else:
|
else:
|
||||||
p = Paper.load(bibfile)
|
p = Paper.load(bibfile)
|
||||||
if label is not None:
|
if label is not None:
|
||||||
p.metadata['labels'] = label.split()
|
p.tags = set(label.split())
|
||||||
# Check if another doc file is specified in bibtex
|
# Check if another doc file is specified in bibtex
|
||||||
docfile2 = extract_doc_path_from_bibdata(p, ui)
|
docfile2 = extract_doc_path_from_bibdata(p, ui)
|
||||||
if docfile is None:
|
if docfile is None:
|
||||||
|
@ -9,7 +9,7 @@ def parser(subparsers, config):
|
|||||||
default=False, dest='citekeys',
|
default=False, dest='citekeys',
|
||||||
help='Only returns citekeys of matching papers.')
|
help='Only returns citekeys of matching papers.')
|
||||||
parser.add_argument('query', nargs='*',
|
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
|
return parser
|
||||||
|
|
||||||
|
|
||||||
@ -23,12 +23,12 @@ def command(config, ui, citekeys, query):
|
|||||||
paper_strings = []
|
paper_strings = []
|
||||||
for n, p in papers:
|
for n, p in papers:
|
||||||
bibdesc = pretty.bib_oneliner(p.bibentry)
|
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),
|
num=int(n),
|
||||||
citekey=color.dye(p.citekey, color.purple),
|
citekey=color.dye(p.citekey, color.purple),
|
||||||
descr=bibdesc,
|
descr=bibdesc,
|
||||||
labels=color.dye(' '.join(p.metadata.get('labels', [])),
|
tags=color.dye(' '.join(p.tags),
|
||||||
color.purple, bold=True),
|
color.purple, bold=True),
|
||||||
)).encode('utf-8'))
|
)).encode('utf-8'))
|
||||||
ui.print_('\n'.join(paper_strings))
|
ui.print_('\n'.join(paper_strings))
|
||||||
|
|
||||||
@ -45,8 +45,8 @@ def test_paper(query_string, p):
|
|||||||
field = tmp[0]
|
field = tmp[0]
|
||||||
value = tmp[1]
|
value = tmp[1]
|
||||||
|
|
||||||
if field in ['labels', 'l', 'tags', 't']:
|
if field in ['tags', 't']:
|
||||||
if value not in p.metadata['labels']:
|
if value not in p.tags:
|
||||||
return False
|
return False
|
||||||
elif field in ['author', 'authors', 'a']: # that is the very ugly
|
elif field in ['author', 'authors', 'a']: # that is the very ugly
|
||||||
if not 'author' in p.bibentry.persons:
|
if not 'author' in p.bibentry.persons:
|
||||||
|
@ -9,5 +9,5 @@ def parser(subparsers, config):
|
|||||||
def command(config, ui):
|
def command(config, ui):
|
||||||
"""List existing tags"""
|
"""List existing tags"""
|
||||||
rp = Repository.from_directory(config)
|
rp = Repository.from_directory(config)
|
||||||
for tag in rp.get_labels():
|
for tag in rp.get_tags():
|
||||||
ui.print_(tag)
|
ui.print_(tag)
|
||||||
|
@ -20,7 +20,7 @@ CITEKEY_EXCLUDE_RE = re.compile('[%s]'
|
|||||||
|
|
||||||
BASE_META = {
|
BASE_META = {
|
||||||
'external-document': None,
|
'external-document': None,
|
||||||
'labels': [],
|
'tags': [],
|
||||||
'notes': [],
|
'notes': [],
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,7 +250,30 @@ class Paper(object):
|
|||||||
return papers
|
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):
|
def __init__(self, repo, *args, **kwargs):
|
||||||
Paper.__init__(self, *args, **kwargs)
|
Paper.__init__(self, *args, **kwargs)
|
||||||
|
@ -198,11 +198,11 @@ class Repository(object):
|
|||||||
new_doc_file = os.path.join(doc_path, citekey + ext)
|
new_doc_file = os.path.join(doc_path, citekey + ext)
|
||||||
shutil.copy(doc_file, new_doc_file)
|
shutil.copy(doc_file, new_doc_file)
|
||||||
|
|
||||||
def get_labels(self):
|
def get_tags(self):
|
||||||
labels = set()
|
tags = set()
|
||||||
for p in self.all_papers():
|
for p in self.all_papers():
|
||||||
labels = labels.union(p.metadata.get('labels', []))
|
tags = tags.union(p.tags)
|
||||||
return labels
|
return tags
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_directory(cls, config, papersdir=None):
|
def from_directory(cls, config, papersdir=None):
|
||||||
|
@ -24,7 +24,7 @@ entries:
|
|||||||
META = """
|
META = """
|
||||||
external-document: null
|
external-document: null
|
||||||
notes: []
|
notes: []
|
||||||
labels: []
|
tags: []
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user