Repository navigation
#6/7/12 samples: error checking and logging capability #9
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
8e1040b
Add automated test runs via travis (#8)
963ac71
samples raise error if project or workbook not found
shinchris fb56e0b
corrected error message and added check to see if site exists before …
shinchris 3057b3d
added logging option for all samples
shinchris 9440536
updating based on code review comments
shinchris 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,17 @@ | ||
| language: python | ||
| python: | ||
| - "2.7" | ||
| - "3.3" | ||
| - "3.4" | ||
| - "3.5" | ||
| - "pypy" | ||
| # command to install dependencies | ||
| install: | ||
| - "pip install -e ." | ||
| # - "pip install pep8" | ||
| # command to run tests | ||
| script: | ||
| # Tests | ||
| - python setup.py test | ||
| # pep8 - disabled for now until we can scrub the files to make sure we pass before turning it on | ||
| # - pep8 . |
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 |
|---|---|---|
|
|
@@ -9,18 +9,22 @@ | |
|
|
||
| import tableauserverapi as TSA | ||
| import argparse | ||
|
|
||
| # import logging | ||
| # logging.basicConfig(level=logging.DEBUG) | ||
| import logging | ||
|
|
||
| parser = argparse.ArgumentParser(description='Move one workbook from the default project to another.') | ||
|
Contributor
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. It might be nice to allow people to set the logging level from the command line |
||
| parser.add_argument('server', help='server address') | ||
| parser.add_argument('username', help='username to sign into server') | ||
| parser.add_argument('password', help='password to sign into server') | ||
| parser.add_argument('workbook_name', help='name of workbook to move') | ||
| parser.add_argument('destination_project', help='name of project to move workbook into') | ||
| parser.add_argument('--logging-level', choices=['debug', 'info', 'error'], default='error', | ||
| help='desired logging level (set to error by default)') | ||
| 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) | ||
|
|
||
| # Step 1: Sign in to server | ||
| tableau_auth = TSA.TableauAuth(args.username, args.password) | ||
| server = TSA.Server(args.server) | ||
|
|
@@ -35,11 +39,16 @@ | |
| pagination_info, all_projects = server.projects.get() | ||
| dest_project = next((project for project in all_projects if project.name == args.destination_project), None) | ||
|
|
||
| # Step 4: Update workbook with new project id | ||
| if all_workbooks: | ||
| print("Old project: {}".format(all_workbooks[0].project_name)) | ||
| all_workbooks[0].project_id = dest_project.id | ||
| target_workbook = server.workbooks.update(all_workbooks[0]) | ||
| print("New project: {}".format(target_workbook.project_name)) | ||
| if dest_project is not None: | ||
| # Step 4: Update workbook with new project id | ||
| if all_workbooks: | ||
| print("Old project: {}".format(all_workbooks[0].project_name)) | ||
| all_workbooks[0].project_id = dest_project.id | ||
| target_workbook = server.workbooks.update(all_workbooks[0]) | ||
| print("New project: {}".format(target_workbook.project_name)) | ||
| else: | ||
| error = "No workbook named {} found.".format(args.workbook_name) | ||
| raise LookupError(error) | ||
| else: | ||
| print('No workbook named {} found.'.format(args.workbook_name)) | ||
| error = "No project named {} found.".format(args.destination_project) | ||
| raise LookupError(error) | ||
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
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.
I'm pretty sure you are fixing this in another feature branch, but consistency is good. Long names should always be
--, short names (single letters) should be-.