-
Notifications
You must be signed in to change notification settings - Fork 446
Enable add to schedule #244
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
graysonarts
merged 8 commits into
tableau:development
from
graysonarts:enable_add_to_schedule
Jan 16, 2018
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b35bfb5
Update Change Log
ad9a14d
initial commit
1cdde32
Making the code more generic so it works with workbooks or datasources
128b319
Adding ability to use datasources
65c7857
fix pep8 failures
graysonarts 9191c2a
Addressing Tyler's feedback about metaprogramming
graysonarts cbd78d8
Address error handling
graysonarts 4d82dce
Fixing a py3 difference
graysonarts 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
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,85 @@ | ||
| import argparse | ||
| import getpass | ||
| import logging | ||
|
|
||
| import tableauserverclient as TSC | ||
|
|
||
|
|
||
| def usage(args): | ||
| parser = argparse.ArgumentParser(description='Explore workbook functions supported by the Server API.') | ||
| parser.add_argument('--server', '-s', required=True, help='server address') | ||
| parser.add_argument('--username', '-u', required=True, help='username to sign into 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('--password', '-p', default=None) | ||
| group = parser.add_mutually_exclusive_group(required=True) | ||
| group.add_argument('--workbook', '-w') | ||
| group.add_argument('--datasource', '-d') | ||
| parser.add_argument('schedule') | ||
|
|
||
| return parser.parse_args(args) | ||
|
|
||
|
|
||
| def make_filter(**kwargs): | ||
| options = TSC.RequestOptions() | ||
| for item, value in kwargs.items(): | ||
| name = getattr(TSC.RequestOptions.Field, item) | ||
| options.filter.add(TSC.Filter(name, TSC.RequestOptions.Operator.Equals, value)) | ||
| return options | ||
|
|
||
|
|
||
| def get_workbook_by_name(server, name): | ||
| request_filter = make_filter(Name=name) | ||
| workbooks, _ = server.workbooks.get(request_filter) | ||
| assert len(workbooks) == 1 | ||
| return workbooks.pop() | ||
|
|
||
|
|
||
| def get_datasource_by_name(server, name): | ||
| request_filter = make_filter(Name=name) | ||
| datasources, _ = server.datasources.get(request_filter) | ||
| assert len(datasources) == 1 | ||
| return datasources.pop() | ||
|
|
||
|
|
||
| def get_schedule_by_name(server, name): | ||
| schedules = [x for x in TSC.Pager(server.schedules) if x.name == name] | ||
| assert len(schedules) == 1 | ||
| return schedules.pop() | ||
|
|
||
|
|
||
| def assign_to_schedule(server, workbook_or_datasource, schedule): | ||
| server.schedules.add_to_schedule(schedule.id, workbook_or_datasource) | ||
|
|
||
|
|
||
| def run(args): | ||
| password = args.password | ||
| if password is None: | ||
| password = getpass.getpass("Password: ") | ||
|
|
||
| # Set logging level based on user input, or error by default | ||
| logging_level = getattr(logging, args.logging_level.upper()) | ||
| logging.basicConfig(level=logging_level) | ||
|
|
||
| # Step 1: Sign in to server. | ||
| tableau_auth = TSC.TableauAuth(args.username, password) | ||
| server = TSC.Server(args.server, use_server_version=True) | ||
|
|
||
| with server.auth.sign_in(tableau_auth): | ||
| if args.workbook: | ||
| item = get_workbook_by_name(server, args.workbook) | ||
| else: | ||
| item = get_datasource_by_name(server, args.datasource) | ||
| schedule = get_schedule_by_name(server, args.schedule) | ||
|
|
||
| assign_to_schedule(server, item, schedule) | ||
|
|
||
|
|
||
| def main(): | ||
| import sys | ||
| args = usage(sys.argv[1:]) | ||
| run(args) | ||
|
|
||
|
|
||
| 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -209,6 +209,29 @@ def update_req(self, schedule_item): | |
| single_interval_element.attrib[expression] = value | ||
| return ET.tostring(xml_request) | ||
|
|
||
| def _add_to_req(self, id_, type_): | ||
| """ | ||
| <task> | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Man we should have done this for all the request factories, it's really nice.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah... hindsight... |
||
| <extractRefresh> | ||
| <workbook/datasource id="..."/> | ||
| </extractRefresh> | ||
| </task> | ||
|
|
||
| """ | ||
| xml_request = ET.Element('tsRequest') | ||
| task_element = ET.SubElement(xml_request, 'task') | ||
| refresh = ET.SubElement(task_element, 'extractRefresh') | ||
| workbook = ET.SubElement(refresh, type_) | ||
| workbook.attrib['id'] = id_ | ||
|
|
||
| return ET.tostring(xml_request) | ||
|
|
||
| def add_workbook_req(self, id_): | ||
| return self._add_to_req(id_, "workbook") | ||
|
|
||
| def add_datasource_req(self, id_): | ||
| return self._add_to_req(id_, "datasource") | ||
|
|
||
|
|
||
| class SiteRequest(object): | ||
| def update_req(self, site_item): | ||
|
|
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
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.
Uh oh!
There was an error while loading. Please reload this page.
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.
EDIT: I figured it out.
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.
👍