@@ -21,7 +21,8 @@ def main():
21
21
parser .add_argument ('--type' , '-t' , required = False , choices = ['site' , 'workbook' , 'project_name' ,
22
22
'project_id' , 'project_path' ],
23
23
help = 'type of content you want to update materialized views settings on' )
24
- parser .add_argument ('--file-path' , '-fp' , required = False , help = 'path to a list of workbooks' )
24
+ parser .add_argument ('--path-list' , '-pl' , required = False , help = 'path to a list of workbook paths' )
25
+ parser .add_argument ('--name-list' , '-nl' , required = False , help = 'path to a list of workbook names' )
25
26
parser .add_argument ('--project-name' , '-pn' , required = False , help = 'name of the project' )
26
27
parser .add_argument ('--project-path' , '-pp' , required = False , help = "path of the project" )
27
28
@@ -168,16 +169,19 @@ def parse_workbook_path(file_path):
168
169
169
170
170
171
def update_workbook (args , enable_materialized_views , password , site_content_url ):
171
- if args .file_path is None :
172
- print ("Use '--file- path <file path >' to specify the path of a list of workbooks" )
172
+ if args .path_list is None and args . name_list is None :
173
+ print ("Use '--path-list <filename>' or '--name-list <filename >' to specify the path of a list of workbooks" )
173
174
print ('\n ' )
174
175
return False
175
176
tableau_auth = TSC .TableauAuth (args .username , password , site_id = site_content_url )
176
177
server = TSC .Server (args .server , use_server_version = True )
177
178
with server .auth .sign_in (tableau_auth ):
178
- workbook_path_mapping = parse_workbook_path (args .file_path )
179
- all_projects = {project .id : project for project in TSC .Pager (server .projects )}
180
- update_workbooks_by_paths (all_projects , enable_materialized_views , server , workbook_path_mapping )
179
+ if args .path_list is not None :
180
+ workbook_path_mapping = parse_workbook_path (args .path_list )
181
+ all_projects = {project .id : project for project in TSC .Pager (server .projects )}
182
+ update_workbooks_by_paths (all_projects , enable_materialized_views , server , workbook_path_mapping )
183
+ elif args .name_list is not None :
184
+ update_workbooks_by_names (args .name_list , server , enable_materialized_views )
181
185
return True
182
186
183
187
@@ -194,7 +198,22 @@ def update_workbooks_by_paths(all_projects, enable_materialized_views, server, w
194
198
workbook .materialized_views_enabled = enable_materialized_views
195
199
server .workbooks .update (workbook )
196
200
print ("Updated materialized views settings for workbook: {}" .format (path + '/' + workbook .name ))
197
- print ('\n ' )
201
+ print ('\n ' )
202
+
203
+
204
+ def update_workbooks_by_names (name_list , server , enable_materialized_views ):
205
+ workbook_names = open (name_list , 'r' )
206
+ for workbook_name in workbook_names :
207
+ req_option = TSC .RequestOptions ()
208
+ req_option .filter .add (TSC .Filter (TSC .RequestOptions .Field .Name ,
209
+ TSC .RequestOptions .Operator .Equals ,
210
+ workbook_name .rstrip ()))
211
+ workbooks = list (TSC .Pager (server .workbooks , req_option ))
212
+ for workbook in workbooks :
213
+ workbook .materialized_views_enabled = enable_materialized_views
214
+ server .workbooks .update (workbook )
215
+ print ("Updated materialized views settings for workbook: {}" .format (workbook .name ))
216
+ print ('\n ' )
198
217
199
218
200
219
def update_site (args , enable_materialized_views , password , site_content_url ):
0 commit comments