* Skip option in manual fallback
* Homogeneize manual entry for books / articles * Sum up skipped elements * Trailing whitespaces in search
This commit is contained in:
parent
059b6c26a4
commit
3591f0cb1f
46
bmc.py
46
bmc.py
@ -106,29 +106,37 @@ def addFile(src, filetype, manual, autoconfirm, tag):
|
|||||||
tools.warning("Could not determine the DOI nor the arXiv id nor " +
|
tools.warning("Could not determine the DOI nor the arXiv id nor " +
|
||||||
"the ISBN for "+src+". Switching to manual entry.")
|
"the ISBN for "+src+". Switching to manual entry.")
|
||||||
doi_arxiv_isbn = ''
|
doi_arxiv_isbn = ''
|
||||||
while doi_arxiv_isbn not in ['doi', 'arxiv', 'isbn', 'manual']:
|
while doi_arxiv_isbn not in ['doi', 'arxiv', 'isbn', 'manual', 'skip']:
|
||||||
doi_arxiv_isbn = tools.rawInput("DOI / arXiv " +
|
doi_arxiv_isbn = tools.rawInput("DOI / arXiv " +
|
||||||
"/ ISBN / manual? ").lower()
|
"/ ISBN / manual / skip? ").lower()
|
||||||
if doi_arxiv_isbn == 'doi':
|
if doi_arxiv_isbn == 'doi':
|
||||||
doi = tools.rawInput('DOI? ')
|
doi = tools.rawInput('DOI? ')
|
||||||
elif doi_arxiv_isbn == 'arxiv':
|
elif doi_arxiv_isbn == 'arxiv':
|
||||||
arxiv = tools.rawInput('arXiv id? ')
|
arxiv = tools.rawInput('arXiv id? ')
|
||||||
elif doi_arxiv_isbn == 'isbn':
|
elif doi_arxiv_isbn == 'isbn':
|
||||||
isbn = tools.rawInput('ISBN? ')
|
isbn = tools.rawInput('ISBN? ')
|
||||||
|
elif doi_arxiv_isbn == 'skip':
|
||||||
|
return False
|
||||||
elif filetype == 'article':
|
elif filetype == 'article':
|
||||||
tools.warning("Could not determine the DOI nor the arXiv id for " +
|
tools.warning("Could not determine the DOI nor the arXiv id for " +
|
||||||
src+", switching to manual entry.")
|
src+", switching to manual entry.")
|
||||||
doi_arxiv = ''
|
doi_arxiv = ''
|
||||||
while doi_arxiv not in ['doi', 'arxiv', 'manual']:
|
while doi_arxiv not in ['doi', 'arxiv', 'manual', 'skip']:
|
||||||
doi_arxiv = tools.rawInput("DOI / arXiv / manual? ").lower()
|
doi_arxiv = tools.rawInput("DOI / arXiv / manual / skip? ").lower()
|
||||||
if doi_arxiv == 'doi':
|
if doi_arxiv == 'doi':
|
||||||
doi = tools.rawInput('DOI? ')
|
doi = tools.rawInput('DOI? ')
|
||||||
elif doi_arxiv == 'arxiv':
|
elif doi_arxiv == 'arxiv':
|
||||||
arxiv = tools.rawInput('arXiv id? ')
|
arxiv = tools.rawInput('arXiv id? ')
|
||||||
|
elif doi_arxiv == 'skip':
|
||||||
|
return False
|
||||||
elif filetype == 'book':
|
elif filetype == 'book':
|
||||||
tools.warning("Could not determine the ISBN for "+src +
|
isbn_manual = ''
|
||||||
", switching to manual entry.")
|
while isbn_manual not in ['isbn', 'manual', 'skip']:
|
||||||
isbn = tools.rawInput('ISBN? ')
|
isbn_manual = tools.rawInput("ISBN / manual / skip? ").lower()
|
||||||
|
if isbn_manual == 'isbn':
|
||||||
|
isbn = tools.rawInput('ISBN? ')
|
||||||
|
elif isbn_manual == 'skip':
|
||||||
|
return False
|
||||||
elif doi is not False:
|
elif doi is not False:
|
||||||
print("DOI for "+src+" is "+doi+".")
|
print("DOI for "+src+" is "+doi+".")
|
||||||
elif arxiv is not False:
|
elif arxiv is not False:
|
||||||
@ -263,6 +271,8 @@ def downloadFile(url, filetype, manual, autoconfirm, tag):
|
|||||||
with open(tmp.name, 'w+') as fh:
|
with open(tmp.name, 'w+') as fh:
|
||||||
fh.write(dl)
|
fh.write(dl)
|
||||||
new_name = addFile(tmp.name, filetype, manual, autoconfirm, tag)
|
new_name = addFile(tmp.name, filetype, manual, autoconfirm, tag)
|
||||||
|
if new_name is False:
|
||||||
|
return False
|
||||||
tmp.close()
|
tmp.close()
|
||||||
return new_name
|
return new_name
|
||||||
else:
|
else:
|
||||||
@ -475,7 +485,7 @@ if __name__ == '__main__':
|
|||||||
|
|
||||||
parser_export = subparsers.add_parser('export', help="export help")
|
parser_export = subparsers.add_parser('export', help="export help")
|
||||||
parser_export.add_argument('ids', metavar='id', nargs='+',
|
parser_export.add_argument('ids', metavar='id', nargs='+',
|
||||||
help="an identifier")
|
help="an identifier")
|
||||||
parser_export.set_defaults(func='export')
|
parser_export.set_defaults(func='export')
|
||||||
|
|
||||||
parser_resync = subparsers.add_parser('resync', help="resync help")
|
parser_resync = subparsers.add_parser('resync', help="resync help")
|
||||||
@ -494,6 +504,7 @@ if __name__ == '__main__':
|
|||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
try:
|
try:
|
||||||
if args.func == 'download':
|
if args.func == 'download':
|
||||||
|
skipped = []
|
||||||
for url in args.url:
|
for url in args.url:
|
||||||
new_name = downloadFile(url, args.type, args.manual, args.y,
|
new_name = downloadFile(url, args.type, args.manual, args.y,
|
||||||
args.tag)
|
args.tag)
|
||||||
@ -501,9 +512,15 @@ if __name__ == '__main__':
|
|||||||
print(url+" successfully imported as "+new_name)
|
print(url+" successfully imported as "+new_name)
|
||||||
else:
|
else:
|
||||||
tools.warning("An error occurred while downloading "+url)
|
tools.warning("An error occurred while downloading "+url)
|
||||||
|
skipped.append(url)
|
||||||
|
if len(skipped) > 0:
|
||||||
|
print("\nSkipped files:")
|
||||||
|
for i in skipped:
|
||||||
|
print(i)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
if args.func == 'import':
|
if args.func == 'import':
|
||||||
|
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.tag)
|
||||||
@ -513,9 +530,15 @@ if __name__ == '__main__':
|
|||||||
else:
|
else:
|
||||||
tools.warning("An error occurred while importing " +
|
tools.warning("An error occurred while importing " +
|
||||||
filename)
|
filename)
|
||||||
|
skipped.append(filename)
|
||||||
|
if len(skipped) > 0:
|
||||||
|
print("\nSkipped files:")
|
||||||
|
for i in skipped:
|
||||||
|
print(i)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
elif args.func == 'delete':
|
elif args.func == 'delete':
|
||||||
|
skipped = []
|
||||||
for filename in list(set(args.entries) - set(args.skip)):
|
for filename in list(set(args.entries) - set(args.skip)):
|
||||||
if not args.force:
|
if not args.force:
|
||||||
confirm = tools.rawInput("Are you sure you want to " +
|
confirm = tools.rawInput("Are you sure you want to " +
|
||||||
@ -530,6 +553,13 @@ if __name__ == '__main__':
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print(filename+" successfully deleted.")
|
print(filename+" successfully deleted.")
|
||||||
|
else:
|
||||||
|
skipped.append(filename)
|
||||||
|
|
||||||
|
if len(skipped) > 0:
|
||||||
|
print("\nSkipped files:")
|
||||||
|
for i in skipped:
|
||||||
|
print(i)
|
||||||
sys.exit()
|
sys.exit()
|
||||||
|
|
||||||
elif args.func == 'edit':
|
elif args.func == 'edit':
|
||||||
|
Loading…
Reference in New Issue
Block a user