Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .travis.yml
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 .
11 changes: 5 additions & 6 deletions samples/explore_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Copy link
Copy Markdown
Contributor

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 -.

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)
Expand Down
11 changes: 5 additions & 6 deletions samples/explore_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
29 changes: 19 additions & 10 deletions samples/move_workbook_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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)
Expand All @@ -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)
23 changes: 22 additions & 1 deletion samples/move_workbook_sites.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Expand All @@ -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
Expand All @@ -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)
Expand Down
10 changes: 9 additions & 1 deletion samples/publish_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
7 changes: 7 additions & 0 deletions samples/set_http_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down