Further fixes for python3

This commit is contained in:
Phyks 2014-08-03 12:38:40 +02:00
parent 07d8d43a7c
commit bb297adfc5
6 changed files with 14 additions and 11 deletions

View File

@ -9,7 +9,7 @@
# Phyks
# -----------------------------------------------------------------------------
from __future__ import unicode_literals
import os
import re
import libbmc.tools as tools
@ -136,7 +136,7 @@ def deleteId(ident):
try:
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
as fh:
bibtex = BibTexParser(fh.read().decode('utf-8'))
bibtex = BibTexParser(fh.read())
bibtex = bibtex.get_entry_dict()
except (IOError, TypeError):
tools.warning("Unable to open index file.")
@ -172,7 +172,7 @@ def deleteFile(filename):
try:
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
as fh:
bibtex = BibTexParser(fh.read().decode('utf-8'))
bibtex = BibTexParser(fh.read())
bibtex = bibtex.get_entry_dict()
except (TypeError, IOError):
tools.warning("Unable to open index file.")
@ -315,7 +315,7 @@ def updateArXiv(entry):
last_bibtex = BibTexParser(fetcher.arXiv2Bib(arxiv_id_no_v))
last_bibtex = last_bibtex.get_entry_dict()
last_bibtex = last_bibtex[last_bibtex.keys()[0]]
last_bibtex = last_bibtex[list(last_bibtex.keys())[0]]
if last_bibtex['eprint'] not in ids:
return last_bibtex

View File

@ -1,3 +1,4 @@
from __future__ import unicode_literals
import os
import errno
import imp

View File

@ -8,6 +8,7 @@
# <del>beer</del> soda in return.
# Phyks
# -----------------------------------------------------------------------------
from __future__ import unicode_literals
import unittest
from libbmc.backend import *
from bibtexparser.bparser import BibTexParser
@ -43,7 +44,7 @@ Lattice},
year={2013},
}""" % config.get("folder")
self.bibtex_article = BibTexParser(self.bibtex_article_string).get_entry_dict()
self.bibtex_article = self.bibtex_article[self.bibtex_article.keys()[0]]
self.bibtex_article = self.bibtex_article[list(self.bibtex_article.keys())[0]]
self.bibtex_book_string = """
@book{9780521846516,
@ -55,7 +56,7 @@ Lattice},
}
"""
self.bibtex_book = BibTexParser(self.bibtex_book_string).get_entry_dict()
self.bibtex_book = self.bibtex_book[self.bibtex_book.keys()[0]]
self.bibtex_book = self.bibtex_book[list(self.bibtex_book.keys())[0]]
def test_getNewName_article(self):
self.assertEqual(getNewName("test.pdf", self.bibtex_article),
@ -99,7 +100,7 @@ Lattice},
open(config.get("folder")+'test.pdf', 'w').close()
deleteId(self.bibtex_article['id'])
with open(config.get("folder")+'index.bib', 'r') as fh:
self.assertEquals(fh.read().strip(), "")
self.assertEqual(fh.read().strip(), "")
self.assertFalse(os.path.isfile(config.get("folder")+'test.pdf'))
def test_deleteFile(self):
@ -108,7 +109,7 @@ Lattice},
open(config.get("folder")+'test.pdf', 'w').close()
deleteFile(self.bibtex_article['file'])
with open(config.get("folder")+'index.bib', 'r') as fh:
self.assertEquals(fh.read().strip(), "")
self.assertEqual(fh.read().strip(), "")
self.assertFalse(os.path.isfile(config.get("folder")+'test.pdf'))
def test_diffFilesIndex(self):

View File

@ -8,6 +8,7 @@
# <del>beer</del> soda in return.
# Phyks
# -----------------------------------------------------------------------------
from __future__ import unicode_literals
import unittest
import json
import os

View File

@ -8,6 +8,7 @@
# <del>beer</del> soda in return.
# Phyks
# -----------------------------------------------------------------------------
from __future__ import unicode_literals
import unittest
from libbmc.tools import *

View File

@ -10,7 +10,7 @@
# -----------------------------------------------------------------------------
from __future__ import print_function
from __future__ import print_function, unicode_literals
import os
import re
import sys
@ -72,8 +72,7 @@ def rawInput(string):
def warning(*objs):
"""Write warnings to stderr"""
printed = [i.encode('utf-8') for i in objs]
print("WARNING: ", *printed, file=sys.stderr)
print("WARNING: ", *objs, file=sys.stderr)
def listDir(path):