This commit is contained in:
Phyks 2014-12-03 12:54:24 +01:00
parent 485516db07
commit fbb158543b
4 changed files with 33 additions and 33 deletions

22
bmc.py
View File

@ -9,7 +9,7 @@ import shutil
import subprocess
import sys
import tempfile
from bibtexparser.bparser import BibTexParser
import bibtexparser
from codecs import open
from libbmc.config import Config
from libbmc import backend
@ -25,8 +25,8 @@ EDITOR = os.environ.get('EDITOR') if os.environ.get('EDITOR') else 'vim'
def checkBibtex(filename, bibtex_string):
print("The bibtex entry found for "+filename+" is:")
bibtex = BibTexParser(bibtex_string)
bibtex = bibtex.get_entry_dict()
bibtex = bibtexparser.loads(bibtex_string)
bibtex = bibtex.entries_dict
try:
bibtex = bibtex[list(bibtex.keys())[0]]
# Check entries are correct
@ -55,9 +55,9 @@ def checkBibtex(filename, bibtex_string):
tmpfile.flush()
subprocess.call([EDITOR, tmpfile.name])
tmpfile.seek(0)
bibtex = BibTexParser(tmpfile.read().decode('utf-8')+"\n")
bibtex = bibtexparser.loads(tmpfile.read().decode('utf-8')+"\n")
bibtex = bibtex.get_entry_dict()
bibtex = bibtex.entries_dict
try:
bibtex = bibtex[list(bibtex.keys())[0]]
except (IndexError, KeyError):
@ -176,8 +176,8 @@ def addFile(src, filetype, manual, autoconfirm, tag):
else:
bibtex = ''
bibtex = BibTexParser(bibtex)
bibtex = bibtex.get_entry_dict()
bibtex = bibtexparser.loads(bibtex)
bibtex = bibtex.entries_dict
if len(bibtex) > 0:
bibtex_name = list(bibtex.keys())[0]
bibtex = bibtex[bibtex_name]
@ -272,8 +272,8 @@ def editEntry(entry, file_id='both'):
try:
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
as fh:
index = BibTexParser(fh.read())
index = index.get_entry_dict()
index = bibtexparser.load(fh)
index = index.entries_dict
except (TypeError, IOError):
tools.warning("Unable to open index file.")
return False
@ -307,8 +307,8 @@ def openFile(ident):
try:
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
as fh:
bibtex = BibTexParser(fh.read())
bibtex = bibtex.get_entry_dict()
bibtex = bibtexparser.load(fh)
bibtex = bibtex.entries_dict
except (TypeError, IOError):
tools.warning("Unable to open index file.")
return False

View File

@ -14,7 +14,7 @@ import os
import re
import libbmc.tools as tools
import libbmc.fetcher as fetcher
from bibtexparser.bparser import BibTexParser
import bibtexparser
from libbmc.config import Config
from codecs import open
@ -103,8 +103,8 @@ def bibtexEdit(ident, modifs):
try:
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
as fh:
bibtex = BibTexParser(fh.read())
bibtex = bibtex.get_entry_dict()
bibtex = bibtexparser.load(fh)
bibtex = bibtex.entries_dict
except (IOError, TypeError):
tools.warning("Unable to open index file.")
return False
@ -136,8 +136,8 @@ def deleteId(ident):
try:
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
as fh:
bibtex = BibTexParser(fh.read())
bibtex = bibtex.get_entry_dict()
bibtex = bibtexparser.load(fh)
bibtex = bibtex.entries_dict
except (IOError, TypeError):
tools.warning("Unable to open index file.")
return False
@ -172,8 +172,8 @@ def deleteFile(filename):
try:
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
as fh:
bibtex = BibTexParser(fh.read())
bibtex = bibtex.get_entry_dict()
bibtex = bibtexparser.load(fh)
bibtex = bibtex.entries_dict
except (TypeError, IOError):
tools.warning("Unable to open index file.")
return False
@ -222,8 +222,8 @@ def diffFilesIndex():
try:
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
as fh:
index = BibTexParser(fh.read())
index_diff = index.get_entry_dict()
index = bibtexparser.load(fh)
index_diff = index.entries_dict
except (TypeError, IOError):
tools.warning("Unable to open index file.")
return False
@ -237,7 +237,7 @@ def diffFilesIndex():
for filename in files:
index_diff[filename] = {'file': filename}
return index.get_entry_dict()
return index.entries_dict
def getBibtex(entry, file_id='both', clean=False):
@ -250,8 +250,8 @@ def getBibtex(entry, file_id='both', clean=False):
try:
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
as fh:
bibtex = BibTexParser(fh.read())
bibtex = bibtex.get_entry_dict()
bibtex = bibtexparser.load(fh)
bibtex = bibtex.entries_dict
except (TypeError, IOError):
tools.warning("Unable to open index file.")
return False
@ -282,8 +282,8 @@ def getEntries():
try:
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
as fh:
bibtex = BibTexParser(fh.read())
bibtex = bibtex.get_entry_dict()
bibtex = bibtexparser.load(fh)
bibtex = bibtex.entries_dict
except (TypeError, IOError):
tools.warning("Unable to open index file.")
return False
@ -313,8 +313,8 @@ def updateArXiv(entry):
continue
ids.add(bibtex['eprint'])
last_bibtex = BibTexParser(fetcher.arXiv2Bib(arxiv_id_no_v))
last_bibtex = last_bibtex.get_entry_dict()
last_bibtex = bibtexparser.loads(fetcher.arXiv2Bib(arxiv_id_no_v))
last_bibtex = last_bibtex.entries_dict
last_bibtex = last_bibtex[list(last_bibtex.keys())[0]]
if last_bibtex['eprint'] not in ids:

View File

@ -25,7 +25,7 @@ except ImportError:
from urllib2 import urlopen, Request, URLError
import arxiv2bib as arxiv_metadata
import libbmc.tools as tools
from bibtexparser.bparser import BibTexParser
import bibtexparser
from libbmc.config import Config
@ -313,8 +313,8 @@ def arXiv2Bib(arxiv):
if isinstance(bib, arxiv_metadata.ReferenceErrorInfo):
continue
else:
fetched_bibtex = BibTexParser(bib.bibtex())
fetched_bibtex = fetched_bibtex.get_entry_dict()
fetched_bibtex = bibtexparser.loads(bib.bibtex())
fetched_bibtex = fetched_bibtex.entries_dict
fetched_bibtex = fetched_bibtex[list(fetched_bibtex.keys())[0]]
try:
del(fetched_bibtex['file'])

View File

@ -11,7 +11,7 @@
from __future__ import unicode_literals
import unittest
from libbmc.backend import *
from bibtexparser.bparser import BibTexParser
import bibtexparser
import os
import shutil
import tempfile
@ -43,7 +43,7 @@ mass density wave should occur.},
Lattice},
year={2013},
}""" % config.get("folder")
self.bibtex_article = BibTexParser(self.bibtex_article_string).get_entry_dict()
self.bibtex_article = bibtexparser.loads(self.bibtex_article_string).entries_dict
self.bibtex_article = self.bibtex_article[list(self.bibtex_article.keys())[0]]
self.bibtex_book_string = """
@ -55,7 +55,7 @@ Lattice},
year={2008},
}
"""
self.bibtex_book = BibTexParser(self.bibtex_book_string).get_entry_dict()
self.bibtex_book = bibtexparser.loads(self.bibtex_book_string).entries_dict
self.bibtex_book = self.bibtex_book[list(self.bibtex_book.keys())[0]]
def test_getNewName_article(self):