-
Notifications
You must be signed in to change notification settings - Fork 445
Add version awareness to site create/update methods #1068
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #### | ||
| # This script demonstrates how to use the Tableau Server Client | ||
| # to interact with sites. | ||
| #### | ||
|
|
||
| import argparse | ||
| import logging | ||
| import os.path | ||
| import sys | ||
|
|
||
| import tableauserverclient as TSC | ||
|
|
||
|
|
||
| def main(): | ||
|
|
||
| parser = argparse.ArgumentParser(description="Explore site updates by the Server API.") | ||
| # Common options; please keep those in sync across all samples | ||
| parser.add_argument("--server", "-s", required=True, help="server address") | ||
| parser.add_argument("--site", "-S", help="site name") | ||
| parser.add_argument( | ||
| "--token-name", "-p", required=True, help="name of the personal access token used to sign into the server" | ||
| ) | ||
| parser.add_argument( | ||
| "--token-value", "-v", required=True, help="value of the personal access token used to sign into the server" | ||
| ) | ||
| parser.add_argument( | ||
| "--logging-level", | ||
| "-l", | ||
| choices=["debug", "info", "error"], | ||
| default="error", | ||
| help="desired logging level (set to error by default)", | ||
| ) | ||
|
|
||
| parser.add_argument("--delete") | ||
| parser.add_argument("--create") | ||
| parser.add_argument("--url") | ||
| parser.add_argument("--new_site_name") | ||
| parser.add_argument("--user_quota") | ||
| parser.add_argument("--storage_quota") | ||
| parser.add_argument("--status") | ||
|
|
||
| args = parser.parse_args() | ||
|
|
||
| # Set logging level based on user input, or error by default | ||
| logging_level = getattr(logging, args.logging_level.upper()) | ||
| logging.basicConfig(level=logging_level) | ||
|
|
||
| # SIGN IN | ||
| tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) | ||
| server = TSC.Server(args.server, use_server_version=True) | ||
| new_site = None | ||
| with server.auth.sign_in(tableau_auth): | ||
| current_site = server.sites.get_by_id(server.site_id) | ||
|
|
||
| if args.delete: | ||
| print("You can only delete the site you are currently in") | ||
| print("Delete site `{}`?".format(current_site.name)) | ||
| # server.sites.delete(server.site_id) | ||
|
|
||
| elif args.create: | ||
| new_site = TSC.SiteItem(args.create, args.url or args.create) | ||
| site_item = server.sites.create(new_site) | ||
| print(site_item) | ||
| # to do anything further with the site, you need to log into it | ||
| # if a PAT is required, that means going to the UI to create one | ||
|
|
||
| else: | ||
| new_site = current_site | ||
| print(current_site, "current user quota:", current_site.user_quota) | ||
| print("Remember, you can only update the site you are currently in") | ||
| if args.url: | ||
| new_site.content_url = args.url | ||
| if args.user_quota: | ||
| new_site.user_quota = args.user_quota | ||
| try: | ||
| updated_site = server.sites.update(new_site) | ||
| print(updated_site, "new user quota:", updated_site.user_quota) | ||
| except TSC.ServerResponseError as e: | ||
| print(e) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this class (and the ones below) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be able to return more informative errors