Move file if filename edited in checkBibtex()

This commit is contained in:
Phyks 2014-05-07 22:13:03 +02:00
parent 73f3fe7778
commit 453a30f4ca

12
main.py
View File

@ -31,6 +31,7 @@ def checkBibtex(filename, bibtex):
bibtex_string = '' bibtex_string = ''
print(bibtex_string) print(bibtex_string)
check = tools.rawInput("Is it correct? [Y/n] ") check = tools.rawInput("Is it correct? [Y/n] ")
old_filename = bibtex['file']
while check.lower() == 'n': while check.lower() == 'n':
with tempfile.NamedTemporaryFile(suffix=".tmp") as tmpfile: with tempfile.NamedTemporaryFile(suffix=".tmp") as tmpfile:
@ -41,6 +42,11 @@ def checkBibtex(filename, bibtex):
customization=homogeneize_latex_encoding) customization=homogeneize_latex_encoding)
bibtex = bibtex.get_entry_dict() bibtex = bibtex.get_entry_dict()
if 'file' not in bibtex:
tools.warning("Invalid bibtex entry. No filename given.")
tools.rawInput("Press Enter to go back to editor.")
check = 'n'
else:
if len(bibtex) > 0: if len(bibtex) > 0:
bibtex_name = bibtex.keys()[0] bibtex_name = bibtex.keys()[0]
bibtex = bibtex[bibtex_name] bibtex = bibtex[bibtex_name]
@ -50,6 +56,12 @@ def checkBibtex(filename, bibtex):
print("\nThe bibtex entry for "+filename+" is:") print("\nThe bibtex entry for "+filename+" is:")
print(bibtex_string) print(bibtex_string)
check = tools.rawInput("Is it correct? [Y/n] ") check = tools.rawInput("Is it correct? [Y/n] ")
if old_filename != bibtex['file']:
try:
shutil.move(old_filename, bibtex['file'])
except:
tools.warning("Unable to move file "+old_filename+" to " +
bibtex['file']+". You should check it manually.")
return bibtex return bibtex