diff --git a/README.md b/README.md index 8fd94a6..4bdd13a 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ Should be almost working and usable now, although still to be considered as **ex * Open * working: all * Resync - * Testing + * working * Update * Testing diff --git a/backend.py b/backend.py index ce810a8..00dfde9 100644 --- a/backend.py +++ b/backend.py @@ -171,6 +171,8 @@ def deleteFile(filename): pass if found: bibtexRewrite(bibtex) + elif os.path.isfile(filename): + os.remove(filename) return found @@ -182,9 +184,10 @@ def diffFilesIndex(): * only file entry if file with missing bibtex entry """ files = tools.listDir(params.folder) + files = [ i for i in files if tools.getExtension(i) in ['.pdf', '.djvu'] ] try: with open(params.folder+'index.bib', 'r', encoding='utf-8') as fh: - index = BibTexParser(fh.read()) + index = BibTexParser(fh.read().encode('utf-8')) index_diff = index.get_entry_dict() except: tools.warning("Unable to open index file.") @@ -199,7 +202,7 @@ def diffFilesIndex(): for filename in files: index_diff[filename] = {'file': filename} - return index + return index.get_entry_dict() def getBibtex(entry, file_id='both'): diff --git a/main.py b/main.py index df94f44..876578d 100755 --- a/main.py +++ b/main.py @@ -272,56 +272,65 @@ def openFile(ident): def resync(): diff = backend.diffFilesIndex() - for entry in diff: + if diff is False: + return False + + for key in diff: + entry = diff[key] if entry['file'] == '': - print("Found entry in index without associated file.") - confirm = False - while not confirm: + print("\nFound entry in index without associated file: " + + entry['id']) + print("Title:\t"+entry['title']) + loop = True + while confirm: filename = tools.rawInput("File to import for this entry " + "(leave empty to delete the " + "entry)? ") if filename == '': break else: - confirm = True if 'doi' in entry.keys(): doi = fetcher.findDOI(filename) if doi is not False and doi != entry['doi']: - confirm = tools.rawInput("Found DOI does not " + + loop = tools.rawInput("Found DOI does not " + "match bibtex entry " + "DOI, continue anyway " + "? [y/N]") - confirm = (confirm.lower() == 'y') + loop = (loop.lower() != 'y') if 'Eprint' in entry.keys(): arxiv = fetcher.findArXivId(filename) if arxiv is not False and arxiv != entry['Eprint']: - confirm = tools.rawInput("Found arXiv id does " + + loop = tools.rawInput("Found arXiv id does " + "not match bibtex " + "entry arxiv id, " + "continue anyway ? [y/N]") - confirm = (confirm.lower() == 'y') - elif 'isbn' in entry.keys(): + loop = (loop.lower() != 'y') + if 'isbn' in entry.keys(): isbn = fetcher.findISBN(filename) if isbn is not False and isbn != entry['isbn']: - confirm = tools.rawInput("Found ISBN does not " + + loop = tools.rawInput("Found ISBN does not " + "match bibtex entry " + "ISBN, continue anyway " + "? [y/N]") - confirm = (confirm.lower() == 'y') + loop = (loop.lower() != 'y') continue if filename == '': backend.deleteId(entry['id']) + print("Deleted entry \""+entry['id']+"\".") else: new_name = backend.getNewName(filename, entry) try: shutil.copy2(filename, new_name) + print("Imported new file "+filename+" for entry " + + entry['id']+".") except IOError: new_name = False sys.exit("Unable to move file to library dir " + params.folder+".") backend.bibtexEdit(entry['id'], {'file': filename}) else: - print("Found file without any associated entry in index.") + print("Found file without any associated entry in index:") + print(entry['file']) action = '' while action.lower() not in ['import', 'delete']: action = tools.rawInput("What to do? [import / delete] ")