8000 clean up use of sites · LehmD/server-client-python@0b49971 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0b49971

Browse files
committed
clean up use of sites
Remove some warnings that aren't really necessary, remove some print statements, add some logging for the sample.
1 parent ad78db4 commit 0b49971

File tree

4 files changed

+23
-23
lines changed

4 files changed

+23
-23
lines changed

samples/explore_site.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ def main():
3737
parser.add_argument("--new_site_name")
3838
parser.add_argument("--user_quota")
3939
parser.add_argument("--storage_quota")
40-
parser.add_argument("--status")
4140

4241
args = parser.parse_args()
4342

@@ -46,16 +45,20 @@ def main():
4645
logging.basicConfig(level=logging_level)
4746

4847
# SIGN IN
48+
print("Logging into `{}`".format(args.site))
4949
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
5050
server = TSC.Server(args.server, use_server_version=True)
51-
new_site = None
5251
with server.auth.sign_in(tableau_auth):
5352
current_site = server.sites.get_by_id(server.site_id)
53+
print(current_site)
54+
current_site = server.sites.get_by_content_url(args.site)
55+
print(current_site)
56+
current_site = server.sites.get_by_name(current_site.name)
57+
print(current_site)
5458

5559
if args.delete:
56-
print("You can only delete the site you are currently in")
57-
print("Delete site `{}`?".format(current_site.name))
58-
# server.sites.delete(server.site_id)
60+
print("Warning: You are deleting the site you are currently in")
61+
server.sites.delete(server.site_id)
5962

6063
elif args.create:
6164
new_site = TSC.SiteItem(args.create, args.url or args.create)
@@ -65,16 +68,23 @@ def main():
6568
# if a PAT is required, that means going to the UI to create one
6669

6770
else:
71+
print("Updating site...")
6872
new_site = current_site
69-
print(current_site, "current user quota:", current_site.user_quota)
70-
print("Remember, you can only update the site you are currently in")
71-
if args.url:
72-
new_site.content_url = args.url
7373
if args.user_quota:
7474
new_site.user_quota = args.user_quota
75+
if args.url:
76+
new_site.content_url = args.url
77+
else:
78+
new_site.content_url = current_site.content_url + "_updated"
79+
if args.new_site_name:
80+
new_site.name = args.new_site_name
81+
if args.storage_quota:
82+
new_site.storage_quota = args.storage_quota
7583
try:
7684
updated_site = server.sites.update(new_site)
77-
print(updated_site, "new user quota:", updated_site.user_quota)
85+
print(updated_site)
86+
if args.user_quota:
87+
print(updated_site, "new user quota:", updated_site.user_quota)
7888
except TSC.ServerResponseError as e:
7989
print(e)
8090

tableauserverclient/models/site_item.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,10 @@ def __str__(self):
2929
return (
3030
"<"
3131
+ __name__
32-
+ ": "
32+
+ " name: "
3333
+ (self.name or "unnamed")
34+
+ ", url:"
35+
+ (self.content_url or "(content-url not set)")
3436
+ ", "
3537
+ (self.id or "unknown-id")
3638
+ ", "

tableauserverclient/server/endpoint/sites_endpoint.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,8 @@ def get_by_name(self, site_name: str) -> SiteItem:
5050
if not site_name:
5151
error = "Site Name undefined."
5252
raise ValueError(error)
53-
print("Note: You can only work with the site for which you are currently authenticated")
5453
logger.info("Querying single site (Name: {0})".format(site_name))
5554
url = "{0}/{1}?key=name".format(self.baseurl, site_name)
56-
print(self.baseurl, url)
5755
server_response = self.get_request(url)
5856
return SiteItem.from_response(server_response.content, self.parent_srv.namespace)[0]
5957

@@ -63,9 +61,6 @@ def get_by_content_url(self, content_url: str) -> SiteItem:
6361
if content_url is None:
6462
error = "Content URL undefined."
6563
raise ValueError(error)
66-
if not self.parent_srv.baseurl.index(content_url) > 0:
67-
error = "You can only work with the site you are currently authenticated for"
68-
raise ValueError(error)
6964

7065
logger.info("Querying single site (Content URL: {0})".format(content_url))
7166
logger.debug("Querying other sites requires Server Admin permissions")
@@ -79,7 +74,6 @@ def update(self, site_item: SiteItem) -> SiteItem:
7974
if not site_item.id:
8075
error = "Site item missing ID."
8176
raise MissingRequiredFieldError(error)
82-
print(self.parent_srv.site_id, site_item.id)
8377
if not site_item.id == self.parent_srv.site_id:
8478
error = "You can only update the site you are currently authenticated for"
8579
raise ValueError(error)

tableauserverclient/server/request_factory.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -799,12 +799,6 @@ def set_versioned_flow_attributes(self, flows_all, flows_edit, flows_schedule, p
799799
if site_item.flows_enabled is not None:
800800
flows_edit = flows_edit or flows_all
801801
flows_schedule = flows_schedule or flows_all
802-
import warnings
803-
804-
warnings.warn(
805-
"FlowsEnabled has been removed and become two options:"
806-
" SchedulingFlowsEnabled and EditingFlowsEnabled"
807-
)
808802
if site_item.editing_flows_enabled is not None:
809803
site_element.attrib["editingFlowsEnabled"] = flows_edit
810804
if site_item.scheduling_flows_enabled is not None:

0 commit comments

Comments
 (0)
0