Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tabcmd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from src import tabcmd
from tabcmd import tabcmd

if __name__ == "__main__":
tabcmd.main()
45 changes: 45 additions & 0 deletions tabcmd/commands/site/list_command.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import tableauserverclient as TSC

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):
"""
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(_("tabcmd.launching"))
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()

logger.info("===== Listing {0} content for user {1}...".format(content_type, session.username))
for item in items:
print("NAME:".rjust(10), item.name)
print("ID:".rjust(10), item.id)

except TSC.ServerResponseError as e:
Errors.exit_with_error(logger, e)
5 changes: 2 additions & 3 deletions tabcmd/commands/site/list_sites_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
2 changes: 2 additions & 0 deletions tabcmd/execution/map_of_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down Expand Up @@ -51,6 +52,7 @@ class CommandsMap:
GetUrl,
HelpCommand,
ListSiteCommand,
ListCommand,
LoginCommand,
LogoutCommand,
PublishCommand,
Expand Down
9 changes: 9 additions & 0 deletions tests/e2e/online_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down