default bibfile formant is bibtex + fixed a bug in get_content
This commit is contained in:
parent
8d91545472
commit
2078876168
@ -69,7 +69,8 @@ def check_content(path):
|
|||||||
def get_content(path):
|
def get_content(path):
|
||||||
"""Will be useful when we need to get content from url"""
|
"""Will be useful when we need to get content from url"""
|
||||||
if content_type(path) == 'url':
|
if content_type(path) == 'url':
|
||||||
return urllib2.urlopen(path)
|
response = urllib2.urlopen(path)
|
||||||
|
return response.read()
|
||||||
else:
|
else:
|
||||||
return read_file(path)
|
return read_file(path)
|
||||||
|
|
||||||
|
@ -32,13 +32,13 @@ class EnDecoder(object):
|
|||||||
* encode_bibdata will try to recognize exceptions
|
* encode_bibdata will try to recognize exceptions
|
||||||
"""
|
"""
|
||||||
|
|
||||||
decode_fmt = {'bibyaml' : pybtex.database.input.bibyaml,
|
decode_fmt = {'bibtex' : pybtex.database.input.bibtex,
|
||||||
'bibtex' : pybtex.database.input.bibtex,
|
'bibyaml' : pybtex.database.input.bibyaml,
|
||||||
'bib' : pybtex.database.input.bibtex,
|
'bib' : pybtex.database.input.bibtex,
|
||||||
'bibtexml': pybtex.database.input.bibtexml}
|
'bibtexml': pybtex.database.input.bibtexml}
|
||||||
|
|
||||||
encode_fmt = {'bibyaml' : pybtex.database.output.bibyaml,
|
encode_fmt = {'bibtex' : pybtex.database.output.bibtex,
|
||||||
'bibtex' : pybtex.database.output.bibtex,
|
'bibyaml' : pybtex.database.output.bibyaml,
|
||||||
'bib' : pybtex.database.output.bibtex,
|
'bib' : pybtex.database.output.bibtex,
|
||||||
'bibtexml': pybtex.database.output.bibtexml}
|
'bibtexml': pybtex.database.output.bibtexml}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ class EnDecoder(object):
|
|||||||
def decode_metadata(self, metadata_raw):
|
def decode_metadata(self, metadata_raw):
|
||||||
return yaml.safe_load(metadata_raw)
|
return yaml.safe_load(metadata_raw)
|
||||||
|
|
||||||
def encode_bibdata(self, bibdata, fmt='bibyaml'):
|
def encode_bibdata(self, bibdata, fmt='bib'):
|
||||||
"""Encode bibdata """
|
"""Encode bibdata """
|
||||||
s = StringIO.StringIO()
|
s = StringIO.StringIO()
|
||||||
EnDecoder.encode_fmt[fmt].Writer().write_stream(bibdata, s)
|
EnDecoder.encode_fmt[fmt].Writer().write_stream(bibdata, s)
|
||||||
|
@ -44,7 +44,7 @@ class FileBroker(object):
|
|||||||
return read_file(filepath)
|
return read_file(filepath)
|
||||||
|
|
||||||
def pull_bibfile(self, citekey):
|
def pull_bibfile(self, citekey):
|
||||||
filepath = os.path.join(self.bibdir, citekey + '.bibyaml')
|
filepath = os.path.join(self.bibdir, citekey + '.bib')
|
||||||
return read_file(filepath)
|
return read_file(filepath)
|
||||||
|
|
||||||
def push_metafile(self, citekey, metadata):
|
def push_metafile(self, citekey, metadata):
|
||||||
@ -54,7 +54,7 @@ class FileBroker(object):
|
|||||||
|
|
||||||
def push_bibfile(self, citekey, bibdata):
|
def push_bibfile(self, citekey, bibdata):
|
||||||
"""Put content to disk. Will gladly override anything standing in its way."""
|
"""Put content to disk. Will gladly override anything standing in its way."""
|
||||||
filepath = os.path.join(self.bibdir, citekey + '.bibyaml')
|
filepath = os.path.join(self.bibdir, citekey + '.bib')
|
||||||
write_file(filepath, bibdata)
|
write_file(filepath, bibdata)
|
||||||
|
|
||||||
def push(self, citekey, metadata, bibdata):
|
def push(self, citekey, metadata, bibdata):
|
||||||
@ -66,17 +66,17 @@ class FileBroker(object):
|
|||||||
metafilepath = os.path.join(self.metadir, citekey + '.yaml')
|
metafilepath = os.path.join(self.metadir, citekey + '.yaml')
|
||||||
if check_file(metafilepath):
|
if check_file(metafilepath):
|
||||||
os.remove(metafilepath)
|
os.remove(metafilepath)
|
||||||
bibfilepath = os.path.join(self.bibdir, citekey + '.bibyaml')
|
bibfilepath = os.path.join(self.bibdir, citekey + '.bib')
|
||||||
if check_file(bibfilepath):
|
if check_file(bibfilepath):
|
||||||
os.remove(bibfilepath)
|
os.remove(bibfilepath)
|
||||||
|
|
||||||
def exists(self, citekey, both=True):
|
def exists(self, citekey, both=True):
|
||||||
if both:
|
if both:
|
||||||
return (check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False) and
|
return (check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False) and
|
||||||
check_file(os.path.join(self.bibdir, citekey + '.bibyaml'), fail=False))
|
check_file(os.path.join(self.bibdir, citekey + '.bib'), fail=False))
|
||||||
else:
|
else:
|
||||||
return (check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False) or
|
return (check_file(os.path.join(self.metadir, citekey + '.yaml'), fail=False) or
|
||||||
check_file(os.path.join(self.bibdir, citekey + '.bibyaml'), fail=False))
|
check_file(os.path.join(self.bibdir, citekey + '.bib'), fail=False))
|
||||||
|
|
||||||
|
|
||||||
def listing(self, filestats=True):
|
def listing(self, filestats=True):
|
||||||
@ -92,7 +92,7 @@ class FileBroker(object):
|
|||||||
|
|
||||||
bibfiles = []
|
bibfiles = []
|
||||||
for filename in os.listdir(self.bibdir):
|
for filename in os.listdir(self.bibdir):
|
||||||
citekey = filter_filename(filename, '.bibyaml')
|
citekey = filter_filename(filename, '.bib')
|
||||||
if citekey is not None:
|
if citekey is not None:
|
||||||
if filestats:
|
if filestats:
|
||||||
stats = os.stat(os.path.join(path, filename))
|
stats = os.stat(os.path.join(path, filename))
|
||||||
@ -163,7 +163,7 @@ class DocBroker(object):
|
|||||||
|
|
||||||
doc_content = get_content(full_source_path)
|
doc_content = get_content(full_source_path)
|
||||||
with open(full_target_path, 'wb') as f:
|
with open(full_target_path, 'wb') as f:
|
||||||
f.write(doc_content.read())
|
f.write(doc_content)
|
||||||
|
|
||||||
return target_path
|
return target_path
|
||||||
|
|
||||||
@ -193,5 +193,7 @@ class DocBroker(object):
|
|||||||
if not self.in_docsdir(docpath):
|
if not self.in_docsdir(docpath):
|
||||||
raise ValueError('cannot rename an external file ({}).'.format(docpath))
|
raise ValueError('cannot rename an external file ({}).'.format(docpath))
|
||||||
|
|
||||||
new_notepath = self.add_doc(new_citekey, docpath)
|
new_docpath = self.add_doc(new_citekey, docpath)
|
||||||
self.remove_doc(docpath)
|
self.remove_doc(docpath)
|
||||||
|
|
||||||
|
return new_docpath
|
Loading…
x
Reference in New Issue
Block a user