@@ -35,6 +35,7 @@ def main():
35
35
parser .add_argument ('--filepath' , '-f' , required = True , help = 'filepath to the datasource to publish' )
36
36
parser .add_argument ('--logging-level' , '-l' , choices = ['debug' , 'info' , 'error' ], default = 'error' ,
37
37
help = 'desired logging level (set to error by default)' )
38
+ parser .add_argument ('--project' , help = 'Project within which to publish the datasource' )
38
39
parser .add_argument ('--async' , '-a' , help = 'Publishing asynchronously' , dest = 'async_' , action = 'store_true' )
39
40
parser .add_argument ('--conn-username' , help = 'connection username' )
40
41
parser .add_argument ('--conn-password' , help = 'connection password' )
@@ -55,9 +56,22 @@ def main():
55
56
tableau_auth = TSC .PersonalAccessTokenAuth (args .token_name , args .token_value , site_id = args .site )
56
57
server = TSC .Server (args .server , use_server_version = True )
57
58
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 )
61
75
62
76
# Create a connection_credentials item if connection details are provided
63
77
new_conn_creds = None
0 commit comments