コード例 #1
0
ファイル: login_dialog.py プロジェクト: simonebarbieri/pype
 def login_with_credentials(self, username, api_key):
     verification = credentials.check_credentials(username, api_key)
     if verification:
         credentials.save_credentials(username, api_key, False)
         credentials.set_env(username, api_key)
         self.set_credentials(username, api_key)
         self.login_changed.emit()
     return verification
コード例 #2
0
def run_event_server(ftrack_url, ftrack_user, ftrack_api_key,
                     ftrack_events_path, no_stored_credentials,
                     store_credentials, legacy, clockify_api_key,
                     clockify_workspace):
    if not no_stored_credentials:
        cred = credentials.get_credentials(ftrack_url)
        username = cred.get('username')
        api_key = cred.get('api_key')

    if clockify_workspace and clockify_api_key:
        os.environ["CLOCKIFY_WORKSPACE"] = clockify_workspace
        os.environ["CLOCKIFY_API_KEY"] = clockify_api_key

    # Check url regex and accessibility
    ftrack_url = check_ftrack_url(ftrack_url)
    if not ftrack_url:
        print('Exiting! < Please enter Ftrack server url >')
        return 1

    # Validate entered credentials
    if not validate_credentials(ftrack_url, username, api_key):
        print('Exiting! < Please enter valid credentials >')
        return 1

    if store_credentials:
        credentials.save_credentials(username, api_key, ftrack_url)

    # Set Ftrack environments
    os.environ["FTRACK_SERVER"] = ftrack_url
    os.environ["FTRACK_API_USER"] = username
    os.environ["FTRACK_API_KEY"] = api_key
    # TODO This won't work probably
    if ftrack_events_path:
        if isinstance(ftrack_events_path, (list, tuple)):
            ftrack_events_path = os.pathsep.join(ftrack_events_path)
        os.environ["FTRACK_EVENTS_PATH"] = ftrack_events_path

    if legacy:
        return legacy_server(ftrack_url)

    return main_loop(ftrack_url)
コード例 #3
0
def main(argv):
    '''
    There are 4 values neccessary for event server:
    1.) Ftrack url - "studio.ftrackapp.com"
    2.) Username - "my.username"
    3.) API key - "apikey-long11223344-6665588-5565"
    4.) Path/s to events - "X:/path/to/folder/with/events"

    All these values can be entered with arguments or environment variables.
    - arguments:
        "-ftrackurl {url}"
        "-ftrackuser {username}"
        "-ftrackapikey {api key}"
        "-ftrackeventpaths {path to events}"
    - environment variables:
        FTRACK_SERVER
        FTRACK_API_USER
        FTRACK_API_KEY
        FTRACK_EVENTS_PATH

    Credentials (Username & API key):
    - Credentials can be stored for auto load on next start
    - To *Store/Update* these values add argument "-storecred"
        - They will be stored to appsdir file when login is successful
    - To *Update/Override* values with enviromnet variables is also needed to:
        - *don't enter argument for that value*
        - add argument "-noloadcred" (currently stored credentials won't be loaded)

    Order of getting values:
        1.) Arguments are always used when entered.
            - entered values through args have most priority! (in each case)
        2.) Credentials are tried to load from appsdir file.
            - skipped when credentials were entered through args or credentials
                are not stored yet
            - can be skipped with "-noloadcred" argument
        3.) Environment variables are last source of values.
            - will try to get not yet set values from environments

    Best practice:
    - set environment variables FTRACK_SERVER & FTRACK_EVENTS_PATH
    - launch event_server_cli with args:
    ~/event_server_cli.py -ftrackuser "{username}" -ftrackapikey "{API key}" -storecred
    - next time launch event_server_cli.py only with set environment variables
        FTRACK_SERVER & FTRACK_EVENTS_PATH
    '''
    parser = argparse.ArgumentParser(description='Ftrack event server')
    parser.add_argument("-ftrackurl",
                        type=str,
                        metavar='FTRACKURL',
                        help=("URL to ftrack server where events should handle"
                              " (default from environment: $FTRACK_SERVER)"))
    parser.add_argument(
        "-ftrackuser",
        type=str,
        help=("Username should be the username of the user in ftrack"
              " to record operations against."
              " (default from environment: $FTRACK_API_USER)"))
    parser.add_argument("-ftrackapikey",
                        type=str,
                        help=("Should be the API key to use for authentication"
                              " (default from environment: $FTRACK_API_KEY)"))
    parser.add_argument(
        "-ftrackeventpaths",
        nargs='+',
        help=("List of paths where events are stored."
              " (default from environment: $FTRACK_EVENTS_PATH)"))
    parser.add_argument('-storecred',
                        help=("Entered credentials will be also stored"
                              " to apps dir for future usage"),
                        action="store_true")
    parser.add_argument('-noloadcred',
                        help="Load creadentials from apps dir",
                        action="store_true")
    parser.add_argument('-legacy',
                        help="Load creadentials from apps dir",
                        action="store_true")
    ftrack_url = os.environ.get('FTRACK_SERVER')
    username = os.environ.get('FTRACK_API_USER')
    api_key = os.environ.get('FTRACK_API_KEY')
    event_paths = os.environ.get('FTRACK_EVENTS_PATH')

    kwargs, args = parser.parse_known_args(argv)

    if kwargs.ftrackurl:
        ftrack_url = kwargs.ftrackurl

    if kwargs.ftrackeventpaths:
        event_paths = kwargs.ftrackeventpaths

    if not kwargs.noloadcred:
        cred = credentials.get_credentials(ftrack_url)
        username = cred.get('username')
        api_key = cred.get('api_key')

    if kwargs.ftrackuser:
        username = kwargs.ftrackuser

    if kwargs.ftrackapikey:
        api_key = kwargs.ftrackapikey

    legacy = kwargs.legacy
    # Check url regex and accessibility
    ftrack_url = check_ftrack_url(ftrack_url)
    if not ftrack_url:
        print('Exiting! < Please enter Ftrack server url >')
        return 1

    # Validate entered credentials
    if not validate_credentials(ftrack_url, username, api_key):
        print('Exiting! < Please enter valid credentials >')
        return 1

    # Process events path
    event_paths, not_found = process_event_paths(event_paths)
    if not_found:
        print('WARNING: These paths were not found: {}'.format(str(not_found)))
    if not event_paths:
        if not_found:
            print('ERROR: Any of entered paths is valid or can be accesible.')
        else:
            print('ERROR: Paths to events are not set. Exiting.')
        return 1

    if kwargs.storecred:
        credentials.save_credentials(username, api_key, ftrack_url)

    # Set Ftrack environments
    os.environ["FTRACK_SERVER"] = ftrack_url
    os.environ["FTRACK_API_USER"] = username
    os.environ["FTRACK_API_KEY"] = api_key
    os.environ["FTRACK_EVENTS_PATH"] = event_paths

    if legacy:
        return legacy_server(ftrack_url)

    return main_loop(ftrack_url)