8000 Extend `publish_datasource.py` sample to allow specifying a project n… · stevee954/server-client-python@cd36685 · GitHub
[go: up one dir, main page]

Skip to content

Commit cd36685

Browse files
authored
Extend publish_datasource.py sample to allow specifying a project name (tableau#888)
I don't have access to the `Default` project on my Tableau server. Still I want to be able to run this sample...
1 parent 7621389 commit cd36685

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

samples/publish_datasource.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ def main():
3535
parser.add_argument('--filepath', '-f', required=True, help='filepath to the datasource to publish')
3636
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
3737
help='desired logging level (set to error by default)')
38+
parser.add_argument('--project', help='Project within which to publish the datasource')
3839
parser.add_argument('--async', '-a', help='Publishing asynchronously', dest='async_', action='store_true')
3940
parser.add_argument('--conn-username', help='connection username')
4041
parser.add_argument('--conn-password', help='connection password')
@@ -55,9 +56,22 @@ def main():
5556
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
5657
server = TSC.Server(args.server, use_server_version=True)
5758
with server.auth.sign_in(tableau_auth):
58-
# Create a new datasource item to publish - empty project_id field
59-
# will default the publish to the site's default project
60-
new_datasource = TSC.DatasourceItem(project_id="")
59+
# Empty project_id field will default the publish to the site's default project
60+
project_id = ""
61+
62+
# Retrieve the project id, if a project name was passed
63+
if args.project is not None:
64+
req_options = TSC.RequestOptions()
65+
req_options.filter.add(TSC.Filter(TSC.RequestOptions.Field.Name,
66+
TSC.RequestOptions.Operator.Equals,
67+
args.project))
68+
projects = list(TSC.Pager(server.projects, req_options))
69+
if len(projects) > 1:
70+
raise ValueError("The project name is not unique")
71+
project_id = projects[0].id
72+
73+
# Create a new datasource item to publish
74+
new_datasource = TSC.DatasourceItem(project_id=project_id)
6175

6276
# Create a connection_credentials item if connection details are provided
6377
new_conn_creds = None

0 commit comments

Comments
 (0)
0