-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathlist_sites_command.py
38 lines (32 loc) · 1.36 KB
/
list_sites_command.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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 ListSiteCommand(Server):
"""
Command to return a list of sites to which the logged in user belongs
"""
name: str = "listsites"
description: str = _("listsites.short_description")
@staticmethod
def define_args(list_site_parser):
group = list_site_parser.add_argument_group(title=ListSiteCommand.name)
set_site_detail_option(group)
@staticmethod
def run_command(args):
logger = log(__class__.__name__, args.logging_level)
logger.debug(_("tabcmd.launching"))
session = Session()
server = session.create_session(args, logger)
try:
sites, pagination = server.sites.get()
logger.info(_("listsites.status").format(session.username))
for site in sites:
logger.info(_("listsites.output").format(" ", site.name, site.id))
if args.get_extract_encryption_mode:
logger.info("EXTRACTENCRYPTION: {}".format(site.extract_encryption_mode))
except Exception as e:
Errors.exit_with_error(logger, e)