Python version.VERSION Examples

The following are 30 code examples of version.VERSION(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module version , or try the search function .
Example #1
Source File: vlcscheduler.py    From VLC-Scheduler with MIT License 8 votes vote down vote up
def main():
    logger.info('VLC Scheduler v%s started.' % version.VERSION)
    
    if sys.platform == 'win32':
        loop = asyncio.ProactorEventLoop()
        asyncio.set_event_loop(loop)
    
    loop = asyncio.get_event_loop()
    
    try:
        loop.run_until_complete(main_coro())
    except Exception as e:
        if config.DEBUG:
            logger.fatal(traceback.format_exc())
        else:
            logger.fatal(str(e))
    finally:
        loop.close()
        logger.info('VLC Scheduler stopped.') 
Example #2
Source File: move_workbook_server.py    From rest-api-samples with MIT License 6 votes vote down vote up
def get_workbook_id(server, auth_token, user_id, site_id, workbook_name):
    """
    Gets the id of the desired workbook to relocate.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'user_id'       ID of user with access to workbook
    'site_id'       ID of the site that the user is signed into
    'workbook_name' name of workbook to get ID of
    Returns the workbook id and the project id that contains the workbook.
    """
    url = server + "/api/{0}/sites/{1}/users/{2}/workbooks".format(VERSION, site_id, user_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    workbooks = xml_response.findall('.//t:workbook', namespaces=xmlns)
    for workbook in workbooks:
        if workbook.get('name') == workbook_name:
            return workbook.get('id')
    error = "Workbook named '{0}' not found.".format(workbook_name)
    raise LookupError(error) 
Example #3
Source File: move_workbook_server.py    From rest-api-samples with MIT License 6 votes vote down vote up
def delete_workbook(server, auth_token, site_id, workbook_id, workbook_filename):
    """
    Deletes the temp workbook file, and workbook from the source project.

    'server'            specified server address
    'auth_token'        authentication token that grants user access to API calls
    'site_id'           ID of the site that the user is signed into
    'workbook_id'       ID of workbook to delete
    'workbook_filename' filename of temp workbook file to delete
    """
    # Builds the request to delete workbook from the source project on server
    url = server + "/api/{0}/sites/{1}/workbooks/{2}".format(VERSION, site_id, workbook_id)
    server_response = requests.delete(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)

    # Remove the temp file created for the download
    os.remove(workbook_filename) 
Example #4
Source File: move_workbook_projects.py    From rest-api-samples with MIT License 6 votes vote down vote up
def get_workbook_id(server, auth_token, user_id, site_id, workbook_name):
    """
    Gets the id of the desired workbook to relocate.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'user_id'       ID of user with access to workbook
    'site_id'       ID of the site that the user is signed into
    'workbook_name' name of workbook to get ID of
    Returns the workbook id and the project id that contains the workbook.
    """
    url = server + "/api/{0}/sites/{1}/users/{2}/workbooks".format(VERSION, site_id, user_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    workbooks = xml_response.findall('.//t:workbook', namespaces=xmlns)
    for workbook in workbooks:
        if workbook.get('name') == workbook_name:
            source_project_id = workbook.find('.//t:project', namespaces=xmlns).get('id')
            return source_project_id, workbook.get('id')
    error = "Workbook named '{0}' not found.".format(workbook_name)
    raise LookupError(error) 
Example #5
Source File: users_by_group.py    From rest-api-samples with MIT License 6 votes vote down vote up
def get_users_in_group(server, auth_token, site_id, group_id, page_size, page_number):
    """
    Get all the users in the group using group id
    GET /api/api-version/sites/site-id/groups/group-id/users
    GET /api/api-version/sites/site-id/groups/group-id/users?pageSize=page-size&pageNumber=page-number
    """
    if page_size == 0:
        url = server + "/api/{0}/sites/{1}/groups/{2}/users".format(VERSION, site_id, group_id)
    else:
        url = server + "/api/{0}/sites/{1}/groups/{2}/users?pageSize={3}&pageNumber={4}".format(VERSION, site_id, group_id, page_size, page_number)

    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    #_check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))
    users = xml_response.findall('.//t:user', namespaces=XMLNS)
    return users 
Example #6
Source File: update_permission.py    From rest-api-samples with MIT License 6 votes vote down vote up
def get_user_id(server, auth_token, site_id, username_to_update):
    """
    Returns the user id of the user to update permissions for, if found.

    'server'                specified server address
    'auth_token'            authentication token that grants user access to API calls
    'site_id'               ID of the site that the user is signed into
    'username_to_update'    username to update permission for on server
    """
    url = server + "/api/{0}/sites/{1}/users".format(VERSION, site_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    server_response = ET.fromstring(_encode_for_display(server_response.text))

    # Find all user tags in the response and look for matching id
    users = server_response.findall('.//t:user', namespaces=xmlns)
    for user in users:
        if user.get('name') == username_to_update:
            return user.get('id')
    error = "User id for {0} not found".format(username_to_update)
    raise LookupError(error) 
Example #7
Source File: update_permission.py    From rest-api-samples with MIT License 6 votes vote down vote up
def get_workbooks(server, auth_token, user_id, site_id):
    """
    Queries all existing workbooks on the current site.

    'server'            specified server address
    'auth_token'        authentication token that grants user access to API calls
    'user_id'           ID of user with access to workbooks
    'site_id'           ID of the site that the user is signed into
    Returns tuples for each workbook, containing its id and name.
    """
    url = server + "/api/{0}/sites/{1}/users/{2}/workbooks".format(VERSION, site_id, user_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    server_response = ET.fromstring(_encode_for_display(server_response.text))

    # Find all workbook ids
    workbook_tags = server_response.findall('.//t:workbook', namespaces=xmlns)

    # Tuples to store each workbook information:(workbook_id, workbook_name)
    workbooks = [(workbook.get('id'), workbook.get('name')) for workbook in workbook_tags]
    if len(workbooks) == 0:
        error = "No workbooks found on this site"
        raise LookupError(error)
    return workbooks 
Example #8
Source File: update_permission.py    From rest-api-samples with MIT License 6 votes vote down vote up
def query_permission(server, auth_token, site_id, workbook_id, user_id):
    """
    Returns a list of all permissions for the specified user.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    'workbook_id'   ID of workbook to update permission in
    'user_id'       ID of the user to update
    """
    url = server + "/api/{0}/sites/{1}/workbooks/{2}/permissions".format(VERSION, site_id, workbook_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    server_response = _encode_for_display(server_response.text)

    # Reads and parses the response
    parsed_response = ET.fromstring(server_response)

    # Find all the capabilities for a specific user
    capabilities = parsed_response.findall('.//t:granteeCapabilities', namespaces=xmlns)
    for capability in capabilities:
        user = capability.find('.//t:user', namespaces=xmlns)
        if user is not None and user.get('id') == user_id:
            return capability.findall('.//t:capability', namespaces=xmlns)
    return None 
Example #9
Source File: user_permission_audit.py    From rest-api-samples with MIT License 6 votes vote down vote up
def delete_permission(server, auth_token, site_id, workbook_id, user_id, permission_name, existing_mode):
    """
    Deletes a specific permission from the workbook.

    'server'            specified server address
    'auth_token'        authentication token that grants user access to API calls
    'site_id'           ID of the site that the user is signed into
    'workbook_id'       ID of workbook to audit permission in
    'user_id'           ID of the user to audit
    'permission_name'   name of permission to add or update
    'existing_mode'     is the mode of the permission already set for the workbook
    """
    url = server + "/api/{0}/sites/{1}/workbooks/{2}/permissions/users/{3}/{4}/{5}".format(VERSION,
                                                                                           site_id,
                                                                                           workbook_id,
                                                                                           user_id,
                                                                                           permission_name,
                                                                                           existing_mode)
    server_response = requests.delete(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return 
Example #10
Source File: user_permission_audit.py    From rest-api-samples with MIT License 6 votes vote down vote up
def get_user_id(server, auth_token, site_id, username_to_audit):
    """
    Returns the user id of the user to audit permissions for, if found.

    'server'                specified server address
    'auth_token'            authentication token that grants user access to API calls
    'site_id'               ID of the site that the user is signed into
    'username_to_audit'     username to audit permission for on server
    """
    url = server + "/api/{0}/sites/{1}/users".format(VERSION, site_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    server_response = ET.fromstring(_encode_for_display(server_response.text))

    # Find all user tags in the response and look for matching id
    users = server_response.findall('.//t:user', namespaces=xmlns)
    for user in users:
        if user.get('name') == username_to_audit:
            return user.get('id')
    error = "User id for {0} not found".format(username_to_audit)
    raise LookupError(error) 
Example #11
Source File: user_permission_audit.py    From rest-api-samples with MIT License 6 votes vote down vote up
def get_workbook_id(server, auth_token, user_id, site_id, workbook_name):
    """
    Gets the id of the desired workbook to relocate.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'user_id'       ID of user with access to workbooks
    'site_id'       ID of the site that the user is signed into
    'workbook_name' name of workbook to get ID of
    Returns the workbook id and the project id that contains the workbook.
    """
    url = server + "/api/{0}/sites/{1}/users/{2}/workbooks".format(VERSION, site_id, user_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    # Find all workbooks in the site and look for the desired one
    workbooks = xml_response.findall('.//t:workbook', namespaces=xmlns)
    for workbook in workbooks:
        if workbook.get('name') == workbook_name:
            return workbook.get('id')
    error = "Workbook named '{0}' not found.".format(workbook_name)
    raise LookupError(error) 
Example #12
Source File: update_permission.py    From rest-api-samples with MIT License 6 votes vote down vote up
def delete_permission(server, auth_token, site_id, workbook_id, user_id, permission_name, existing_mode):
    """
    Deletes a specific permission from the workbook.

    'server'            specified server address
    'auth_token'        authentication token that grants user access to API calls
    'site_id'           ID of the site that the user is signed into
    'workbook_id'       ID of workbook to update permission in
    'user_id'           ID of the user to update
    'permission_name'   name of permission to update
    'existing_mode'     is the existing mode for the permission
    """
    url = server + "/api/{0}/sites/{1}/workbooks/{2}/permissions/users/{3}/{4}/{5}".format(VERSION,
                                                                                           site_id,
                                                                                           workbook_id,
                                                                                           user_id,
                                                                                           permission_name,
                                                                                           existing_mode)
    print("\tDeleting existing permission")
    server_response = requests.delete(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return 
Example #13
Source File: move_workbook_sites.py    From rest-api-samples with MIT License 6 votes vote down vote up
def get_workbook_id(server, auth_token, user_id, site_id, workbook_name):
    """
    Gets the id of the desired workbook to relocate.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'user_id'       ID of the user with access to workbooks
    'site_id'       ID of the site that the user is signed into
    'workbook_name' name of workbook to get ID of
    Returns the workbook id and the project id that contains the workbook.
    """
    url = server + "/api/{0}/sites/{1}/users/{2}/workbooks".format(VERSION, site_id, user_id)
    server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    workbooks = xml_response.findall('.//t:workbook', namespaces=xmlns)
    for workbook in workbooks:
        if workbook.get('name') == workbook_name:
            return workbook.get('id')
    error = "Workbook named '{0}' not found.".format(workbook_name)
    raise LookupError(error) 
Example #14
Source File: fb2mobi-gui.py    From fb2mobi with MIT License 5 votes vote down vote up
def __init__(self, parent):
        super(AboutDialog, self).__init__(parent)
        self.setupUi(self)

        image = QPixmap(':/Images/icon128.png')
        self.labelImage.setPixmap(image)
        self.labelVersion.setText(version.VERSION)
        self.labelUIVersion.setText(ui.ui_version.VERSION)

        self.setFixedSize(self.size()) 
Example #15
Source File: compile.py    From dcc with GNU General Public License v3.0 5 votes vote down vote up
def get_wrapper_tar_source(options):
	wrapper_source = ''.join(pkgutil.get_data('src', f).decode('utf8') for f in ['dcc_main.c', 'dcc_dual_sanitizers.c', 'dcc_util.c', 'dcc_check_output.c'])

	wrapper_source = wrapper_source.replace('__PATH__', options.dcc_path)
	wrapper_source = wrapper_source.replace('__DCC_VERSION__', '"' + VERSION + '"')
	wrapper_source = wrapper_source.replace('__HOSTNAME__', '"' +  platform.node() + '"')
	wrapper_source = wrapper_source.replace('__CLANG_VERSION__', '"%s"' % options.clang_version)
	wrapper_source = wrapper_source.replace('__SUPRESSIONS_FILE__', options.suppressions_file)
	wrapper_source = wrapper_source.replace('__STACK_USE_AFTER_RETURN__', "1" if options.stack_use_after_return else "0")
	wrapper_source = wrapper_source.replace('__CHECK_OUTPUT__', "1" if options.check_output else "0")
	wrapper_source = wrapper_source.replace('__WRAP_POSIX_SPAWN__', "1" if options.valgrind_fix_posix_spawn else "0")
	wrapper_source = wrapper_source.replace('__CLANG_VERSION_MAJOR__', str(options.clang_version_major))
	wrapper_source = wrapper_source.replace('__CLANG_VERSION_MINOR__', str(options.clang_version_minor))
	wrapper_source = wrapper_source.replace('__N_SANITIZERS__', str(len(options.sanitizers)))
	wrapper_source = wrapper_source.replace('__SANITIZER_1__', options.sanitizers[0].upper())

	if len(options.sanitizers) > 1:
		wrapper_source = wrapper_source.replace('__SANITIZER_2__', options.sanitizers[1].upper())

	if options.embed_source:
		tar_n_bytes, tar_source = source_for_embedded_tarfile(options)
		watcher = fr"python3 -E -c \"import io,os,sys,tarfile,tempfile\n\
with tempfile.TemporaryDirectory() as temp_dir:\n\
 buffer = io.BytesIO(sys.stdin.buffer.raw.read({tar_n_bytes}))\n\
 if len(buffer.getbuffer()) == {tar_n_bytes}:\n\
  tarfile.open(fileobj=buffer, bufsize={tar_n_bytes}, mode='r|xz').extractall(temp_dir)\n\
  os.chdir(temp_dir)\n\
  exec(open('watch_valgrind.py').read())\n\
\""
	else:
		# hopefully obsolete option to invoke Python in dcc rather than use Python embeded in binary
		tar_n_bytes, tar_source = 0, ''
		watcher = options.dcc_path +  "--watch-stdin-for-valgrind-errors"

	wrapper_source = wrapper_source.replace('__MONITOR_VALGRIND__', watcher)

	return wrapper_source, tar_source 
Example #16
Source File: epycyzm.py    From epycyzm with MIT License 5 votes vote down vote up
def subscribe(self):
        ret = yield from self.call('mining.subscribe', VERSION, None, self.server.host, self.server.port)
        nonce1 = binascii.unhexlify(ret['result'][1])
        print("Successfully subscribed for jobs")
        self.solvers.set_nonce(nonce1)
        return nonce1 
Example #17
Source File: update_permission.py    From rest-api-samples with MIT License 5 votes vote down vote up
def sign_out(server, auth_token):
    """
    Destroys the active session and invalidates authentication token.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    """
    url = server + "/api/{0}/auth/signout".format(VERSION)
    server_response = requests.post(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return 
Example #18
Source File: update_permission.py    From rest-api-samples with MIT License 5 votes vote down vote up
def sign_in(server, username, password, site=""):
    """
    Signs in to the server specified with the given credentials

    'server'   specified server address
    'username' is the name (not ID) of the user to sign in as.
               Note that most of the functions in this example require that the user
               have server administrator permissions.
    'password' is the password for the user.
    'site'     is the ID (as a string) of the site on the server to sign in to. The
               default is "", which signs in to the default site.
    Returns the authentication token and the site ID.
    """
    url = server + "/api/{0}/auth/signin".format(VERSION)

    # Builds the request
    xml_request = ET.Element('tsRequest')
    credentials_element = ET.SubElement(xml_request, 'credentials', name=username, password=password)
    ET.SubElement(credentials_element, 'site', contentUrl=site)
    xml_request = ET.tostring(xml_request)

    # Make the request to server
    server_response = requests.post(url, data=xml_request)
    _check_status(server_response, 200)

    # ASCII encode server response to enable displaying to console
    server_response = _encode_for_display(server_response.text)

    # Reads and parses the response
    parsed_response = ET.fromstring(server_response)

    # Gets the auth token and site ID
    token = parsed_response.find('t:credentials', namespaces=xmlns).get('token')
    site_id = parsed_response.find('.//t:site', namespaces=xmlns).get('id')
    user_id = parsed_response.find('.//t:user', namespaces=xmlns).get('id')
    return token, site_id, user_id 
Example #19
Source File: move_workbook_projects.py    From rest-api-samples with MIT License 5 votes vote down vote up
def get_project_id(server, auth_token, site_id, dest_project):
    """
    Returns the project ID of the desired project

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    'dest_project'  name of destination project to get ID of
    """
    page_num, page_size = 1, 100   # Default paginating values

    # Builds the request
    url = server + "/api/{0}/sites/{1}/projects".format(VERSION, site_id)
    paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page_num)
    server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    # Used to determine if more requests are required to find all projects on server
    total_projects = int(xml_response.find('t:pagination', namespaces=xmlns).get('totalAvailable'))
    max_page = int(math.ceil(total_projects / page_size))

    projects = xml_response.findall('.//t:project', namespaces=xmlns)

    # Continue querying if more projects exist on the server
    for page in range(2, max_page + 1):
        paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page)
        server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
        _check_status(server_response, 200)
        xml_response = ET.fromstring(_encode_for_display(server_response.text))
        projects.extend(xml_response.findall('.//t:project', namespaces=xmlns))

    # Look through all projects to find the 'default' one
    for project in projects:
        if project.get('name') == dest_project:
            return project.get('id')
    error = "Project named '{0}' was not found on server".format(dest_project)
    raise LookupError(error) 
Example #20
Source File: japonicus.py    From japonicus with MIT License 5 votes vote down vote up
def launchWebEvolutionaryInfo():
    print("WEBSERVER MODE")
    webpageTitle = "japonicus evolutionary statistics - v%.2f" % VERSION
    webApp, webServer = promoterz.webServer.core.build_server(webpageTitle)

    webServerProcess = Thread(
        target=waitress.serve,
        kwargs={
            "app": webServer,
            "listen": "0.0.0.0:8182"
        }
    )

    webServerProcess.start()
    return webApp 
Example #21
Source File: move_workbook_projects.py    From rest-api-samples with MIT License 5 votes vote down vote up
def sign_out(server, auth_token):
    """
    Destroys the active session and invalidates authentication token.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    """
    url = server + "/api/{0}/auth/signout".format(VERSION)
    server_response = requests.post(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return 
Example #22
Source File: move_workbook_projects.py    From rest-api-samples with MIT License 5 votes vote down vote up
def sign_in(server, username, password, site=""):
    """
    Signs in to the server specified with the given credentials

    'server'   specified server address
    'name'     is the name (not ID) of the user to sign in as.
               Note that most of the functions in this example require that the user
               have server administrator permissions.
    'password' is the password for the user.
    'site'     is the ID (as a string) of the site on the server to sign in to. The
               default is "", which signs in to the default site.
    Returns the authentication token and the site ID.
    """
    url = server + "/api/{0}/auth/signin".format(VERSION)

    # Builds the request
    xml_request = ET.Element('tsRequest')
    credentials_element = ET.SubElement(xml_request, 'credentials', name=username, password=password)
    ET.SubElement(credentials_element, 'site', contentUrl=site)
    xml_request = ET.tostring(xml_request)

    # Make the request to server
    server_response = requests.post(url, data=xml_request)
    _check_status(server_response, 200)

    # ASCII encode server response to enable displaying to console
    server_response = _encode_for_display(server_response.text)

    # Reads and parses the response
    parsed_response = ET.fromstring(server_response)

    # Gets the auth token and site ID
    token = parsed_response.find('t:credentials', namespaces=xmlns).get('token')
    site_id = parsed_response.find('.//t:site', namespaces=xmlns).get('id')
    user_id = parsed_response.find('.//t:user', namespaces=xmlns).get('id')
    return token, site_id, user_id 
Example #23
Source File: main.py    From aws-instance-scheduler with Apache License 2.0 5 votes vote down vote up
def lambda_handler(event, context):
    try:
        dt = datetime.utcnow()
        log_stream = LOG_STREAM.format(dt.year, dt.month, dt.day)
        result = {}
        with Logger(logstream=log_stream, buffersize=20, context=context,
                    debug=util.as_bool(os.getenv(configuration.ENV_TRACE, False))) as logger:

            logger.info("InstanceScheduler, version {}".format(VERSION))

            logger.debug("Event is {}", util.safe_json(event, indent=3))

            for handler_type in [SchedulerRequestHandler,
                                 SchedulerSetupHandler,
                                 ScheduleResourceHandler,
                                 AdminCliRequestHandler,
                                 CloudWatchEventHandler]:

                if handler_type.is_handling_request(event):
                    start = time()
                    handler = handler_type(event, context)
                    logger.info("Handler is {}".format(handler_type.__name__))
                    try:
                        result = handler.handle_request()
                    except Exception as e:
                        logger.error("Error handling request {} by handler {}: ({})\n{}", json.dumps(event), handler_type.__name__,
                                     e, traceback.format_exc())
                    execution_time = round(float((time() - start)), 3)
                    logger.info("Handling took {} seconds", execution_time)
                    return result
            logger.debug("Request was not handled, no handler was able to handle this type of request {}", json.dumps(event))
    finally:
        configuration.unload_scheduler_configuration() 
Example #24
Source File: move_workbook_server.py    From rest-api-samples with MIT License 5 votes vote down vote up
def get_default_project_id(server, auth_token, site_id):
    """
    Returns the project ID for the 'default' project on the Tableau server.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    """
    page_num, page_size = 1, 100  # Default paginating values

    # Builds the request
    url = server + "/api/{0}/sites/{1}/projects".format(VERSION, site_id)
    paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page_num)
    server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    # Used to determine if more requests are required to find all projects on server
    total_projects = int(xml_response.find('t:pagination', namespaces=xmlns).get('totalAvailable'))
    max_page = int(math.ceil(total_projects / page_size))

    projects = xml_response.findall('.//t:project', namespaces=xmlns)

    # Continue querying if more projects exist on the server
    for page in range(2, max_page + 1):
        paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page)
        server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
        _check_status(server_response, 200)
        xml_response = ET.fromstring(_encode_for_display(server_response.text))
        projects.extend(xml_response.findall('.//t:project', namespaces=xmlns))

    # Look through all projects to find the 'default' one
    for project in projects:
        if project.get('name') == 'default' or project.get('name') == 'Default':
            return project.get('id')
    print("\tProject named 'default' was not found in {0}".format(server)) 
Example #25
Source File: move_workbook_sites.py    From rest-api-samples with MIT License 5 votes vote down vote up
def sign_in(server, username, password, site=""):
    """
    Signs in to the server specified with the given credentials

    'server'   specified server address
    'username' is the name (not ID) of the user to sign in as.
               Note that most of the functions in this example require that the user
               have server administrator permissions.
    'password' is the password for the user.
    'site'     is the ID (as a string) of the site on the server to sign in to. The
               default is "", which signs in to the default site.
    Returns the authentication token and the site ID.
    """
    url = server + "/api/{0}/auth/signin".format(VERSION)

    # Builds the request
    xml_request = ET.Element('tsRequest')
    credentials_element = ET.SubElement(xml_request, 'credentials', name=username, password=password)
    ET.SubElement(credentials_element, 'site', contentUrl=site)
    xml_request = ET.tostring(xml_request)

    # Make the request to server
    server_response = requests.post(url, data=xml_request)
    _check_status(server_response, 200)

    # ASCII encode server response to enable displaying to console
    server_response = _encode_for_display(server_response.text)

    # Reads and parses the response
    parsed_response = ET.fromstring(server_response)

    # Gets the auth token and site ID
    token = parsed_response.find('t:credentials', namespaces=xmlns).get('token')
    site_id = parsed_response.find('.//t:site', namespaces=xmlns).get('id')
    user_id = parsed_response.find('.//t:user', namespaces=xmlns).get('id')
    return token, site_id, user_id 
Example #26
Source File: move_workbook_server.py    From rest-api-samples with MIT License 5 votes vote down vote up
def sign_out(server, auth_token):
    """
    Destroys the active session and invalidates authentication token.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    """
    url = server + "/api/{0}/auth/signout".format(VERSION)
    server_response = requests.post(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return 
Example #27
Source File: move_workbook_sites.py    From rest-api-samples with MIT License 5 votes vote down vote up
def sign_out(server, auth_token):
    """
    Destroys the active session and invalidates authentication token.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    """
    url = server + "/api/{0}/auth/signout".format(VERSION)
    server_response = requests.post(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)
    return 
Example #28
Source File: move_workbook_sites.py    From rest-api-samples with MIT License 5 votes vote down vote up
def start_upload_session(server, auth_token, site_id):
    """
    Creates a POST request that initiates a file upload session.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    Returns a session ID that is used by subsequent functions to identify the upload session.
    """
    url = server + "/api/{0}/sites/{1}/fileUploads".format(VERSION, site_id)
    server_response = requests.post(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 201)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))
    return xml_response.find('t:fileUpload', namespaces=xmlns).get('uploadSessionId') 
Example #29
Source File: move_workbook_sites.py    From rest-api-samples with MIT License 5 votes vote down vote up
def get_default_project_id(server, auth_token, site_id):
    """
    Returns the project ID for the 'default' project on the Tableau server.

    'server'        specified server address
    'auth_token'    authentication token that grants user access to API calls
    'site_id'       ID of the site that the user is signed into
    """
    page_num, page_size = 1, 100   # Default paginating values

    # Builds the request
    url = server + "/api/{0}/sites/{1}/projects".format(VERSION, site_id)
    paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page_num)
    server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 200)
    xml_response = ET.fromstring(_encode_for_display(server_response.text))

    # Used to determine if more requests are required to find all projects on server
    total_projects = int(xml_response.find('t:pagination', namespaces=xmlns).get('totalAvailable'))
    max_page = int(math.ceil(total_projects / page_size))

    projects = xml_response.findall('.//t:project', namespaces=xmlns)

    # Continue querying if more projects exist on the server
    for page in range(2, max_page + 1):
        paged_url = url + "?pageSize={0}&pageNumber={1}".format(page_size, page)
        server_response = requests.get(paged_url, headers={'x-tableau-auth': auth_token})
        _check_status(server_response, 200)
        xml_response = ET.fromstring(_encode_for_display(server_response.text))
        projects.extend(xml_response.findall('.//t:project', namespaces=xmlns))

    # Look through all projects to find the 'default' one
    for project in projects:
        if project.get('name') == 'default' or project.get('name') == 'Default':
            return project.get('id')
    error = "Project named 'default' was not found in destination site"
    raise LookupError(error) 
Example #30
Source File: move_workbook_sites.py    From rest-api-samples with MIT License 5 votes vote down vote up
def delete_workbook(server, auth_token, site_id, workbook_id):
    """
    Deletes the workbook from the source project.

    'server'            specified server address
    'auth_token'        authentication token that grants user access to API calls
    'site_id'           ID of the site that the user is signed into
    'workbook_id'       ID of workbook to delete
    """
    # Builds the request to delete workbook from the source project on server
    url = server + "/api/{0}/sites/{1}/workbooks/{2}".format(VERSION, site_id, workbook_id)
    server_response = requests.delete(url, headers={'x-tableau-auth': auth_token})
    _check_status(server_response, 204)