added timestamps

main
Fabien Benureau 11 years ago
parent c4f296346a
commit 529e4e5950

@ -1,3 +1,5 @@
import datetime
from ..uis import get_ui
from ..configs import config
from .. import bibstruct
@ -23,25 +25,8 @@ def parser(subparsers):
return parser
def command(args):
"""
:param bibfile: bibtex file (in .bib, .bibml or .yaml format.
:param docfile: path (no url yet) to a pdf or ps file
"""
ui = get_ui()
bibfile = args.bibfile
docfile = args.docfile
tags = args.tags
citekey = args.copy
rp = repo.Repository(config())
# get bibfile
if bibfile is None:
cont = True
bibstr = ''
def bibdata_from_editor(rp):
again = True
try:
bibstr = content.editor_input(config().edit_cmd,
templates.add_bib,
@ -58,11 +43,32 @@ def command(args):
# REFACTOR Generate citykey
cont = False
except ValueError:
cont = ui.input_yn(
again = ui.input_yn(
question='Invalid bibfile. Edit again ?',
default='y')
if not cont:
if not again:
ui.exit(0)
return bibdata
def command(args):
"""
:param bibfile: bibtex file (in .bib, .bibml or .yaml format.
:param docfile: path (no url yet) to a pdf or ps file
"""
ui = get_ui()
bibfile = args.bibfile
docfile = args.docfile
tags = args.tags
citekey = args.copy
rp = repo.Repository(config())
# get bibfile
if bibfile is None:
bibdata = bibdata_from_editor(rp)
else:
bibdata_raw = content.get_content(bibfile)
bibdata = rp.databroker.verify(bibdata_raw)
@ -84,6 +90,7 @@ def command(args):
p.tags = set(tags.split(','))
p = paper.Paper(bibdata, citekey=citekey)
p.added = datetime.datetime.now()
# document file

@ -1,4 +1,5 @@
import os
import datetime
from pybtex.database import Entry, BibliographyData, FieldDict, Person
@ -58,6 +59,7 @@ def many_from_path(bibpath):
bibdata.entries[k] = b.entries[k]
papers[k] = Paper(bibdata, citekey=k)
p.added = datetime.datetime.now()
except ValueError, e:
papers[k] = e
return papers

@ -1,17 +1,21 @@
import copy
import collections
import datetime
from . import bibstruct
DEFAULT_META = collections.OrderedDict([('docfile', None), ('tags', set()), ('notes', [])])
DEFAULT_META = {'docfile': None, 'tags': set(), 'notes': []}
#DEFAULT_META = collections.OrderedDict([('docfile', None), ('tags', set()), ('added', )])
DEFAULT_META = {'docfile': None, 'tags': set(), 'added': None}
class Paper(object):
""" Paper class. The object is responsible for the integrity of its data
""" Paper class.
The object is not responsible of any disk i/o.
The object is not responsible of any disk I/O.
self.bibdata is a pybtex.database.BibliographyData object
self.metadata is a dictionary
The paper class provides methods to access the fields for its metadata
in a pythonic manner.
"""
def __init__(self, bibdata, citekey=None, metadata=None):
@ -42,6 +46,8 @@ class Paper(object):
metadata=copy.deepcopy(self.metadata),
bibdata=copy.deepcopy(self.bibdata))
# docpath
@property
def docpath(self):
return self.metadata.get('docfile', '')
@ -69,3 +75,13 @@ class Paper(object):
def remove_tag(self, tag):
"""Remove a tag from a paper if present."""
self.tags.discard(tag)
# added date
@property
def added(self):
datetime.datetime.strptime(self.metadata['added'], '%Y-%m-%d %H:%M:%S')
@added.setter
def added(self, value):
self.metadata['added'] = value.strftime('%Y-%m-%d %H:%M:%S')

Loading…
Cancel
Save