Skip to content

Commit

Permalink
Merge pull request #909 from debrief/update-pepys-viewer
Browse files Browse the repository at this point in the history
Extend Pepys Viewer to include more view-only options
  • Loading branch information
IanMayo authored May 10, 2021
2 parents 1a0fb37 + a15539b commit 4f73cf5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
3 changes: 2 additions & 1 deletion pepys_admin/admin_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def __init__(self, data_store, csv_path=DIR_PATH):
super(AdminShell, self).__init__()
self.data_store = data_store
self.csv_path = csv_path
self.viewer = False
self.aliases = {
".": self.do_exit,
"1": self.do_initialise,
Expand Down Expand Up @@ -196,7 +197,7 @@ def do_view_data(self):
if is_schema_created(self.data_store.engine, self.data_store.db_type) is False:
return
print("-" * 60)
shell = ViewDataShell(self.data_store)
shell = ViewDataShell(self.data_store, viewer=self.viewer)
shell.cmdloop()

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions pepys_admin/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import config
from pepys_admin.admin_cli import AdminShell
from pepys_admin.view_data_cli import ViewDataShell
from pepys_admin.viewer_cli import ViewerShell
from pepys_import.cli import set_up_training_mode
from pepys_import.core.store.data_store import DataStore
from pepys_import.utils.data_store_utils import is_schema_created
Expand Down Expand Up @@ -100,7 +100,7 @@ def run_shell(path, training=False, data_store=None, db=None, viewer=False):
)
)
return
ViewDataShell(data_store, viewer=True).cmdloop()
ViewerShell(data_store, path).cmdloop()
else:
with handle_database_errors():
AdminShell(data_store, path).cmdloop()
Expand Down
8 changes: 2 additions & 6 deletions pepys_admin/view_data_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,13 @@ def __init__(self, data_store, viewer=False):
self.viewer = viewer

if viewer:
self.prompt = "(pepys-viewer) "
self.choices = self.choices.replace("(.) Back", "(.) Exit")
self.prompt = "(pepys-viewer) (view) "
else:
self.prompt = "(pepys-admin) (view) "

def do_cancel(self):
"""Returns to the previous menu"""
if self.viewer:
print("Thank you for using Pepys Viewer")
else:
print("Returning to the previous menu...")
print("Returning to the previous menu...")

def _get_table_names(self):
"""Gets the table names using SQL Alchemy's inspect db functionality."""
Expand Down
31 changes: 31 additions & 0 deletions pepys_admin/viewer_cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import os

from pepys_admin.admin_cli import AdminShell

DIR_PATH = os.path.dirname(os.path.abspath(__file__))


class ViewerShell(AdminShell):
"""The ViewerShell is a limited version of the AdminShell. It inherits from AdminShell so we don't
have to re-implement each function."""

choices = """(1) Status
(2) View Data
(3) View Docs
(4) View dashboard
(.) Exit
"""
prompt = "(pepys-viewer) "

def __init__(self, data_store, csv_path=DIR_PATH):
super(ViewerShell, self).__init__(data_store, csv_path)
self.viewer = True
self.data_store = data_store
self.csv_path = csv_path
self.aliases = {
".": self.do_exit,
"1": self.do_status,
"2": self.do_view_data,
"3": self.do_view_docs,
"4": self.do_view_dashboard,
}
6 changes: 3 additions & 3 deletions tests/test_admin_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1746,8 +1746,8 @@ def test_viewer_mode_blank_db(patched_print):
assert "Database schema does not exist: tables cannot be viewed" in output


@patch("pepys_admin.cli.ViewDataShell")
def test_viewer_mode_valid_db(patched_vds):
@patch("pepys_admin.cli.ViewerShell")
def test_viewer_mode_valid_db(patched_vs):
if os.path.exists("created_db.db"):
os.remove("created_db.db")

Expand All @@ -1756,7 +1756,7 @@ def test_viewer_mode_valid_db(patched_vds):

run_shell(path=".", db="created_db.db", training=False, viewer=True)

patched_vds.assert_called_with(ANY, viewer=True)
patched_vs.assert_called()


if __name__ == "__main__":
Expand Down

0 comments on commit 4f73cf5

Please sign in to comment.