8000 Unify arguments of sample scripts by vogelsgesang · Pull Request #889 · tableau/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

Unify arguments of sample scripts #889

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 23, 2021
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
24 changes: 11 additions & 13 deletions samples/add_default_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,33 @@
####

import argparse
import getpass
import logging

import tableauserverclient as TSC


def main():
parser = argparse.ArgumentParser(description='Add workbook default permissions for a given project.')
parser.add_argument('--server', '-s', required=True, help='Server address')
parser.add_argument('--username', '-u', required=True, help='Username to sign into server')
parser.add_argument('--site', '-S', default=None, help='Site to sign into - default site if not provided')
parser.add_argument('-p', default=None, help='Password to sign into server')

# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
# Options specific to this sample
# This sample has no additional options, yet. If you add some, please add them here

args = parser.parse_args()

if args.p is None:
password = getpass.getpass("Password: ")
else:
password = args.p

# Set logging level based on user input, or error by default
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)

# Sign in
tableau_auth = TSC.TableauAuth(args.username, password, args.site)
# Sign in to server
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
with server.auth.sign_in(tableau_auth):

Expand Down
17 changes: 11 additions & 6 deletions samples/create_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


import argparse
import getpass
import logging

from datetime import time
Expand All @@ -18,20 +17,26 @@
def main():

parser = argparse.ArgumentParser(description='Creates a sample user group.')
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
args = parser.parse_args()
# Options specific to this sample
# This sample has no additional options, yet. If you add some, please add them here

password = getpass.getpass("Password: ")
args = parser.parse_args()

# Set logging level based on user input, or error by default
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)

tableau_auth = TSC.TableauAuth(args.username, password)
server = TSC.Server(args.server)
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
with server.auth.sign_in(tableau_auth):
group = TSC.GroupItem('test')
group = server.groups.create(group)
Expand Down
23 changes: 10 additions & 13 deletions samples/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
####

import argparse
import getpass
import logging
import sys

Expand All @@ -27,28 +26,26 @@ def create_project(server, project_item):

def main():
parser = argparse.ArgumentParser(description='Create new projects.')
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
parser.add_argument('--site', '-S', default=None)
parser.add_argument('-p', default=None, help='password')

parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
# Options specific to this sample
# This sample has no additional options, yet. If you add some, please add them here

args = parser.parse_args()

if args.p is None:
password = getpass.getpass("Password: ")
else:
password = args.p

# Set logging level based on user input, or error by default
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)

tableau_auth = TSC.TableauAuth(args.username, password)
server = TSC.Server(args.server)

tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
with server.auth.sign_in(tableau_auth):
# Use highest Server REST API version available
server.use_server_version()
Expand Down
17 changes: 11 additions & 6 deletions samples/create_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


import argparse
import getpass
import logging

from datetime import time
Expand All @@ -18,20 +17,26 @@
def main():

parser = argparse.ArgumentParser(description='Creates sample schedules for each type of frequency.')
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
args = parser.parse_args()
# Options specific to this sample
# This sample has no additional options, yet. If you add some, please add them here

password = getpass.getpass("Password: ")
args = parser.parse_args()

# Set logging level based on user input, or error by default
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)

tableau_auth = TSC.TableauAuth(args.username, password)
server = TSC.Server(args.server)
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
with server.auth.sign_in(tableau_auth):
# Hourly Schedule
# This schedule will run every 2 hours between 2:30AM and 11:00PM
Expand Down
29 changes: 12 additions & 17 deletions samples/download_view_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
####

import argparse
import getpass
import logging

import tableauserverclient as TSC
Expand All @@ -18,34 +17,30 @@
def main():

parser = argparse.ArgumentParser(description='Download image of a specified view.')
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--site-id', '-si', required=False,
help='content url for site the view is on')
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
parser.add_argument('--view-name', '-v', required=True,
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
# Options specific to this sample
parser.add_argument('--view-name', '-vn', required=True,
help='name of view to download an image of')
parser.add_argument('--filepath', '-f', required=True, help='filepath to save the image returned')
parser.add_argument('--maxage', '-m', required=False, help='max age of the image in the cache in minutes.')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')

args = parser.parse_args()

password = getpass.getpass("Password: ")

# Set logging level based on user input, or error by default
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)

# Step 1: Sign in to server.
site_id = args.site_id
if not site_id:
site_id = ""
tableau_auth = TSC.TableauAuth(args.username, password, site_id=site_id)
server = TSC.Server(args.server)
# The new endpoint was introduced in Version 2.5
server.version = "2.5"

tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
with server.auth.sign_in(tableau_auth):
# Step 2: Query for the view that we want an image of
req_option = TSC.RequestOptions()
Expand Down
20 changes: 11 additions & 9 deletions samples/explore_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
####

import argparse
import getpass
import logging

import tableauserverclient as TSC
Expand All @@ -19,25 +18,28 @@
def main():

parser = argparse.ArgumentParser(description='Explore datasource functions supported by the Server API.')
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
parser.add_argument('--publish', '-p', metavar='FILEPATH', help='path to datasource to publish')
parser.add_argument('--download', '-d', metavar='FILEPATH', help='path to save downloaded datasource')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
# Options specific to this sample
parser.add_argument('--publish', metavar='FILEPATH', help='path to datasource to publish')
parser.add_argument('--download', metavar='FILEPATH', help='path to save downloaded datasource')

args = parser.parse_args()

password = getpass.getpass("Password: ")

# Set logging level based on user input, or error by default
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)

# SIGN IN
tableau_auth = TSC.TableauAuth(args.username, password)
server = TSC.Server(args.server)
server.use_highest_version()
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
with server.auth.sign_in(tableau_auth):
# Query projects for use when demonstrating publishing and updating
all_projects, pagination_item = server.projects.get()
Expand Down
30 changes: 11 additions & 19 deletions samples/explore_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
####

import argparse
import getpass
import logging
import os.path

Expand All @@ -20,35 +19,28 @@
def main():

parser = argparse.ArgumentParser(description='Explore webhook functions supported by the Server API.')
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
parser.add_argument('--site', '-S', default=None)
parser.add_argument('-p', default=None, help='password')
parser.add_argument('--create', '-c', help='create a webhook')
parser.add_argument('--delete', '-d', help='delete a webhook', action='store_true')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
# Options specific to this sample
parser.add_argument('--create', help='create a webhook')
parser.add_argument('--delete', help='delete a webhook', action='store_true')

args = parser.parse_args()
if args.p is None:
password = getpass.getpass("Password: ")
else:
password = args.p

# Set logging level based on user input, or error by default
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)

# SIGN IN
tableau_auth = TSC.TableauAuth(args.username, password, args.site)
print("Signing in to " + args.server + " [" + args.site + "] as " + args.username)
server = TSC.Server(args.server)

# Set http options to disable verifying SSL
server.add_http_options({'verify': False})

server.use_server_version()

tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
with server.auth.sign_in(tableau_auth):

# Create webhook if create flag is set (-create, -c)
Expand Down
28 changes: 14 additions & 14 deletions samples/explore_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
####

import argparse
import getpass
import logging
import os.path

Expand All @@ -20,33 +19,34 @@
def main():

parser = argparse.ArgumentParser(description='Explore workbook functions supported by the Server API.')
# Common options; please keep those in sync across all samples
parser.add_argument('--server', '-s', required=True, help='server address')
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
parser.add_argument('--publish', '-p', metavar='FILEPATH', help='path to workbook to publish')
parser.add_argument('--download', '-d', metavar='FILEPATH', help='path to save downloaded workbook')
parser.add_argument('--preview-image', '-i', metavar='FILENAME',
help='filename (a .png file) to save the preview image')
parser.add_argument('--site', '-S', help='site name')
parser.add_argument('--token-name', '-p', required=True,
help='name of the personal access token used to sign into the server')
parser.add_argument('--token-value', '-v', required=True,
help='value of the personal access token used to sign into the server')
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
help='desired logging level (set to error by default)')
# Options specific to this sample
parser.add_argument('--publish', metavar='FILEPATH', help='path to workbook to publish')
parser.add_argument('--download', metavar='FILEPATH', help='path to save downloaded workbook')
parser.add_argument('--preview-image', '-i', metavar='FILENAME',
help='filename (a .png file) to save the preview image')

args = parser.parse_args()

password = getpass.getpass("Password: ")

# Set logging level based on user input, or error by default
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)

# SIGN IN
tableau_auth = TSC.TableauAuth(args.username, password)
server = TSC.Server(args.server)
server.use_highest_version()

overwrite_true = TSC.Server.PublishMode.Overwrite

tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
server = TSC.Server(args.server, use_server_version=True)
with server.auth.sign_in(tableau_auth):

# Publish workbook if publish flag is set (-publish, -p)
overwrite_true = TSC.Server.PublishMode.Overwrite
if args.publish:
all_projects, pagination_item = server.projects.get()
default_project = next((project for project in all_projects if project.is_default()), None)
Expand Down
Loading
0