updated remove cmd
This commit is contained in:
parent
da3e70649b
commit
c6d7300ae3
@ -3,10 +3,10 @@ import add_cmd
|
|||||||
import list_cmd
|
import list_cmd
|
||||||
import open_cmd
|
import open_cmd
|
||||||
import websearch_cmd
|
import websearch_cmd
|
||||||
|
import remove_cmd
|
||||||
# import import_cmd
|
# import import_cmd
|
||||||
# import export_cmd
|
# import export_cmd
|
||||||
# import edit_cmd
|
# import edit_cmd
|
||||||
# import remove_cmd
|
|
||||||
# import tag_cmd
|
# import tag_cmd
|
||||||
# import attach_cmd
|
# import attach_cmd
|
||||||
# import update_cmd
|
# import update_cmd
|
||||||
|
@ -2,14 +2,14 @@ from .. import repo
|
|||||||
from .. import color
|
from .. import color
|
||||||
from ..configs import config
|
from ..configs import config
|
||||||
from ..uis import get_ui
|
from ..uis import get_ui
|
||||||
from .helpers import add_references_argument, parse_references
|
|
||||||
|
|
||||||
|
|
||||||
def parser(subparsers):
|
def parser(subparsers):
|
||||||
parser = subparsers.add_parser('remove', help='removes a paper')
|
parser = subparsers.add_parser('remove', help='removes a paper')
|
||||||
parser.add_argument('-f', '--force', action='store_true', default=None,
|
parser.add_argument('-f', '--force', action='store_true', default=None,
|
||||||
help="does not prompt for confirmation.")
|
help="does not prompt for confirmation.")
|
||||||
add_references_argument(parser)
|
parser.add_argument('citekeys', nargs='*',
|
||||||
|
help="one or several citekeys")
|
||||||
return parser
|
return parser
|
||||||
|
|
||||||
|
|
||||||
@ -17,15 +17,13 @@ def command(args):
|
|||||||
|
|
||||||
ui = get_ui()
|
ui = get_ui()
|
||||||
force = args.force
|
force = args.force
|
||||||
references = args.references
|
|
||||||
|
|
||||||
rp = repo.Repository(config())
|
rp = repo.Repository(config())
|
||||||
citekeys = parse_references(rp, references)
|
|
||||||
if force is None:
|
if force is None:
|
||||||
are_you_sure = ("Are you sure you want to delete paper(s) [%s]"
|
are_you_sure = (("Are you sure you want to delete paper(s) [{}]"
|
||||||
" (this will also delete associated documents)?"
|
" (this will also delete associated documents)?")
|
||||||
% ', '.join([color.dye(c, color.citekey) for c in citekeys]))
|
.format(', '.join([color.dye(c, color.citekey) for c in args.citekeys])))
|
||||||
sure = ui.input_yn(question=are_you_sure, default='n')
|
sure = ui.input_yn(question=are_you_sure, default='n')
|
||||||
if force or sure:
|
if force or sure:
|
||||||
for c in citekeys:
|
for c in args.citekeys:
|
||||||
rp.remove_paper(c)
|
rp.remove_paper(c)
|
||||||
|
@ -58,8 +58,8 @@ class DataBroker(object):
|
|||||||
def copy_doc(self, citekey, source_path, overwrite=False):
|
def copy_doc(self, citekey, source_path, overwrite=False):
|
||||||
return self.docbroker.copy_doc(citekey, source_path, overwrite=overwrite)
|
return self.docbroker.copy_doc(citekey, source_path, overwrite=overwrite)
|
||||||
|
|
||||||
def remove_doc(self, docpath):
|
def remove_doc(self, docpath, silent=True):
|
||||||
return self.docbroker.remove_doc(docpath)
|
return self.docbroker.remove_doc(docpath, silent=silent)
|
||||||
|
|
||||||
def real_docpath(self, docpath):
|
def real_docpath(self, docpath):
|
||||||
return self.docbroker.real_docpath(docpath)
|
return self.docbroker.real_docpath(docpath)
|
@ -68,8 +68,8 @@ class DataCache(object):
|
|||||||
def copy_doc(self, citekey, source_path, overwrite=False):
|
def copy_doc(self, citekey, source_path, overwrite=False):
|
||||||
return self.databroker.copy_doc(citekey, source_path, overwrite=overwrite)
|
return self.databroker.copy_doc(citekey, source_path, overwrite=overwrite)
|
||||||
|
|
||||||
def remove_doc(self, docpath):
|
def remove_doc(self, docpath, silent=True):
|
||||||
return self.databroker.remove_doc(docpath)
|
return self.databroker.remove_doc(docpath, silent=silent)
|
||||||
|
|
||||||
def real_docpath(self, docpath):
|
def real_docpath(self, docpath):
|
||||||
return self.databroker.real_docpath(docpath)
|
return self.databroker.real_docpath(docpath)
|
||||||
|
@ -118,7 +118,10 @@ class DocBroker(object):
|
|||||||
os.mkdir(self.docdir)
|
os.mkdir(self.docdir)
|
||||||
|
|
||||||
def is_pubsdir_doc(self, docpath):
|
def is_pubsdir_doc(self, docpath):
|
||||||
parsed = urlparse.urlparse(docpath)
|
try:
|
||||||
|
parsed = urlparse.urlparse(docpath)
|
||||||
|
except Exception:
|
||||||
|
return False
|
||||||
if parsed.scheme == 'pubsdir':
|
if parsed.scheme == 'pubsdir':
|
||||||
assert parsed.netloc == 'doc'
|
assert parsed.netloc == 'doc'
|
||||||
assert parsed.path[0] == '/'
|
assert parsed.path[0] == '/'
|
||||||
@ -143,14 +146,16 @@ class DocBroker(object):
|
|||||||
|
|
||||||
return target_path
|
return target_path
|
||||||
|
|
||||||
def remove_doc(self, docpath):
|
def remove_doc(self, docpath, silent=True):
|
||||||
""" Will remove only file hosted in pubsdir://doc/
|
""" Will remove only file hosted in pubsdir://doc/
|
||||||
|
|
||||||
:raise ValueError: for other paths.
|
:raise ValueError: for other paths, unless :param silent: is True
|
||||||
"""
|
"""
|
||||||
if not self.is_pubsdir_doc(docpath):
|
if not self.is_pubsdir_doc(docpath):
|
||||||
raise ValueError(('the file to be removed {} is set as external. '
|
if not silent:
|
||||||
'you should remove it manually.').format(docpath))
|
raise ValueError(('the file to be removed {} is set as external. '
|
||||||
|
'you should remove it manually.').format(docpath))
|
||||||
|
return
|
||||||
filepath = self.real_docpath(docpath)
|
filepath = self.real_docpath(docpath)
|
||||||
if check_file(filepath):
|
if check_file(filepath):
|
||||||
os.remove(filepath)
|
os.remove(filepath)
|
||||||
|
@ -18,10 +18,10 @@ CORE_CMDS = collections.OrderedDict([
|
|||||||
('list', commands.list_cmd),
|
('list', commands.list_cmd),
|
||||||
('open', commands.open_cmd),
|
('open', commands.open_cmd),
|
||||||
('websearch', commands.websearch_cmd),
|
('websearch', commands.websearch_cmd),
|
||||||
|
('remove', commands.remove_cmd),
|
||||||
# ('import', commands.import_cmd),
|
# ('import', commands.import_cmd),
|
||||||
# ('export', commands.export_cmd),
|
# ('export', commands.export_cmd),
|
||||||
# ('edit', commands.edit_cmd),
|
# ('edit', commands.edit_cmd),
|
||||||
# ('remove', commands.remove_cmd),
|
|
||||||
# ('tag', commands.tag_cmd),
|
# ('tag', commands.tag_cmd),
|
||||||
# ('attach', commands.attach_cmd),
|
# ('attach', commands.attach_cmd),
|
||||||
# ('update', commands.update_cmd),
|
# ('update', commands.update_cmd),
|
||||||
|
@ -79,12 +79,12 @@ class Repository(object):
|
|||||||
""" Remove a paper. Is silent if nothing needs to be done."""
|
""" Remove a paper. Is silent if nothing needs to be done."""
|
||||||
|
|
||||||
if event:
|
if event:
|
||||||
RemoveEvent(citekey).send()
|
events.RemoveEvent(citekey).send()
|
||||||
if remove_doc:
|
if remove_doc:
|
||||||
try:
|
try:
|
||||||
metadata = self.databroker.pull_metadata(paper.citekey)
|
metadata = self.databroker.pull_metadata(citekey)
|
||||||
docpath = metadata.get('docfile', '')
|
docpath = metadata.get('docfile')
|
||||||
self.databroker.remove_doc(docpath)
|
self.databroker.remove_doc(docpath, silent=True)
|
||||||
except IOError:
|
except IOError:
|
||||||
pass # FXME: if IOError is about being unable to
|
pass # FXME: if IOError is about being unable to
|
||||||
# remove the file, we need to issue an error.I
|
# remove the file, we need to issue an error.I
|
||||||
|
Loading…
x
Reference in New Issue
Block a user