Add --keep argument for delete action, see issue #26
This commit is contained in:
parent
3232fc68be
commit
b655c50f07
7
bmc.py
7
bmc.py
@ -465,6 +465,8 @@ if __name__ == '__main__':
|
||||
help="Confirm all")
|
||||
parser_download.add_argument('--tag', default='',
|
||||
help="Tag", type=commandline_arg)
|
||||
parser_download.add_argument('--keep', default=False,
|
||||
help="Do not remove the file")
|
||||
parser_download.add_argument('url', nargs='+',
|
||||
help="url of the file to import",
|
||||
type=commandline_arg)
|
||||
@ -603,8 +605,9 @@ if __name__ == '__main__':
|
||||
confirm = 'y'
|
||||
|
||||
if confirm.lower() == 'y':
|
||||
if args.file or not backend.deleteId(filename):
|
||||
if args.id or not backend.deleteFile(filename):
|
||||
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)
|
||||
|
||||
|
@ -131,7 +131,7 @@ def bibtexRewrite(data):
|
||||
return False
|
||||
|
||||
|
||||
def deleteId(ident):
|
||||
def deleteId(ident, keep=False):
|
||||
"""Delete a file based on its id in the bibtex file"""
|
||||
try:
|
||||
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
|
||||
@ -145,11 +145,12 @@ def deleteId(ident):
|
||||
if ident not in bibtex.keys():
|
||||
return False
|
||||
|
||||
if not keep:
|
||||
try:
|
||||
os.remove(bibtex[ident]['file'])
|
||||
except (KeyError, OSError):
|
||||
tools.warning("Unable to delete file associated to id "+ident+" : " +
|
||||
bibtex[ident]['file'])
|
||||
tools.warning("Unable to delete file associated to id " + ident +
|
||||
" : " + bibtex[ident]['file'])
|
||||
|
||||
try:
|
||||
if not os.listdir(os.path.dirname(bibtex[ident]['file'])):
|
||||
@ -167,7 +168,7 @@ def deleteId(ident):
|
||||
return True
|
||||
|
||||
|
||||
def deleteFile(filename):
|
||||
def deleteFile(filename, keep=False):
|
||||
"""Delete a file based on its filename"""
|
||||
try:
|
||||
with open(config.get("folder")+'index.bib', 'r', encoding='utf-8') \
|
||||
@ -183,11 +184,12 @@ def deleteFile(filename):
|
||||
try:
|
||||
if os.path.samefile(bibtex[key]['file'], filename):
|
||||
found = True
|
||||
if not keep:
|
||||
try:
|
||||
os.remove(bibtex[key]['file'])
|
||||
except (KeyError, OSError):
|
||||
tools.warning("Unable to delete file associated to id " +
|
||||
key+" : "+bibtex[key]['file'])
|
||||
tools.warning("Unable to delete file associated " +
|
||||
"to id " + key+" : "+bibtex[key]['file'])
|
||||
|
||||
try:
|
||||
if not os.listdir(os.path.dirname(filename)):
|
||||
|
Loading…
Reference in New Issue
Block a user