Skip to content

Commit

Permalink
Fixed a bug in the workspaces command completion caused by the previo…
Browse files Browse the repository at this point in the history
…us update.

Changed several subcommand instances of "delete" to "remove" to be more consistent.
  • Loading branch information
lanmaster53 committed Oct 16, 2019
1 parent b427255 commit 9fd69d7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
49 changes: 26 additions & 23 deletions recon/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _init_workspace(self, workspace):
self._load_modules()
return True

def delete_workspace(self, workspace):
def remove_workspace(self, workspace):
path = os.path.join(self.spaces_path, workspace)
try:
shutil.rmtree(path)
Expand All @@ -218,14 +218,11 @@ def delete_workspace(self, workspace):

def _get_workspaces(self):
workspaces = []
path = os.path.join(self.spaces_path)
path = self.spaces_path
for name in os.listdir(path):
dirname = os.path.join(path, name)
if os.path.isdir(dirname):
db_path = os.path.join(path, name, 'data.db')
modified = datetime.fromtimestamp(os.path.getmtime(db_path)).strftime('%Y-%m-%d %H:%M:%S')
workspaces.append((name, modified))
return sorted(workspaces, key=lambda tup: tup[0])
if os.path.isdir(os.path.join(path, name)):
workspaces.append(name)
return workspaces

def _get_snapshots(self):
snapshots = []
Expand Down Expand Up @@ -618,7 +615,13 @@ def do_workspaces(self, params):

def _do_workspaces_list(self, params):
'''Lists existing workspaces'''
self.table(self._get_workspaces(), header=['Workspaces', 'Modified'])
rows = []
for workspace in self._get_workspaces():
db_path = os.path.join(self.spaces_path, workspace, 'data.db')
modified = datetime.fromtimestamp(os.path.getmtime(db_path)).strftime('%Y-%m-%d %H:%M:%S')
rows.append((workspace, modified))
rows.sort(key=lambda x: x[0])
self.table(rows, header=['Workspaces', 'Modified'])

def _do_workspaces_create(self, params):
'''Creates a new workspace'''
Expand All @@ -636,13 +639,13 @@ def _do_workspaces_select(self, params):
if not self._init_workspace(params):
self.output(f"Unable to initialize '{params}' workspace.")

def _do_workspaces_delete(self, params):
def _do_workspaces_remove(self, params):
'''Deletes an existing workspace'''
if not params:
self._help_workspaces_delete()
self._help_workspaces_remove()
return
if not self.delete_workspace(params):
self.output(f"Unable to delete '{params}' workspace.")
if not self.remove_workspace(params):
self.output(f"Unable to remove '{params}' workspace.")

def do_snapshots(self, params):
'''Manages workspace snapshots'''
Expand Down Expand Up @@ -685,10 +688,10 @@ def _do_snapshots_load(self, params):
else:
self.error(f"No snapshot named '{params}'.")

def _do_snapshots_delete(self, params):
def _do_snapshots_remove(self, params):
'''Deletes an existing snapshot'''
if not params:
self._help_snapshots_delete()
self._help_snapshots_remove()
return
if params in self._get_snapshots():
os.remove(os.path.join(self.workspace, params))
Expand Down Expand Up @@ -791,9 +794,9 @@ def _help_workspaces_select(self):
print(getattr(self, '_do_workspaces_select').__doc__)
print(f"{os.linesep}Usage: workspace select <name>{os.linesep}")

def _help_workspaces_delete(self):
print(getattr(self, '_do_workspaces_delete').__doc__)
print(f"{os.linesep}Usage: workspace delete <name>{os.linesep}")
def _help_workspaces_remove(self):
print(getattr(self, '_do_workspaces_remove').__doc__)
print(f"{os.linesep}Usage: workspace remove <name>{os.linesep}")

def help_snapshots(self):
print(getattr(self, 'do_snapshots').__doc__)
Expand All @@ -803,9 +806,9 @@ def _help_snapshots_load(self):
print(getattr(self, '_do_snapshots_load').__doc__)
print(f"{os.linesep}Usage: snapshots load <name>{os.linesep}")

def _help_snapshots_delete(self):
print(getattr(self, '_do_snapshots_delete').__doc__)
print(f"{os.linesep}Usage: snapshots delete <name>{os.linesep}")
def _help_snapshots_remove(self):
print(getattr(self, '_do_snapshots_remove').__doc__)
print(f"{os.linesep}Usage: snapshots remove <name>{os.linesep}")

#==================================================
# COMPLETE METHODS
Expand Down Expand Up @@ -847,7 +850,7 @@ def _complete_workspaces_list(self, text, *ignored):

def _complete_workspaces_select(self, text, *ignored):
return [x for x in self._get_workspaces() if x.startswith(text)]
_complete_workspaces_delete = _complete_workspaces_select
_complete_workspaces_remove = _complete_workspaces_select

def complete_snapshots(self, text, line, *ignored):
arg, params = self._parse_params(line.split(' ', 1)[1])
Expand All @@ -862,7 +865,7 @@ def _complete_snapshots_list(self, text, *ignored):

def _complete_snapshots_load(self, text, *ignored):
return [x for x in self._get_snapshots() if x.startswith(text)]
_complete_snapshots_delete = _complete_snapshots_load
_complete_snapshots_remove = _complete_snapshots_load

def _complete_modules_reload(self, text, *ignored):
return []
Expand Down
2 changes: 1 addition & 1 deletion recon/core/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,7 +947,7 @@ def _do_keys_remove(self, params):
return
if self.get_key(key):
if self.remove_key(key):
self.output(f"Key '{key}' deleted.")
self.output(f"Key '{key}' removed.")
else:
self.error('Invalid key name.')

Expand Down

0 comments on commit 9fd69d7

Please sign in to comment.