From 2a6582d3ca1a0fa33d279d3c08a8c7da0ec581db Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Thu, 14 Apr 2022 16:20:21 -0700 Subject: [PATCH 1/4] new command: list content --- tabcmd/commands/site/list_command.py | 49 ++++++++++++++++++++++++++++ tabcmd/execution/map_of_commands.py | 2 ++ 2 files changed, 51 insertions(+) create mode 100644 tabcmd/commands/site/list_command.py diff --git a/tabcmd/commands/site/list_command.py b/tabcmd/commands/site/list_command.py new file mode 100644 index 00000000..888ac88e --- /dev/null +++ b/tabcmd/commands/site/list_command.py @@ -0,0 +1,49 @@ +import tableauserverclient as TSC + +from tabcmd.commands.auth.session import Session +from tabcmd.commands.server import Server +from tabcmd.commands.constants import Errors +from tabcmd.execution.logger_config import log + + +class ListCommand(Server): + """ + Command to return a list of content the user can access + """ + + name: str = "list" + description: str = "List content items of a specified type" + + @staticmethod + def define_args(list_parser): + list_parser.add_argument( + "content", + choices=["projects", "workbooks", "datasources"], + help="View content" + ) + + @staticmethod + def run_command(args): + logger = log(__name__, args.logging_level) + logger.debug("======================= Launching command =======================") + session = Session() + server = session.create_session(args) + content_type = args.content + + try: + if content_type == "projects": + items = server.projects.all() + elif content_type == "workbooks": + items = server.workbooks.all() + elif content_type == "datasources": + items = server.datasources.all() + else: + items = Server.get_sites(server) + + logger.info("===== Listing {0} content for user {1}...".format(content_type, session.username)) + for item in items: + print("NAME:", item.name) + print(" ID:", item.id) + + except TSC.ServerResponseError as e: + Errors.exit_with_error(logger, e) diff --git a/tabcmd/execution/map_of_commands.py b/tabcmd/execution/map_of_commands.py index 87ff0a1d..c6f7a679 100644 --- a/tabcmd/execution/map_of_commands.py +++ b/tabcmd/execution/map_of_commands.py @@ -23,6 +23,7 @@ from tabcmd.commands.user.add_users_command import * from tabcmd.commands.user.create_site_users import * from tabcmd.commands.user.delete_site_users_command import * +from tabcmd.commands.site.list_command import * # from tabcmd.commands.user.create_users import * from tabcmd.commands.user.remove_users_command import * @@ -51,6 +52,7 @@ class CommandsMap: GetUrl, HelpCommand, ListSiteCommand, + ListCommand, LoginCommand, LogoutCommand, PublishCommand, From 121687db8b31eb8e53d96b18317c48076199ef88 Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Thu, 23 Jun 2022 18:41:56 -0700 Subject: [PATCH 2/4] some localization --- tabcmd/commands/site/list_command.py | 15 ++++++++------- tabcmd/commands/site/list_sites_command.py | 5 ++--- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/tabcmd/commands/site/list_command.py b/tabcmd/commands/site/list_command.py index 888ac88e..0fadb27e 100644 --- a/tabcmd/commands/site/list_command.py +++ b/tabcmd/commands/site/list_command.py @@ -1,9 +1,10 @@ import tableauserverclient as TSC -from tabcmd.commands.auth.session import Session -from tabcmd.commands.server import Server -from tabcmd.commands.constants import Errors -from tabcmd.execution.logger_config import log +from src.commands.auth.session import Session +from src.commands.server import Server +from src.commands.constants import Errors +from src.execution.logger_config import log +from src.execution.localize import _ class ListCommand(Server): @@ -25,7 +26,7 @@ def define_args(list_parser): @staticmethod def run_command(args): logger = log(__name__, args.logging_level) - logger.debug("======================= Launching command =======================") + logger.debug(_("tabcmd.launching")) session = Session() server = session.create_session(args) content_type = args.content @@ -42,8 +43,8 @@ def run_command(args): logger.info("===== Listing {0} content for user {1}...".format(content_type, session.username)) for item in items: - print("NAME:", item.name) - print(" ID:", item.id) + print("NAME:".rjust(10), item.name) + print("ID:".rjust(10), item.id) except TSC.ServerResponseError as e: Errors.exit_with_error(logger, e) diff --git a/tabcmd/commands/site/list_sites_command.py b/tabcmd/commands/site/list_sites_command.py index 418f6caf..8a371ccb 100644 --- a/tabcmd/commands/site/list_sites_command.py +++ b/tabcmd/commands/site/list_sites_command.py @@ -30,10 +30,9 @@ def run_command(args): sites, pagination = server.sites.get() logger.info(_("listsites.status").format(session.username)) for site in sites: - print("NAME:", site.name) - print("SITEID:", site.content_url) + print("NAME:".rjust(10), site.name) + print("SITEID:".rjust(10), site.content_url) if args.get_extract_encryption_mode: print("EXTRACTENCRYPTION:", site.extract_encryption_mode) - print("") except TSC.ServerResponseError as e: Errors.exit_with_error(logger, e) From ca440a484e67837f930cc2d8e77f6b35692e5f6d Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Fri, 29 Jul 2022 11:57:16 -0700 Subject: [PATCH 3/4] add new command to e2e tests --- tabcmd.py | 2 +- tabcmd/commands/site/list_command.py | 11 ++++++----- tests/e2e/online_tests.py | 9 +++++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/tabcmd.py b/tabcmd.py index 1c987d62..55e7e634 100644 --- a/tabcmd.py +++ b/tabcmd.py @@ -1,4 +1,4 @@ -from src import tabcmd +from tabcmd import tabcmd if __name__ == "__main__": tabcmd.main() diff --git a/tabcmd/commands/site/list_command.py b/tabcmd/commands/site/list_command.py index 0fadb27e..ae26c935 100644 --- a/tabcmd/commands/site/list_command.py +++ b/tabcmd/commands/site/list_command.py @@ -1,10 +1,11 @@ import tableauserverclient as TSC -from src.commands.auth.session import Session -from src.commands.server import Server -from src.commands.constants import Errors -from src.execution.logger_config import log -from src.execution.localize import _ +from tabcmd.commands.auth.session import Session +from tabcmd.commands.constants import Errors +from tabcmd.commands.server import Server +from tabcmd.execution.global_options import * +from tabcmd.execution.localize import _ +from tabcmd.execution.logger_config import log class ListCommand(Server): diff --git a/tests/e2e/online_tests.py b/tests/e2e/online_tests.py index 7aa69610..8906c9b8 100644 --- a/tests/e2e/online_tests.py +++ b/tests/e2e/online_tests.py @@ -106,6 +106,11 @@ def _delete_extract(self, wb_name): arguments = [command, "-w", wb_name] _test_command(arguments) + def _list(self, item_type: str): + command = "list" + arguments = [command, item_type] + _test_command(arguments) + # actual tests TWBX_FILE_WITH_EXTRACT = "extract-data-access.twbx" TWBX_WITH_EXTRACT_NAME = "WorkbookWithExtract" @@ -192,6 +197,10 @@ def test_create_projects(self): self._create_project(project_name, parent_path) time.sleep(indexing_sleep_time) + @pytest.mark.order(8) + def test_list_projects(self): + self._list("projects") + @pytest.mark.order(9) def test_delete_projects(self): self._delete_project("project_name_2", project_name) # project 2 From 7dda0674c0c39122c26a0487f1bc10f0298f68fe Mon Sep 17 00:00:00 2001 From: Jac Fitzgerald Date: Fri, 5 Aug 2022 13:12:49 -0700 Subject: [PATCH 4/4] remove unneeded fallback --- tabcmd/commands/site/list_command.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tabcmd/commands/site/list_command.py b/tabcmd/commands/site/list_command.py index ae26c935..2eff8ec5 100644 --- a/tabcmd/commands/site/list_command.py +++ b/tabcmd/commands/site/list_command.py @@ -18,11 +18,7 @@ class ListCommand(Server): @staticmethod def define_args(list_parser): - list_parser.add_argument( - "content", - choices=["projects", "workbooks", "datasources"], - help="View content" - ) + list_parser.add_argument("content", choices=["projects", "workbooks", "datasources"], help="View content") @staticmethod def run_command(args): @@ -39,8 +35,6 @@ def run_command(args): items = server.workbooks.all() elif content_type == "datasources": items = server.datasources.all() - else: - items = Server.get_sites(server) logger.info("===== Listing {0} content for user {1}...".format(content_type, session.username)) for item in items: