def main():

    parser = argparse.ArgumentParser(description='Publish a workbook to server.')
    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('--filepath', '-f', required=True, help='computer filepath of the workbook to publish')
    parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',
                        help='desired logging level (set to error by default)')
    parser.add_argument('--as-job', '-a', help='Publishing asynchronously', action='store_true')
    parser.add_argument('--site', '-S', default='', help='id (contentUrl) of site to sign into')

    args = parser.parse_args()

    password = getpass.getpass("Password: "******"mssql.test.com"
        connection1.connection_credentials = ConnectionCredentials("test", "password", True)

        connection2 = ConnectionItem()
        connection2.server_address = "postgres.test.com"
        connection2.server_port = "5432"
        connection2.connection_credentials = ConnectionCredentials("test", "password", True)

        all_connections = list()
        all_connections.append(connection1)
        all_connections.append(connection2)

        # Step 3: If default project is found, form a new workbook item and publish.
        if default_project is not None:
            new_workbook = TSC.WorkbookItem(default_project.id)
            if args.as_job:
                new_job = server.workbooks.publish(new_workbook, args.filepath, overwrite_true,
                                                   connections=all_connections, as_job=args.as_job)
                print("Workbook published. JOB ID: {0}".format(new_job.id))
            else:
                new_workbook = server.workbooks.publish(new_workbook, args.filepath, overwrite_true,
                                                        connections=all_connections, as_job=args.as_job)
                print("Workbook published. ID: {0}".format(new_workbook.id))
        else:
            error = "The default project could not be found."
            raise LookupError(error)
def main():

    parser = argparse.ArgumentParser(
        description='Publish a workbook to server.')
    # 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)')
    # Options specific to this sample
    parser.add_argument('--file',
                        '-f',
                        required=True,
                        help='local filepath of the workbook to publish')
    parser.add_argument('--as-job',
                        '-a',
                        help='Publishing asynchronously',
                        action='store_true')
    parser.add_argument('--skip-connection-check',
                        '-c',
                        help='Skip live connection check',
                        action='store_true')

    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 = TSC.PersonalAccessTokenAuth(args.token_name,
                                               args.token_value,
                                               site_id=args.site)
    server = TSC.Server(args.server, use_server_version=True)
    with server.auth.sign_in(tableau_auth):

        # Step 2: Get all the projects on server, then look for the default one.
        all_projects, pagination_item = server.projects.get()
        default_project = next(
            (project for project in all_projects if project.is_default()),
            None)

        connection1 = ConnectionItem()
        connection1.server_address = "mssql.test.com"
        connection1.connection_credentials = ConnectionCredentials(
            "test", "password", True)

        connection2 = ConnectionItem()
        connection2.server_address = "postgres.test.com"
        connection2.server_port = "5432"
        connection2.connection_credentials = ConnectionCredentials(
            "test", "password", True)

        all_connections = list()
        all_connections.append(connection1)
        all_connections.append(connection2)

        # Step 3: If default project is found, form a new workbook item and publish.
        overwrite_true = TSC.Server.PublishMode.Overwrite
        if default_project is not None:
            new_workbook = TSC.WorkbookItem(default_project.id)
            if args.as_job:
                new_job = server.workbooks.publish(
                    new_workbook,
                    args.filepath,
                    overwrite_true,
                    connections=all_connections,
                    as_job=args.as_job,
                    skip_connection_check=args.skip_connection_check)
                print("Workbook published. JOB ID: {0}".format(new_job.id))
            else:
                new_workbook = server.workbooks.publish(
                    new_workbook,
                    args.filepath,
                    overwrite_true,
                    connections=all_connections,
                    as_job=args.as_job,
                    skip_connection_check=args.skip_connection_check)
                print("Workbook published. ID: {0}".format(new_workbook.id))
        else:
            error = "The default project could not be found."
            raise LookupError(error)
Пример #3
0
args = parser.parse_args()

token_value = input("Please enter token value:") #'G2YYOZ/bTgmJWUoAnmnQlQ==:ydeQWjbpdhEYsGppUPNYL0HpYS7L7q3F'
tableau_auth = TSC.PersonalAccessTokenAuth(args.tokenname, token_value, '')
overwrite_true = TSC.Server.PublishMode.Overwrite

server = TSC.Server(args.server, use_server_version = True)


with server.auth.sign_in(tableau_auth):

        # Step 2: Get all the projects on server, then look for the default one.
        all_projects, pagination_item = server.projects.get()
        default_project = next((project for project in all_projects if project.is_default()), None)

        connection1 = ConnectionItem()
        connection1.server_address = "mssql.test.com"
        connection1.connection_credentials = ConnectionCredentials("test", "password", True)

        connection2 = ConnectionItem()
        connection2.server_address = "postgres.test.com"
        connection2.server_port = "5432"
        connection2.connection_credentials = ConnectionCredentials("test", "password", True)

        all_connections = list()
        all_connections.append(connection1)
        all_connections.append(connection2)

        # Step 3: If default project is found, form a new workbook item and publish.
        if default_project is not None:
            new_workbook = TSC.WorkbookItem(default_project.id)
Пример #4
0
try:
    all_project_items, pagination_item = server.projects.get()
    projectId = [
        proj.id for proj in all_project_items
        if proj.name == deployed.container.name
    ][0]
    print "Found the Project [ %s ] under site [ %s ]" % (
        projectId, deployed.container.site.name)
except ServerResponseError as e:
    raise Exception(e.message)

try:
    # Creating all connections
    all_connections = list()
    for item in deployed.connections:
        temp_connection = ConnectionItem()
        temp_connection.server_address = item.serverAddress
        temp_connection.server_port = item.serverPort
        temp_connection.connection_credentials = ConnectionCredentials(
            item.username, item.password, True)
        all_connections.append(temp_connection)

    wb_item = TSC.WorkbookItem(name=deployed.workbookName,
                               project_id=projectId)
    wb_item._connections = all_connections
    # call the publish method with the workbook item
    wb_item = server.workbooks.publish(wb_item, deployed.file.path,
                                       deployed.publishMode)
    print "Successfully published workbook [%s] " % deployed.workbookName
except ServerResponseError as e:
    raise Exception(e.message)