diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 000000000..656e169f7 --- /dev/null +++ b/.travis.yml @@ -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 . diff --git a/samples/explore_datasource.py b/samples/explore_datasource.py index a9ec5fc71..4c2fb5a6d 100644 --- a/samples/explore_datasource.py +++ b/samples/explore_datasource.py @@ -19,16 +19,15 @@ 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('-info', action='store_true', help='set this flag to show logging information on INFO level') -parser.add_argument('-debug', action='store_true', help='set this flag to show logging information on DEBUG level') parser.add_argument('-publish', '-p', metavar='FILEPATH', help='path to datasource to publish') parser.add_argument('-download', '-d', metavar='FILEPATH', help='path to save downloaded datasource') +parser.add_argument('--logging-level', choices=['debug', 'info', 'error'], default='error', + help='desired logging level (set to error by default)') args = parser.parse_args() -if args.debug: - logging.basicConfig(level=logging.DEBUG) -elif args.info: - logging.basicConfig(level=logging.INFO) +# 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 = TSA.TableauAuth(args.username, args.password) diff --git a/samples/explore_workbook.py b/samples/explore_workbook.py index da5e79169..d371a1b38 100644 --- a/samples/explore_workbook.py +++ b/samples/explore_workbook.py @@ -19,17 +19,16 @@ 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('-info', action='store_true', help='set this flag to show logging information on INFO level') -parser.add_argument('-debug', action='store_true', help='set this flag to show logging information on DEBUG level') parser.add_argument('-publish', '-p', metavar='FILEPATH', help='path to workbook to publish') parser.add_argument('-download', '-d', metavar='FILEPATH', help='path to save downloaded workbook') parser.add_argument('-preview-image', '-i', metavar='FILEPATH', help='path to save populated preview image') +parser.add_argument('--logging-level', choices=['debug', 'info', 'error'], defualt='error', + help='desired logging level (set to error by default)') args = parser.parse_args() -if args.debug: - logging.basicConfig(level=logging.DEBUG) -elif args.info: - logging.basicConfig(level=logging.INFO) +# 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 = TSA.TableauAuth(args.username, args.password) diff --git a/samples/move_workbook_projects.py b/samples/move_workbook_projects.py index 19722630e..e47d4f322 100644 --- a/samples/move_workbook_projects.py +++ b/samples/move_workbook_projects.py @@ -9,9 +9,7 @@ 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.') parser.add_argument('server', help='server address') @@ -19,8 +17,14 @@ 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) diff --git a/samples/move_workbook_sites.py b/samples/move_workbook_sites.py index 43ccd33cf..968f23aae 100644 --- a/samples/move_workbook_sites.py +++ b/samples/move_workbook_sites.py @@ -11,6 +11,7 @@ import shutil import argparse import tempfile +import logging parser = argparse.ArgumentParser(description="Move one workbook from the" "default project of the default site to" @@ -20,8 +21,14 @@ 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_site', help='name of site 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 both sites on server tableau_auth = TSA.TableauAuth(args.username, args.password) @@ -43,8 +50,18 @@ try: workbook_path = source_server.workbooks.download(all_workbooks[0].id, tmpdir) - # Step 4: Sign in to destination site + # Step 4: Check if destination site exists, then sign in to the site + pagination_info, all_sites = source_server.sites.get() + found_destination_site = any((True for site in all_sites if + args.destination_site.lower() == site.content_url.lower())) + if not found_destination_site: + error = "No site named {} found.".format(args.destination_site) + raise LookupError(error) + tableau_auth.site = args.destination_site + + # Signing into another site requires another server object + # because of the different auth token and site ID. with dest_server.auth.sign_in(tableau_auth): # Step 5: Find destination site's default project @@ -56,6 +73,10 @@ new_workbook = TSA.WorkbookItem(name=args.workbook_name, project_id=target_project.id) new_workbook = dest_server.workbooks.publish(new_workbook, workbook_path, mode=dest_server.PublishMode.Overwrite) + print("Successfully moved {0} ({1})".format(new_workbook.name, new_workbook.id)) + else: + error = "The default project could not be found." + raise LookupError(error) # Step 7: Delete workbook from source site and delete temp directory source_server.workbooks.delete(all_workbooks[0].id) diff --git a/samples/publish_workbook.py b/samples/publish_workbook.py index b3836d389..662b38323 100644 --- a/samples/publish_workbook.py +++ b/samples/publish_workbook.py @@ -16,14 +16,21 @@ import tableauserverapi as TSA import argparse +import logging parser = argparse.ArgumentParser(description='Publish a workbook to server.') 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('filepath', help='filepath to the workbook to publish') +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) @@ -39,4 +46,5 @@ new_workbook = server.workbooks.publish(new_workbook, args.filepath, server.PublishMode.Overwrite) print("Workbook published. ID: {0}".format(new_workbook.id)) else: - print("The default project could not be found.") + error = "The default project could not be found." + raise LookupError(error) diff --git a/samples/set_http_options.py b/samples/set_http_options.py index 487be46f0..f5ef02db0 100644 --- a/samples/set_http_options.py +++ b/samples/set_http_options.py @@ -11,14 +11,21 @@ import tableauserverapi as TSA import argparse import getpass +import logging parser = argparse.ArgumentParser(description='List workbooks on site.') parser.add_argument('server', help='server address') parser.add_argument('username', help='username to sign into server') +parser.add_argument('--logging-level', choices=['debug', 'info', 'error'], default='error', + help='desired logging level (set to error by default)') args = parser.parse_args() 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: Create required objects for sign in tableau_auth = TSA.TableauAuth(args.username, password) server = TSA.Server(args.server)