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

View File

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

View File

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

View File

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