|
|
|
@ -4,6 +4,11 @@ import files
|
|
|
|
|
import color
|
|
|
|
|
import pretty
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NoDocumentFile(Exception):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Paper(object):
|
|
|
|
|
"""Paper class. The object is responsible for the integrity of its own data,
|
|
|
|
|
and for loading and writing it to disc.
|
|
|
|
@ -20,7 +25,7 @@ class Paper(object):
|
|
|
|
|
@classmethod
|
|
|
|
|
def from_bibpdffiles(cls, pdfpath, bibpath):
|
|
|
|
|
bib_data = cls.import_bibdata(bibpath)
|
|
|
|
|
name, meta = cls.create_meta(pdfpath, bib_data)
|
|
|
|
|
name, meta = cls.create_meta(bib_data, pdfpath=pdfpath)
|
|
|
|
|
p = Paper(name, bib_data = bib_data, metadata = meta)
|
|
|
|
|
|
|
|
|
|
return p
|
|
|
|
@ -33,6 +38,20 @@ class Paper(object):
|
|
|
|
|
self.citekey = citekey
|
|
|
|
|
self.number = number
|
|
|
|
|
|
|
|
|
|
def has_file(self):
|
|
|
|
|
"""Whether there exist a document file for this entry.
|
|
|
|
|
"""
|
|
|
|
|
return self.metadata['path'] is not None
|
|
|
|
|
|
|
|
|
|
def get_file_path(self):
|
|
|
|
|
if self.has_file():
|
|
|
|
|
return self.metadata['path']
|
|
|
|
|
else:
|
|
|
|
|
raise NoDocumentFile
|
|
|
|
|
|
|
|
|
|
def check_file(self):
|
|
|
|
|
return files.check_file(self.get_file_path())
|
|
|
|
|
|
|
|
|
|
def save_to_disc(self):
|
|
|
|
|
files.save_bibdata(self.bib_data, self.name)
|
|
|
|
|
files.save_meta(self.metadata, self.name)
|
|
|
|
@ -50,12 +69,19 @@ class Paper(object):
|
|
|
|
|
return bib_data
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def create_meta(cls, pdfpath, bib_data):
|
|
|
|
|
|
|
|
|
|
fullpdfpath = os.path.abspath(pdfpath)
|
|
|
|
|
files.check_file(fullpdfpath)
|
|
|
|
|
|
|
|
|
|
name, ext = files.name_from_path(pdfpath)
|
|
|
|
|
def create_meta(cls, bib_data, pdfpath=None):
|
|
|
|
|
|
|
|
|
|
if pdfpath is None:
|
|
|
|
|
name = bib_data.entries.keys()[0]
|
|
|
|
|
# TODO this introduces a bug and a security issue since the name
|
|
|
|
|
# is used to generate a file name that is written. It should be
|
|
|
|
|
# escaped here. (22/10/2012)
|
|
|
|
|
fullpdfpath, ext = None, None
|
|
|
|
|
else:
|
|
|
|
|
fullpdfpath = os.path.abspath(pdfpath)
|
|
|
|
|
files.check_file(fullpdfpath)
|
|
|
|
|
|
|
|
|
|
name, ext = files.name_from_path(pdfpath)
|
|
|
|
|
|
|
|
|
|
meta = {}
|
|
|
|
|
|
|
|
|
|