8000 cleaning up samples - argparse, getpass, and print messages (#19) · subodhgupta/server-client-python@0245d6a · GitHub
[go: up one dir, main page]

Skip to content

Commit 0245d6a

Browse files
authored
cleaning up samples - argparse, getpass, and print messages (tableau#19)
1 parent fa97e62 commit 0245d6a

File tree

6 files changed

+52
-42
lines changed

6 files changed

+52
-42
lines changed

samples/explore_datasource.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,26 @@
1313
import tableauserverapi as TSA
1414
import os.path
1515
import argparse
16+
import getpass
1617
import logging
1718

1819
parser = argparse.ArgumentParser(description='Explore datasource functions supported by the Server API.')
19-
parser.add_argument('server', help='server address')
20-
parser.add_argument('username', help='username to sign into server')
21-
parser.add_argument('password', help='password to sign into server')
22-
parser.add_argument('-publish', '-p', metavar='FILEPATH', help='path to datasource to publish')
23-
parser.add_argument('-download', '-d', metavar='FILEPATH', help='path to save downloaded datasource')
24-
parser.add_argument('--logging-level', choices=['debug', 'info', 'error'], default='error',
20+
parser.add_argument('--server', '-s', required=True, help='server address')
21+
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
22+
parser.add_argument('--publish', '-p', metavar='FILEPATH', help='path to datasource to publish')
23+
parser.add_argument('--download', '-d', metavar='FILEPATH', help='path to save downloaded datasource')
24+
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
2525
help='desired logging level (set to error by default)')
2626
args = parser.parse_args()
2727

28+
password = getpass.getpass("Password: ")
29+
2830
# Set logging level based on user input, or error by default
2931
logging_level = getattr(logging, args.logging_level.upper())
3032
logging.basicConfig(level=logging_level)
3133

3234
##### SIGN IN #####
33-
tableau_auth = TSA.TableauAuth(args.username, args.password)
35+
tableau_auth = TSA.TableauAuth(args.username, password)
3436
server = TSA.Server(args.server)
3537
with server.auth.sign_in(tableau_auth):
3638

@@ -58,7 +60,7 @@
5860

5961
# Populate connections
6062
server.datasources.populate_connections(sample_datasource)
61-
print("\nConnections for datasource: ")
63+
print("\nConnections for {}: ".format(sample_datasource.name))
6264
print(["{0}({1})".format(connection.id, connection.datasource_name)
6365
for connection in sample_datasource.connections])
6466

samples/explore_workbook.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,27 @@
1313
import os.path
1414
import copy
1515
import argparse
16+
import getpass
1617
import logging
1718

1819
parser = argparse.ArgumentParser(description='Explore workbook functions supported by the Server API.')
19-
parser.add_argument('server', help='server address')
20-
parser.add_argument('username', help='username to sign into server')
21-
parser.add_argument('password', help='password to sign into server')
22-
parser.add_argument('-publish', '-p', metavar='FILEPATH', help='path to workbook to publish')
23-
parser.add_argument('-download', '-d', metavar='FILEPATH', help='path to save downloaded workbook')
24-
parser.add_argument('-preview-image', '-i', metavar='FILEPATH', help='path to save populated preview image')
25-
parser.add_argument('--logging-level', choices=['debug', 'info', 'error'], defualt='error',
20+
parser.add_argument('--server', '-s', required=True, help='server address')
21+
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
22+
parser.add_argument('--publish', '-p', metavar='FILEPATH', help='path to workbook to publish')
23+
parser.add_argument('--download', '-d', metavar='FILEPATH', help='path to save downloaded workbook')
24+
parser.add_argument('--preview-image', '-i', metavar='FILEPATH', help='path to save populated preview image')
25+
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], defualt='error',
2626
help='desired logging level (set to error by default)')
2727
args = parser.parse_args()
2828

29+
password = getpass.getpass("Password: ")
30+
2931
# Set logging level based on user input, or error by default
3032
logging_level = getattr(logging, args.logging_level.upper())
3133
logging.basicConfig(level=logging_level)
3234

3335
##### SIGN IN #####
34-
tableau_auth = TSA.TableauAuth(args.username, args.password)
36+
tableau_auth = TSA.TableauAuth(args.username, password)
3537
server = TSA.Server(args.server)
3638
with server.auth.sign_in(tableau_auth):
3739

@@ -58,12 +60,12 @@
5860

5961
# Populate views
6062
server.workbooks.populate_views(sample_workbook)
61-
print("\nName of views in workbook {}: ".format(sample_workbook.name))
63+
print("\nName of views in {}: ".format(sample_workbook.name))
6264
print([view.name for view in sample_workbook.views])
6365

6466
# Populate connections
6567
server.workbooks.populate_connections(sample_workbook)
66-
print("\nConnections for workbook: ")
68+
print("\nConnections for {}: ".format(sample_workbook.name))
6769
print(["{0}({1})".format(connection.id, connection.datasource_name)
6870
for connection in sample_workbook.connections])
6971

samples/move_workbook_projects.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,26 @@
99

1010
import tableauserverapi as TSA
1111
import argparse
12+
import getpass
1213
import logging
1314

1415
parser = argparse.ArgumentParser(description='Move one workbook from the default project to another.')
15-
parser.add_argument('server', help='server address')
16-
parser.add_argument('username', help='username to sign into server')
17-
parser.add_argument('password', help='password to sign into server')
18-
parser.add_argument('workbook_name', help='name of workbook to move')
19-
parser.add_argument('destination_project', help='name of project to move workbook into')
20-
parser.add_argument('--logging-level', choices=['debug', 'info', 'error'], default='error',
16+
parser.add_argument('--server', '-s', required=True, help='server address')
17+
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
18+
parser.add_argument('--workbook-name', '-w', required=True, help='name of workbook to move')
19+
parser.add_argument('--destination-project', '-d', required=True, help='name of project to move workbook into')
20+
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
2121
help='desired logging level (set to error by default)')
2222
args = parser.parse_args()
2323

24+
password = getpass.getpass("Password: ")
25+
2426
# Set logging level based on user input, or error by default
2527
logging_level = getattr(logging, args.logging_level.upper())
2628
logging.basicConfig(level=logging_level)
2729

2830
# Step 1: Sign in to server
29-
tableau_auth = TSA.TableauAuth(args.username, args.password)
31+
tableau_auth = TSA.TableauAuth(args.username, password)
3032
server = TSA.Server(args.server)
3133
with server.auth.sign_in(tableau_auth):
3234
# Step 2: Query workbook to move

samples/move_workbook_sites.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,28 @@
1111
import shutil
1212
import argparse
1313
import tempfile
14+
import getpass
1415
import logging
1516

1617
parser = argparse.ArgumentParser(description="Move one workbook from the"
1718
"default project of the default site to"
1819
"the default project of another site.")
19-
parser.add_argument('server', help='server address')
20-
parser.add_argument('username', help='username to sign into server')
21-
parser.add_argument('password', help='password to sign into server')
22-
parser.add_argument('workbook_name', help='name of workbook to move')
23-
parser.add_argument('destination_site', help='name of site to move workbook into')
24-
parser.add_argument('--logging-level', choices=['debug', 'info', 'error'], default='error',
20+
parser.add_argument('--server', '-s', required=True, help='server address')
21+
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
22+
parser.add_argument('--workbook-name', '-w', required=True, help='name of workbook to move')
23+
parser.add_argument('--destination-site', '-d', required=True, help='name of site to move workbook into')
24+
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
2525
help='desired logging level (set to error by default)')
2626
args = parser.parse_args()
2727

28+
password = getpass.getpass("Password: ")
29+
2830
# Set logging level based on user input, or error by default
2931
logging_level = getattr(logging, args.logging_level.upper())
3032
logging.basicConfig(level=logging_level)
3133

3234
# Step 1: Sign in to both sites on server
33-
tableau_auth = TSA.TableauAuth(args.username, args.password)
35+
tableau_auth = TSA.TableauAuth(args.username, password)
3436

3537
source_server = TSA.Server(args.server)
3638
dest_server = TSA.Server(args.server)

samples/publish_workbook.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,25 @@
1616

1717
import tableauserverapi as TSA
1818
import argparse
19+
import getpass
1920
import logging
2021

2122
parser = argparse.ArgumentParser(description='Publish a workbook to server.')
22-
parser.add_argument('server', help='server address')
23-
parser.add_argument('username', help='username to sign into server')
24-
parser.add_argument('password', help='password to sign into server')
25-
parser.add_argument('filepath', help='filepath to the workbook to publish')
26-
parser.add_argument('--logging-level', choices=['debug', 'info', 'error'], default='error',
23+
parser.add_argument('--server', '-s', required=True, help='server address')
24+
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
25+
parser.add_argument('--filepath', '-f', required=True, help='filepath to the workbook to publish')
26+
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
2727
help='desired logging level (set to error by default)')
2828
args = parser.parse_args()
2929

30+
password = getpass.getpass("Password: ")
31+
3032
# Set logging level based on user input, or error by default
3133
logging_level = getattr(logging, args.logging_level.upper())
3234
logging.basicConfig(level=logging_level)
3335

3436
# Step 1: Sign in to server.
35-
tableau_auth = TSA.TableauAuth(args.username, args.password)
37+
tableau_auth = TSA.TableauAuth(args.username, password)
3638
server = TSA.Server(args.server)
3739
with server.auth.sign_in(tableau_auth):
3840

samples/set_http_options.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313
import getpass
1414
import logging
1515

16-
parser = argparse.ArgumentParser(description='List workbooks on site.')
17-
parser.add_argument('server', help='server address')
18-
parser.add_argument('username', help='username to sign into server')
19-
parser.add_argument('--logging-level', choices=['debug', 'info', 'error'], default='error',
16+
parser = argparse.ArgumentParser(description='List workbooks on site, with option set to ignore SSL verification.')
17+
parser.add_argument('--server', '-s', required=True, help='server address')
18+
parser.add_argument('--username', '-u', required=True, help='username to sign into server')
19+
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
2020
help='desired logging level (set to error by default)')
2121
args = parser.parse_args()
2222

0 commit comments

Comments
 (0)
0