@@ -36,9 +36,16 @@ def main():
36
36
help = "desired logging level (set to error by default)" ,
37
37
)
38
38
# Options specific to this sample
39
+ group = parser .add_mutually_exclusive_group (required = False )
40
+ group .add_argument ("--thumbnails-user-id" , "-u" , help = "User ID to use for thumbnails" )
41
+ group .add_argument ("--thumbnails-group-id" , "-g" , help = "Group ID to use for thumbnails" )
42
+
43
+ parser .add_argument ("--workbook-name" , "-n" , help = "Name with which to publish the workbook" )
39
44
parser .add_argument ("--file" , "-f" , help = "local filepath of the workbook to publish" )
40
45
parser .add_argument ("--as-job" , "-a" , help = "Publishing asynchronously" , action = "store_true" )
41
46
parser .add_argument ("--skip-connection-check" , "-c" , help = "Skip live connection check" , action = "store_true" )
47
+ parser .add_argument ("--project" , help = "Project within which to publish the workbook" )
48
+ parser .add_argument ("--show-tabs" , help = "Publish workbooks with tabs displayed" , action = "store_true" )
42
49
43
50
args = parser .parse_args ()
44
51
@@ -50,9 +57,20 @@ def main():
50
57
tableau_auth = TSC .PersonalAccessTokenAuth (args .token_name , args .token_value , site_id = args .site )
51
58
server = TSC .Server (args .server , use_server_version = True )
52
59
with server .auth .sign_in (tableau_auth ):
53
- # Step 2: Get all the projects on server, then look for the default one.
54
- all_projects , pagination_item = server .projects .get ()
55
- default_project = next ((project for project in all_projects if project .is_default ()), None )
60
+ # Step2: Retrieve the project id, if a project name was passed
61
+ if args .project is not None :
62
+ req_options = TSC .RequestOptions ()
63
+ req_options .filter .add (
64
+ TSC .Filter (TSC .RequestOptions .Field .Name , TSC .RequestOptions .Operator .Equals , args .project )
65
+ )
66
+ projects = list (TSC .Pager (server .projects , req_options ))
67
+ if len (projects ) > 1 :
68
+ raise ValueError ("The project name is not unique" )
69
+ project_id = projects [0 ].id
70
+ else :
71
+ # Get all the projects on server, then look for the default one.
72
+ all_projects , pagination_item = server .projects .get ()
73
+ project_id = next ((project for project in all_projects if project .is_default ()), None ).id
56
74
57
75
connection1 = ConnectionItem ()
58
76
connection1 .server_address = "mssql.test.com"
@@ -67,10 +85,16 @@ def main():
67
85
all_connections .append (connection1 )
68
86
all_connections .append (connection2 )
69
87
70
- # Step 3: If default project is found, form a new workbook item and publish.
88
+ # Step 3: Form a new workbook item and publish.
71
89
overwrite_true = TSC .Server .PublishMode .Overwrite
72
- if default_project is not None :
73
- new_workbook = TSC .WorkbookItem (default_project .id )
90
+ if project_id is not None :
91
+ new_workbook = TSC .WorkbookItem (
92
+ project_id = project_id ,
93
+ name = args .workbook_name ,
94
+ show_tabs = args .show_tabs ,
95
+ thumbnails_user_id = args .thumbnails_user_id ,
96
+ thumbnails_group_id = args .thumbnails_group_id ,
97
+ )
74
98
if args .as_job :
75
99
new_job = server .workbooks .publish (
76
100
new_workbook ,
@@ -92,7 +116,7 @@ def main():
92
116
)
93
117
print (f"Workbook published. ID: { new_workbook .id } " )
94
118
else :
95
- error = "The default project could not be found."
119
+ error = "The destination project could not be found."
96
120
raise LookupError (error )
97
121
98
122
0 commit comments