コード例 #1
0
ファイル: bmc.py プロジェクト: drvinceknight/BMC
def update(entry):
    update = backend.updateArXiv(entry)
    if update is not False:
        print("New version found for "+entry)
        print("\t Title: "+update['title'])
        confirm = tools.rawInput("Download it ? [Y/n] ")
        if confirm.lower() == 'n':
            return
        new_name = downloadFile('http://arxiv.org/pdf/'+update['eprint'],
                                'article', False)
        if new_name is not False:
            print(update['eprint']+" successfully imported as "+new_name)
        else:
            tools.warning("An error occurred while downloading "+url)
        confirm = tools.rawInput("Delete previous version ? [y/N] ")
        if confirm.lower() == 'y':
            if not backend.deleteId(entry):
                if not backend.deleteFile(entry):
                    tools.warning("Unable to remove previous version.")
                    return
            print("Previous version successfully deleted.")
コード例 #2
0
def update(entry):
    update = backend.updateArXiv(entry)
    if update is not False:
        print("New version found for " + entry)
        print("\t Title: " + update['title'])
        confirm = tools.rawInput("Download it ? [Y/n] ")
        if confirm.lower() == 'n':
            return
        new_name = downloadFile('http://arxiv.org/pdf/' + update['eprint'],
                                'article', False)
        if new_name is not False:
            print(update['eprint'] + " successfully imported as " + new_name)
        else:
            tools.warning("An error occurred while downloading " + url)
        confirm = tools.rawInput("Delete previous version ? [y/N] ")
        if confirm.lower() == 'y':
            if not backend.deleteId(entry):
                if not backend.deleteFile(entry):
                    tools.warning("Unable to remove previous version.")
                    return
            print("Previous version successfully deleted.")
コード例 #3
0
def resync():
    diff = backend.diffFilesIndex()

    if diff is False:
        return False

    for key in diff:
        entry = diff[key]
        if entry['file'] == '':
            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:
                    if 'doi' in list(entry.keys()):
                        doi = fetcher.findArticleID(filename, only=["DOI"])
                        if doi is not False and doi != entry['doi']:
                            loop = tools.rawInput("Found DOI does not " +
                                                  "match bibtex entry " +
                                                  "DOI, continue anyway " +
                                                  "? [y/N]")
                            loop = (loop.lower() != 'y')
                    if 'Eprint' in list(entry.keys()):
                        arxiv = fetcher.findArticleID(filename, only=["arXiv"])
                        if arxiv is not False and arxiv != entry['Eprint']:
                            loop = tools.rawInput("Found arXiv id does " +
                                                  "not match bibtex " +
                                                  "entry arxiv id, " +
                                                  "continue anyway ? [y/N]")
                            loop = (loop.lower() != 'y')
                    if 'isbn' in list(entry.keys()):
                        isbn = fetcher.findISBN(filename)
                        if isbn is not False and isbn != entry['isbn']:
                            loop = tools.rawInput("Found ISBN does not " +
                                                  "match bibtex entry " +
                                                  "ISBN, continue anyway " +
                                                  "? [y/N]")
                            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 shutil.Error:
                    new_name = False
                    sys.exit("Unable to move file to library dir " +
                             config.get("folder") + ".")
                backend.bibtexEdit(entry['id'], {'file': filename})
        else:
            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] ")
                action = action.lower()
            if action == 'import':
                tmp = tempfile.NamedTemporaryFile()
                shutil.copy(entry['file'], tmp.name)
                filetype = tools.getExtension(entry['file'])
                try:
                    os.remove(entry['file'])
                except OSError:
                    tools.warning("Unable to delete file " + entry['file'])
                if not addFile(tmp.name, filetype):
                    tools.warning("Unable to reimport file " + entry['file'])
                tmp.close()
            else:
                backend.deleteFile(entry['file'])
                print(entry['file'] + " removed from disk and " + "index.")
    # Check for empty tag dirs
    for i in os.listdir(config.get("folder")):
        if os.path.isdir(i) and not os.listdir(config.get("folder") + i):
            try:
                os.rmdir(config.get("folder") + i)
            except OSError:
                tools.warning("Found empty tag dir " + config.get("folder") +
                              i + " but could not delete it.")
コード例 #4
0
                for i in skipped:
                    print(i)
            sys.exit()

        elif args.func == 'delete':
            skipped = []
            for filename in list(set(args.entries) - set(args.skip)):
                if not args.force:
                    confirm = tools.rawInput("Are you sure you want to " +
                                             "delete " + filename +
                                             " ? [y/N] ")
                else:
                    confirm = 'y'

                if confirm.lower() == 'y':
                    if args.file or not backend.deleteId(filename, args.keep):
                        if (args.id or
                                not backend.deleteFile(filename, args.keep)):
                            tools.warning("Unable to delete " + filename)
                            sys.exit(1)

                    print(filename + " successfully deleted.")
                else:
                    skipped.append(filename)

            if len(skipped) > 0:
                print("\nSkipped files:")
                for i in skipped:
                    print(i)
            sys.exit()
コード例 #5
0
ファイル: bmc.py プロジェクト: drvinceknight/BMC
def resync():
    diff = backend.diffFilesIndex()

    if diff is False:
        return False

    for key in diff:
        entry = diff[key]
        if entry['file'] == '':
            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:
                    if 'doi' in list(entry.keys()):
                        doi = fetcher.findArticleID(filename, only=["DOI"])
                        if doi is not False and doi != entry['doi']:
                            loop = tools.rawInput("Found DOI does not " +
                                                  "match bibtex entry " +
                                                  "DOI, continue anyway " +
                                                  "? [y/N]")
                            loop = (loop.lower() != 'y')
                    if 'Eprint' in list(entry.keys()):
                        arxiv = fetcher.findArticleID(filename, only=["arXiv"])
                        if arxiv is not False and arxiv != entry['Eprint']:
                            loop = tools.rawInput("Found arXiv id does " +
                                                  "not match bibtex " +
                                                  "entry arxiv id, " +
                                                  "continue anyway ? [y/N]")
                            loop = (loop.lower() != 'y')
                    if 'isbn' in list(entry.keys()):
                        isbn = fetcher.findISBN(filename)
                        if isbn is not False and isbn != entry['isbn']:
                            loop = tools.rawInput("Found ISBN does not " +
                                                  "match bibtex entry " +
                                                  "ISBN, continue anyway " +
                                                  "? [y/N]")
                            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 shutil.Error:
                    new_name = False
                    sys.exit("Unable to move file to library dir " +
                             config.get("folder")+".")
                backend.bibtexEdit(entry['id'], {'file': filename})
        else:
            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] ")
                action = action.lower()
            if action == 'import':
                tmp = tempfile.NamedTemporaryFile()
                shutil.copy(entry['file'], tmp.name)
                filetype = tools.getExtension(entry['file'])
                try:
                    os.remove(entry['file'])
                except OSError:
                    tools.warning("Unable to delete file "+entry['file'])
                if not addFile(tmp.name, filetype):
                    tools.warning("Unable to reimport file "+entry['file'])
                tmp.close()
            else:
                backend.deleteFile(entry['file'])
                print(entry['file'] + " removed from disk and " +
                      "index.")
    # Check for empty tag dirs
    for i in os.listdir(config.get("folder")):
        if os.path.isdir(i) and not os.listdir(config.get("folder") + i):
            try:
                os.rmdir(config.get("folder") + i)
            except OSError:
                tools.warning("Found empty tag dir "+config.get("folder") + i +
                              " but could not delete it.")
コード例 #6
0
ファイル: bmc.py プロジェクト: drvinceknight/BMC
                print("\nSkipped files:")
                for i in skipped:
                    print(i)
            sys.exit()

        elif args.func == 'delete':
            skipped = []
            for filename in list(set(args.entries) - set(args.skip)):
                if not args.force:
                    confirm = tools.rawInput("Are you sure you want to " +
                                             "delete "+filename+" ? [y/N] ")
                else:
                    confirm = 'y'

                if confirm.lower() == 'y':
                    if args.file or not backend.deleteId(filename):
                        if args.id or not backend.deleteFile(filename):
                            tools.warning("Unable to delete "+filename)
                            sys.exit(1)

                    print(filename+" successfully deleted.")
                else:
                    skipped.append(filename)

            if len(skipped) > 0:
                print("\nSkipped files:")
                for i in skipped:
                    print(i)
            sys.exit()

        elif args.func == 'edit':
コード例 #7
0
ファイル: bmc.py プロジェクト: m000/BMC
                print("\nSkipped files:")
                for i in skipped:
                    print(i)
            sys.exit()

        elif args.func == 'delete':
            skipped = []
            for filename in list(set(args.entries) - set(args.skip)):
                if not args.force:
                    confirm = tools.rawInput("Are you sure you want to " +
                                             "delete "+filename+" ? [y/N] ")
                else:
                    confirm = 'y'

                if confirm.lower() == 'y':
                    if args.file or not backend.deleteId(filename, args.keep):
                        if(args.id or
                           not backend.deleteFile(filename, args.keep)):
                            tools.warning("Unable to delete "+filename)
                            sys.exit(1)

                    print(filename+" successfully deleted.")
                else:
                    skipped.append(filename)

            if len(skipped) > 0:
                print("\nSkipped files:")
                for i in skipped:
                    print(i)
            sys.exit()