@@ -18,8 +18,12 @@ def main():
18
18
help = 'set to Default site by default' )
19
19
parser .add_argument ('--logging-level' , '-l' , choices = ['debug' , 'info' , 'error' ], default = 'error' ,
20
20
help = 'desired logging level (set to error by default)' )
21
- parser .add_argument ('--type' , '-t' , required = False , choices = ['site' , 'workbook' ],
21
+ parser .add_argument ('--type' , '-t' , required = False , choices = ['site' , 'workbook' , 'project_name' ,
22
+ 'project_id' , 'project_path' ],
22
23
help = 'type of content you want to update materialized views settings on' )
24
+ parser .add_argument ('--project-name' , '-pn' , required = False , help = 'name of the project' )
25
+ parser .add_argument ('--project-id' , '-pi' , required = False , help = "id of the project" )
26
+ parser .add_argument ('--project-path' , '-pp' , required = False , help = "path of the project" )
23
27
24
28
args = parser .parse_args ()
25
29
@@ -36,7 +40,7 @@ def main():
36
40
enable_materialized_views = args .mode == "enable"
37
41
38
42
if (args .type is None ) != (args .mode is None ):
39
- print ( "Use '--type <workbook/site > --mode <enable/disable>' to update materialized views settings." )
43
+ print "Use '--type <content type > --mode <enable/disable>' to update materialized views settings."
40
44
return
41
45
42
46
if args .type == 'site' :
@@ -45,10 +49,42 @@ def main():
45
49
elif args .type == 'workbook' :
46
50
update_workbook (args , enable_materialized_views , password , site_content_url )
47
51
52
+ elif args .type == 'project_name' :
53
+ update_project_by_name (args , enable_materialized_views , password , site_content_url )
54
+
55
+ elif args .type == 'project_id' :
56
+ update_project_by_id (args , enable_materialized_views , password , site_content_url )
57
+
58
+ elif args .type == 'project_path' :
59
+ update_project_by_path (args , enable_materialized_views , password , site_content_url )
60
+
48
61
if args .status :
49
62
show_materialized_views_status (args , password , site_content_url )
50
63
51
64
65
+ def find_project_path (project , all_projects , path ):
66
+ path = project .name + '/' + path
67
+ if project .parent_id is None :
68
+ return path
69
+ else :
70
+ find_project_path (all_projects [project .parent_id ], all_projects , path )
71
+
72
+
73
+ def get_project_paths (server , projects ):
74
+ # most likely user won't have too many projects so we store them in a dict to search
75
+ all_projects = {project .id : project for project in TSC .Pager (server .projects )}
76
+
77
+ result = dict ()
78
+ for project in projects :
79
+ result [find_project_path (project , all_projects , "" )] = project
80
+ return result
81
+
82
+
83
+ def print_paths (paths ):
84
+ for path in paths .keys ():
85
+ print path
86
+
87
+
52
88
def show_materialized_views_status (args , password , site_content_url ):
53
89
tableau_auth = TSC .TableauAuth (args .username , password , site_id = site_content_url )
54
90
server = TSC .Server (args .server , use_server_version = True )
@@ -73,6 +109,66 @@ def show_materialized_views_status(args, password, site_content_url):
73
109
print "Workbook:" , workbook .name , "from site:" , site .name
74
110
75
111
112
+ def update_project_by_path (args , enable_materialized_views , password , site_content_url ):
113
+ if args .project_path is None :
114
+ print "Use --project_path <project path> to specify the path of the project"
115
+ return
116
+ tableau_auth = TSC .TableauAuth (args .username , password , site_content_url )
117
+ server = TSC .Server (args .server , use_server_version = True )
118
+ project_name = args .project_path .split ('/' )
119
+ with server .auth .sign_in (tableau_auth ):
120
+ projects = [project for project in TSC .Pager (server .projects ) if project .name == project_name ]
121
+
122
+ if len (projects ) > 1 :
123
+ possible_paths = get_project_paths (server .projects )
124
+ update_project (possible_paths [args .project_path ], server , enable_materialized_views )
125
+ else :
126
+ update_project (projects [0 ], server , enable_materialized_views )
127
+
128
+
129
+ def update_project_by_id (args , enable_materialized_views , password , site_content_url ):
130
+ if args .project_id is None :
131
+ print "Use --project-id <project id> to specify the id of the project"
132
+ return
133
+ tableau_auth = TSC .TableauAuth (args .username , password , site_content_url )
134
+ server = TSC .Server (args .server , use_server_version = True )
135
+ with server .auth .sign_in (tableau_auth ):
136
+ for project in TSC .Pager (server .projects ):
137
+ if project .id == args .project_id :
138
+ update_project (project , server , enable_materialized_views )
139
+ break
140
+
141
+
142
+ def update_project_by_name (args , enable_materialized_views , password , site_content_url ):
143
+ if args .project_name is None :
144
+ print "Use --project-name <project name> to specify the name of the project"
145
+ return
146
+ tableau_auth = TSC .TableauAuth (args .username , password , site_content_url )
147
+ server = TSC .Server (args .server , use_server_version = True )
148
+ with server .auth .sign_in (tableau_auth ):
149
+ # get all projects with given name
150
+ projects = [project for project in TSC .Pager (server .projects ) if project .name == args .project_name ]
151
+
152
+ if len (projects ) > 1 :
153
+ possible_paths = get_project_paths (server , projects )
154
+ print "Project name is not unique, use '--project_path <path>' or '--project-id <project id>'"
155
+ print "Possible project paths:"
156
+ print_paths (possible_paths )
157
+ print '\n '
158
+ return
159
+ else :
160
+ update_project (projects [0 ], server , enable_materialized_views )
161
+
162
+
163
+ def update_project (project<
7A1C
/span>, server , enable_materialized_views ):
164
+ for workbook in TSC .Pager (server .workbooks ):
165
+ if workbook .project_id == project .id :
166
+ workbook .materialized_views_enabled = enable_materialized_views
167
+ server .workbooks .update (workbook )
168
+ print "Updated materialized views settings for project:" , project .name
169
+ print '\n '
170
+
171
+
76
172
def update_workbook (args , enable_materialized_views , password , site_content_url ):
77
173
tableau_auth = TSC .TableauAuth (args .username , password , site_id = site_content_url )
78
174
server = TSC .Server (args .server , use_server_version = True )
0 commit comments