コード例 #1
0
def task_run(config, task_name, org, o, debug, debug_before, debug_after,
             no_prompt):

    # Get necessary configs
    org, org_config = config.get_org(org, fail_if_missing=False)
    task_config = getattr(config.project_config, "tasks__{}".format(task_name))
    if not task_config:
        raise TaskNotFoundError("Task not found: {}".format(task_name))

    # Get the class to look up options
    class_path = task_config.get("class_path")
    task_class = import_class(class_path)

    # Parse command line options and add to task config
    if o:
        if "options" not in task_config:
            task_config["options"] = {}
        for name, value in o:
            # Validate the option
            if name not in task_class.task_options:
                raise click.UsageError(
                    'Option "{}" is not available for task {}'.format(
                        name, task_name))

            # Override the option in the task config
            task_config["options"][name] = value

    task_config = TaskConfig(task_config)

    # Create and run the task
    try:
        task = task_class(config.project_config,
                          task_config,
                          org_config=org_config)

        if debug_before:
            import pdb

            pdb.set_trace()

        task()

        if debug_after:
            import pdb

            pdb.set_trace()

    except CumulusCIUsageError as e:
        # Usage error; report with usage line and no traceback
        exception = click.UsageError(str(e))
        handle_exception_debug(config, debug, throw_exception=exception)
    except (CumulusCIFailure, ScratchOrgException) as e:
        # Expected failure; report without traceback
        exception = click.ClickException(str(e) or e.__class__.__name__)
        handle_exception_debug(config, debug, throw_exception=exception)
    except Exception:
        # Unexpected exception; log to sentry and raise
        handle_exception_debug(config, debug, no_prompt=no_prompt)

    config.alert("Task complete: {}".format(task_name))
コード例 #2
0
ファイル: cci.py プロジェクト: shidatonglin/CumulusCI
def task_info(config, task_name):
    check_project_config(config)
    task_config = getattr(config.project_config, 'tasks__{}'.format(task_name))
    if not task_config:
        raise TaskNotFoundError('Task not found: {}'.format(task_name))

    task_config = TaskConfig(task_config)
    click.echo(rst2ansi(doc_task(task_name, task_config)))
コード例 #3
0
 def get_task(self, name):
     """ Returns a TaskConfig """
     config = getattr(self, "tasks__{}".format(name))
     if not config:
         error_msg = "Task not found: {}".format(name)
         suggestion = self.get_suggested_name(name, self.tasks)
         raise TaskNotFoundError(error_msg + suggestion)
     return TaskConfig(config)
コード例 #4
0
ファイル: CumulusCI.py プロジェクト: ti2nakr/CumulusCI
 def run_task(self, task_name, **options):
     """ Runs a named CumulusCI task for the current project with optional
         support for overriding task options via kwargs.
         
         Examples:
         | =Keyword= | =task_name= | =task_options=             | =comment=                        |
         | Run Task  | deploy      |                            | Run deploy with standard options |
         | Run Task  | deploy      | path=path/to/some/metadata | Run deploy with custom path      |
     """
     task_config = getattr(self.config.project_config,
                           'tasks__{}'.format(task_name))
     if not task_config:
         raise TaskNotFoundError('Task not found: {}'.format(task_name))
     class_path = task_config.get('class_path')
     task_class, task_config = self._init_task(class_path, options,
                                               task_config)
     return self._run_task(task_class, task_config)
コード例 #5
0
def task_info(config, task_name):
    check_project_config(config)
    task_config = getattr(config.project_config, 'tasks__{}'.format(task_name))
    if not task_config:
        raise TaskNotFoundError('Task not found: {}'.format(task_name))

    task_config = TaskConfig(task_config)
    click.echo(rst2ansi(doc_task(task_name, task_config)))
    return
    class_path = task_config.get('class_path')
    task_class = import_class(class_path)

    # General task info
    click.echo('Description: {}'.format(task_config.get('description')))
    click.echo('Class: {}'.format(task_config.get('class_path')))

    # Default options
    default_options = task_config.get('options', {})
    if default_options:
        click.echo('')
        click.echo('Default Option Values')
        for key, value in default_options.items():
            click.echo('    {}: {}'.format(key, value))

    # Task options
    task_options = getattr(task_class, 'task_options', {})
    if task_options:
        click.echo('')
        data = []
        headers = ['Option', 'Required', 'Description']
        for key, option in task_options.items():
            if option.get('required'):
                data.append((key, '*', option.get('description')))
            else:
                data.append((key, '', option.get('description')))
        table = Table(data, headers)
        click.echo(table)
コード例 #6
0
 def get_task(self, name):
     """ Returns a TaskConfig """
     config = getattr(self, "tasks__{}".format(name))
     if not config:
         raise TaskNotFoundError("Task not found: {}".format(name))
     return TaskConfig(config)
コード例 #7
0
def task_run(config, task_name, org, o, debug, debug_before, debug_after,
             no_prompt):
    # Check environment
    check_keychain(config)

    # Get necessary configs
    if org:
        org_config = config.project_config.get_org(org)
    else:
        org, org_config = config.project_config.keychain.get_default_org()
    if org_config:
        org_config = check_org_expired(config, org, org_config)
    task_config = getattr(config.project_config, 'tasks__{}'.format(task_name))
    if not task_config:
        raise TaskNotFoundError('Task not found: {}'.format(task_name))

    # Get the class to look up options
    class_path = task_config.get('class_path')
    task_class = import_class(class_path)

    # Parse command line options and add to task config
    if o:
        if 'options' not in task_config:
            task_config['options'] = {}
        for option in o:
            name = option[0]
            value = option[1]

            # Validate the option
            if name not in task_class.task_options:
                raise click.UsageError(
                    'Option "{}" is not available for task {}'.format(
                        name,
                        task_name,
                    ), )

            # Override the option in the task config
            task_config['options'][name] = value

    task_config = TaskConfig(task_config)
    exception = None

    # Create and run the task
    try:
        task = task_class(config.project_config,
                          task_config,
                          org_config=org_config)
    except TaskRequiresSalesforceOrg as e:
        exception = click.UsageError(
            'This task requires a salesforce org.  Use org default <name> to set a default org or pass the org name with the --org option'
        )
    except TaskOptionsError as e:
        exception = click.UsageError(e.message)
        handle_exception_debug(config, debug, e, throw_exception=exception)
    except Exception as e:
        handle_exception_debug(config, debug, e, no_prompt=no_prompt)

    if debug_before:
        import pdb
        pdb.set_trace()

    if not exception:
        try:
            task()
        except TaskOptionsError as e:
            exception = click.UsageError(e.message)
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except ApexTestException as e:
            exception = click.ClickException('Failed: ApexTestFailure')
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except BrowserTestFailure as e:
            exception = click.ClickException('Failed: BrowserTestFailure')
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except MetadataComponentFailure as e:
            exception = click.ClickException(
                'Failed: MetadataComponentFailure')
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except MetadataApiError as e:
            exception = click.ClickException('Failed: MetadataApiError')
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except ScratchOrgException as e:
            exception = click.ClickException('ScratchOrgException: {}'.format(
                e.message))
            handle_exception_debug(config, debug, e, throw_exception=exception)
        except Exception as e:
            handle_exception_debug(config, debug, e, no_prompt=no_prompt)

    if debug_after:
        import pdb
        pdb.set_trace()

    if exception:
        handle_sentry_event(config, no_prompt)
        raise exception
コード例 #8
0
ファイル: cci.py プロジェクト: gizmo96/CumulusCI
def task_run(config, task_name, org, o, debug, debug_before, debug_after,
             no_prompt):
    # Check environment
    config.check_keychain()

    # Get necessary configs
    org, org_config = config.get_org(org, fail_if_missing=False)
    task_config = getattr(config.project_config, "tasks__{}".format(task_name))
    if not task_config:
        raise TaskNotFoundError("Task not found: {}".format(task_name))

    # Get the class to look up options
    class_path = task_config.get("class_path")
    task_class = import_class(class_path)

    # Parse command line options and add to task config
    if o:
        if "options" not in task_config:
            task_config["options"] = {}
        for name, value in o:
            # Validate the option
            if name not in task_class.task_options:
                raise click.UsageError(
                    'Option "{}" is not available for task {}'.format(
                        name, task_name))

            # Override the option in the task config
            task_config["options"][name] = value

    task_config = TaskConfig(task_config)

    # Create and run the task
    try:
        task = task_class(config.project_config,
                          task_config,
                          org_config=org_config)

        if debug_before:
            import pdb

            pdb.set_trace()

        task()

        if debug_after:
            import pdb

            pdb.set_trace()

    except (TaskRequiresSalesforceOrg, TaskOptionsError) as e:
        # Usage error; report with usage line and no traceback
        exception = click.UsageError(e.message)
        handle_exception_debug(config, debug, throw_exception=exception)
    except (
            ApexTestException,
            BrowserTestFailure,
            MetadataComponentFailure,
            MetadataApiError,
            ScratchOrgException,
    ) as e:
        # Expected failure; report without traceback
        exception = click.ClickException("Failed: {}".format(
            e.__class__.__name__))
        handle_exception_debug(config, debug, throw_exception=exception)
    except Exception:
        # Unexpected exception; log to sentry and raise
        handle_exception_debug(config, debug, no_prompt=no_prompt)
コード例 #9
0
def task_run(config, task_name, org, o, debug):
    # Check environment
    check_keychain(config)

    # Get necessary configs
    if org:
        org_config = config.project_config.get_org(org)
    else:
        org, org_config = config.project_config.keychain.get_default_org()
    task_config = getattr(config.project_config, 'tasks__{}'.format(task_name))
    if not task_config:
        raise TaskNotFoundError('Task not found: {}'.format(task_name))

    # Get the class to look up options
    class_path = task_config.get('class_path')
    task_class = import_class(class_path)

    # Parse command line options and add to task config
    if o:
        if 'options' not in task_config:
            task_config['options'] = {}
        for option in o:
            name = option[0]
            value = option[1]

            # Validate the option
            if name not in task_class.task_options:
                raise click.UsageError(
                    'Option "{}" is not available for task {}'.format(
                        name,
                        task_name,
                    ), )

            # Override the option in the task config
            task_config['options'][name] = value

    task_config = TaskConfig(task_config)
    exception = None

    # Create and run the task
    try:
        task = task_class(config.project_config,
                          task_config,
                          org_config=org_config)
    except TaskRequiresSalesforceOrg as e:
        exception = click.UsageError(
            'This task requires a salesforce org.  Use org default <name> to set a default org or pass the org name with the --org option'
        )
    except TaskOptionsError as e:
        exception = click.UsageError(e.message)
    except Exception as e:
        if debug:
            import pdb
            import traceback
            traceback.print_exc()
            pdb.post_mortem()
        else:
            raise

    if not exception:
        try:
            task()
        except TaskOptionsError as e:
            exception = click.UsageError(e.message)
        except ApexTestException as e:
            exception = click.ClickException('Failed: ApexTestFailure')
        except MetadataComponentFailure as e:
            exception = click.ClickException(
                'Failed: MetadataComponentFailure')
        except MetadataApiError as e:
            exception = click.ClickException('Failed: MetadataApiError')
        except Exception as e:
            if debug:
                import pdb
                import traceback
                traceback.print_exc()
                pdb.post_mortem()
            else:
                raise

    # Save the org config in case it was modified in the task
    if org and org_config:
        config.keychain.set_org(org, org_config)

    if exception:
        raise exception