Fix remaining bug

This commit is contained in:
Phyks 2015-06-08 20:02:09 +02:00
parent 0ba55402d2
commit e7edf7e5bf
2 changed files with 17 additions and 17 deletions

24
bmc.py
View File

@ -30,18 +30,19 @@ def checkBibtex(filename, bibtex_string):
try: try:
bibtex = bibtex[list(bibtex.keys())[0]] bibtex = bibtex[list(bibtex.keys())[0]]
# Check entries are correct # Check entries are correct
assert bibtex['title'] if "title" not in bibtex:
if bibtex['type'] == 'article': raise AssertionError
assert bibtex['authors'] if "authors" not in bibtex and "author" not in bibtex:
elif bibtex['type'] == 'book': raise AssertionError
assert bibtex['author'] if "year" not in bibtex:
assert bibtex['year'] raise AssertionError
# Print the bibtex and confirm # Print the bibtex and confirm
print(tools.parsed2Bibtex(bibtex)) print(tools.parsed2Bibtex(bibtex))
check = tools.rawInput("Is it correct? [Y/n] ") check = tools.rawInput("Is it correct? [Y/n] ")
except KeyboardInterrupt: except KeyboardInterrupt:
sys.exit() sys.exit()
except (IndexError, KeyError, AssertionError): except (IndexError, KeyError, AssertionError):
print("Missing author, year or title in bibtex.")
check = 'n' check = 'n'
try: try:
@ -207,16 +208,15 @@ def addFile(src, filetype, manual, autoconfirm, tag, rename=True):
new_name = default_rename new_name = default_rename
else: else:
new_name = rename new_name = rename
else:
new_name = src
bibtex['file'] = new_name
try: try:
shutil.copy2(src, new_name) shutil.copy2(src, new_name)
except shutil.Error: except shutil.Error:
new_name = False new_name = False
sys.exit("Unable to move file to library dir " + sys.exit("Unable to move file to library dir " +
config.get("folder")+".") config.get("folder")+".")
else:
new_name = src
bibtex['file'] = new_name
# Remove first page of IOP papers # Remove first page of IOP papers
try: try:
@ -482,7 +482,7 @@ if __name__ == '__main__':
help="Confirm all") help="Confirm all")
parser_import.add_argument('--tag', default='', help="Tag", parser_import.add_argument('--tag', default='', help="Tag",
type=commandline_arg) type=commandline_arg)
parser_download.add_argument('--in-place', default=False, parser_import.add_argument('--in-place', default=False,
dest="inplace", action='store_true', dest="inplace", action='store_true',
help="Leave the imported file in place",) help="Leave the imported file in place",)
parser_import.add_argument('file', nargs='+', parser_import.add_argument('file', nargs='+',
@ -579,7 +579,7 @@ if __name__ == '__main__':
skipped = [] skipped = []
for filename in list(set(args.file) - set(args.skip)): for filename in list(set(args.file) - set(args.skip)):
new_name = addFile(filename, args.type, args.manual, args.y, new_name = addFile(filename, args.type, args.manual, args.y,
args.tag, args.inplace) args.tag, not args.inplace)
if new_name is not False: if new_name is not False:
print(filename+" successfully imported as " + print(filename+" successfully imported as " +
new_name+".") new_name+".")

View File

@ -22,7 +22,7 @@ try:
from urllib.error import URLError from urllib.error import URLError
except ImportError: except ImportError:
# Fall back to Python 2's urllib2 # Fall back to Python 2's urllib2
from urllib2 import urlopen, Request, URLError from urllib2 import urlopen, Request
import arxiv2bib as arxiv_metadata import arxiv2bib as arxiv_metadata
import libbmc.tools as tools import libbmc.tools as tools
import bibtexparser import bibtexparser
@ -297,7 +297,7 @@ def doi2Bib(doi):
return '' return ''
except KeyError: except KeyError:
return '' return ''
except URLError: except:
tools.warning('Unable to contact remote server to get the bibtex ' + tools.warning('Unable to contact remote server to get the bibtex ' +
'entry for doi '+doi) 'entry for doi '+doi)
return '' return ''