8000 when update one project, update all the sub-project of this project too · prnka11/server-client-python@ad83f80 · GitHub
[go: up one dir, main page]

Skip to content

Commit ad83f80

Browse files
author
bzhang
committed
when update one project, update all the sub-project of this project too
1 parent 418af7d commit ad83f80

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

samples/materialize_workbooks.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,15 +170,23 @@ def update_project_by_name(args, materialized_views_config, password, site_conte
170170

171171

172172
def update_project(project, server, materialized_views_config):
173+
all_projects = list(TSC.Pager(server.projects))
174+
project_ids = find_project_ids_to_update(all_projects, project, server)
173175
for workbook in TSC.Pager(server.workbooks):
174-
if workbook.project_id == project.id:
176+
if workbook.project_id in project_ids:
175177
workbook.materialized_views_config = materialized_views_config
176178
server.workbooks.update(workbook)
177179

178180
print("Updated materialized views settings for project: {}".format(project.name))
179181
print('\n')
180182

181183

184+
def find_project_ids_to_update(all_projects, project, server):
185+
projects_to_update = []
186+
find_projects_to_update(project, server, all_projects, projects_to_update)
187+
return set([project_to_update.id for project_to_update in projects_to_update])
188+
189+
182190
def parse_workbook_path(file_path):
183191
# parse the list of project path of workbooks
184192
workbook_paths = open(file_path, 'r')
@@ -296,5 +304,16 @@ def assert_project_valid(project_name, projects):
296304
return True
297305

298306

307+
def find_projects_to_update(project, server, all_projects, projects_to_update):
308+
# Use recursion to find all the sub-projects and enable/disable the workbooks in them
309+
projects_to_update.append(project)
310+
children_projects = [child for child in all_projects if child.parent_id == project.id]
311+
if len(children_projects) == 0:
312+
return
313+
314+
for child in children_projects:
315+
find_projects_to_update(child, server, all_projects, projects_to_update)
316+
317+
299318
if __name__ == "__main__":
300319
main()

0 commit comments

Comments
 (0)
0