Esempio n. 1
0
def config(ctx):
    """List available config.

    \b
    Usage:
        $ pyblish config
        DEFAULTCONFIG = config.yaml
        DEFAULTCONFIGPATH = pyblish\config.yaml
        commit_template = {prefix}/{date}/{family}/{instance}
        configuration_environment_variable = PYBLISHCONFIGPATH
        conformers_regex = ^conform_.*\.py$
        date_format = %Y%m%d_%H%M%S
        extractors_regex = ^extract_.*\.py$
        identifier = publishable
        paths = ["{pyblish}/plugins"]
        paths_environment_variable = PYBLISHPLUGINPATH
        prefix = published
        publish_by_default = True
        selectors_regex = ^select_.*\.py$
        validators_regex = ^validate_.*\.py$

    """

    for key, value in sorted(pyblish.api.config.iteritems()):
        entry = "{k} = {v}".format(tab=TAB, k=key, v=value)
        entry += " " * (SCREEN_WIDTH - len(entry))
        click.echo(entry)
Esempio n. 2
0
def config(ctx):
    """List available config.

    \b
    Usage:
        $ pyblish config
        DEFAULTCONFIG = config.yaml
        DEFAULTCONFIGPATH = pyblish\config.yaml
        commit_template = {prefix}/{date}/{family}/{instance}
        configuration_environment_variable = PYBLISHCONFIGPATH
        conformers_regex = ^conform_.*\.py$
        date_format = %Y%m%d_%H%M%S
        extractors_regex = ^extract_.*\.py$
        identifier = publishable
        paths = ["{pyblish}/plugins"]
        paths_environment_variable = PYBLISHPLUGINPATH
        prefix = published
        publish_by_default = True
        selectors_regex = ^select_.*\.py$
        validators_regex = ^validate_.*\.py$

    """

    for key, value in sorted(pyblish.api.config.iteritems()):
        entry = "{k} = {v}".format(
            tab=TAB, k=key, v=value)
        entry += " " * (SCREEN_WIDTH - len(entry))
        click.echo(entry)
Esempio n. 3
0
def publish(ctx,
            path,
            instances,
            delay):
    """Publish instances of path.

    \b
    Arguments:
        path: Optional path, either absolute or relative,
            at which to initialise a publish. Defaults to
            the current working directory.

    \b
    Usage:
        $ pyblish publish my_file.txt --instance=Message01
        $ pyblish publish my_file.txt --all

    """

    _start = time.time()  # Benchmark

    # Use `path` argument as initial data for context
    context = ctx.obj["context"]

    if os.path.isdir(path):
        context.data["current_dir"] = path  # backwards compatibility
        context.data["currentDir"] = path
    else:
        context.data["current_file"] = path  # backwards compatibility
        context.data["currentFile"] = path

    # Begin processing
    plugins = list(p for p in pyblish.api.discover(
        paths=ctx.obj["plugin_paths"]) if p.active)
    context = pyblish.util.publish(context=context, plugins=plugins)

    if any(result["error"] for result in context.data["results"]):
        click.echo("There were errors.")

        for result in context.data["results"]:
            if result["error"] is not None:
                click.echo(result["error"])

    _end = time.time()

    if ctx.obj["verbose"]:
        click.echo()
        click.echo("-" * 80)
        click.echo(_format_time(_start, _end))
Esempio n. 4
0
def publish(ctx, path, instances, delay):
    """Publish instances of path.

    \b
    Arguments:
        path: Optional path, either absolute or relative,
            at which to initialise a publish. Defaults to
            the current working directory.

    \b
    Usage:
        $ pyblish publish my_file.txt --instance=Message01
        $ pyblish publish my_file.txt --all

    """

    _start = time.time()  # Benchmark

    # Use `path` argument as initial data for context
    context = ctx.obj["context"]

    if os.path.isdir(path):
        context.set_data("current_dir", path)
    else:
        context.set_data("current_file", path)

    # Begin processing
    plugins = pyblish.api.discover(paths=ctx.obj["plugin_paths"])
    context = pyblish.util.publish(context=context, plugins=plugins)

    if any(result["error"] for result in context.data("results")):
        click.echo("There were errors.")

        for result in context.data("results"):
            if result["error"] is not None:
                click.echo(result["error"])

    _end = time.time()

    if ctx.obj["verbose"]:
        click.echo()
        click.echo("-" * 80)
        click.echo(_format_time(_start, _end))
Esempio n. 5
0
def main(ctx,
         verbose,
         version,
         paths,
         plugins,
         environment_paths,
         configured_paths,
         registered_paths,
         plugin_paths,
         add_plugin_paths,
         config,
         data,
         logging_level):
    """Pyblish command-line interface

    Use the appropriate sub-command to initiate a publish.

    Use the --help flag of each subcommand to learn more
    about what it can do.

    \b
    Usage:
        $ pyblish publish --help
        $ pyblish test --help

    """

    global _ctx
    _ctx = ctx

    level = LOG_LEVEL[logging_level]
    log.setLevel(level)

    # Process top-level arguments
    if version:
        click.echo("pyblish version %s" % pyblish.__version__)

    # Respond to sub-commands
    if not ctx.obj:
        ctx.obj = dict()

    # Initialise context with data passed as argument
    context = pyblish.api.Context()
    ctx.obj["context"] = context

    for key, value in data:
        try:
            yaml_loaded = yaml.load(value)
        except Exception as err:
            log.error("Error: Data must be YAML formatted: "
                      "--data %s %s" % (key, value))
            ctx.obj["error"] = err
        else:
            context.set_data(str(key), yaml_loaded)

    # Load user data
    data_loaded = _load_data(context)
    config_loaded = _load_config()

    if not plugin_paths:
        plugin_paths = pyblish.api.plugin_paths()
    plugin_paths += add_plugin_paths
    ctx.obj["plugin_paths"] = plugin_paths

    available_plugins = pyblish.api.discover(paths=plugin_paths)

    if plugins:
        click.echo(_format_plugins(available_plugins))

    if verbose:
        click.echo(
            intro_message.format(
                version=pyblish.__version__,
                config_path=CONFIG_PATH if config_loaded else "None",
                data_path=DATA_PATH if data_loaded else "None",
                paths=_format_paths(plugin_paths),
                plugins=_format_plugins(available_plugins))
        )

    # Visualise available paths
    if any([paths, environment_paths, registered_paths, configured_paths]):
        _paths = list()

        if paths:
            environment_paths = True
            registered_paths = True
            configured_paths = True

        for path in plugin_paths:

            # Determine the source of each path
            _typ = "custom"
            if path in pyblish.api.environment_paths():
                _typ = "environment"

            elif path in pyblish.api.registered_paths():
                _typ = "registered"

            elif path in pyblish.api.configured_paths():
                _typ = "configured"

            # Only display queried paths
            if _typ == "environment" and not environment_paths:
                continue

            if _typ == "configured" and not configured_paths:
                continue

            if _typ == "registered" and not registered_paths:
                continue

            click.echo(PATH_TEMPLATE.format(
                path=path, typ=_typ))
            _paths.append(path)

    # Pass data to sub-commands
    ctx.obj["verbose"] = verbose
    ctx.obj["plugin_paths"] = plugin_paths
Esempio n. 6
0
def main(ctx, verbose, version, paths, plugins, environment_paths,
         configured_paths, registered_paths, plugin_paths, add_plugin_paths,
         config, data, logging_level):
    """Pyblish command-line interface

    Use the appropriate sub-command to initiate a publish.

    Use the --help flag of each subcommand to learn more
    about what it can do.

    \b
    Usage:
        $ pyblish publish --help
        $ pyblish test --help

    """

    global _ctx
    _ctx = ctx

    level = LOG_LEVEL[logging_level]
    log.setLevel(level)

    # Process top-level arguments
    if version:
        click.echo("pyblish version %s" % pyblish.__version__)

    # Respond to sub-commands
    if not ctx.obj:
        ctx.obj = dict()

    # Initialise context with data passed as argument
    context = pyblish.api.Context()
    ctx.obj["context"] = context

    for key, value in data:
        try:
            yaml_loaded = yaml.load(value)
        except Exception as err:
            log.error("Error: Data must be YAML formatted: "
                      "--data %s %s" % (key, value))
            ctx.obj["error"] = err
        else:
            context.set_data(str(key), yaml_loaded)

    # Load user data
    data_loaded = _load_data(context)
    config_loaded = _load_config()

    if not plugin_paths:
        plugin_paths = pyblish.api.plugin_paths()
    plugin_paths += add_plugin_paths
    ctx.obj["plugin_paths"] = plugin_paths

    available_plugins = pyblish.api.discover(paths=plugin_paths)

    if plugins:
        click.echo(_format_plugins(available_plugins))

    if verbose:
        click.echo(
            intro_message.format(
                version=pyblish.__version__,
                config_path=CONFIG_PATH if config_loaded else "None",
                data_path=DATA_PATH if data_loaded else "None",
                paths=_format_paths(plugin_paths),
                plugins=_format_plugins(available_plugins)))

    # Visualise available paths
    if any([paths, environment_paths, registered_paths, configured_paths]):
        _paths = list()

        if paths:
            environment_paths = True
            registered_paths = True
            configured_paths = True

        for path in plugin_paths:

            # Determine the source of each path
            _typ = "custom"
            if path in pyblish.api.environment_paths():
                _typ = "environment"

            elif path in pyblish.api.registered_paths():
                _typ = "registered"

            elif path in pyblish.api.configured_paths():
                _typ = "configured"

            # Only display queried paths
            if _typ == "environment" and not environment_paths:
                continue

            if _typ == "configured" and not configured_paths:
                continue

            if _typ == "registered" and not registered_paths:
                continue

            click.echo(PATH_TEMPLATE.format(path=path, typ=_typ))
            _paths.append(path)

    # Pass data to sub-commands
    ctx.obj["verbose"] = verbose
    ctx.obj["plugin_paths"] = plugin_paths
Esempio n. 7
0
def main(ctx,
         verbose,
         version,
         paths,
         plugins,
         environment_paths,
         registered_paths,
         plugin_paths,
         add_plugin_paths,
         data,
         logging_level):
    """Pyblish command-line interface

    Use the appropriate sub-command to initiate a publish.

    Use the --help flag of each subcommand to learn more
    about what it can do.

    \b
    Usage:
        $ pyblish publish --help
        $ pyblish test --help

    """

    global _ctx
    _ctx = ctx

    level = LOG_LEVEL[logging_level]
    log.setLevel(level)

    # Process top-level arguments
    if version:
        click.echo("pyblish version %s" % pyblish.__version__)

    # Respond to sub-commands
    if not ctx.obj:
        ctx.obj = dict()

    # Initialise context with data passed as argument
    context = pyblish.api.Context()
    ctx.obj["context"] = context

    for key, value in data:
        try:
            value = json.loads(value)
        except ValueError:
            pass
        
        context.data[str(key)] = value

    if not plugin_paths:
        plugin_paths = pyblish.api.plugin_paths()
    plugin_paths += add_plugin_paths
    ctx.obj["plugin_paths"] = plugin_paths

    available_plugins = pyblish.api.discover(paths=plugin_paths)

    if plugins:
        click.echo(_format_plugins(available_plugins))

    if verbose:
        click.echo(
            intro_message.format(
                version=pyblish.__version__,
                paths=_format_paths(plugin_paths),
                plugins=_format_plugins(available_plugins))
        )

    # Visualise available paths
    if any([paths, environment_paths, registered_paths]):
        _paths = list()

        if paths:
            environment_paths = True
            registered_paths = True

        for path in plugin_paths:

            # Determine the source of each path
            _typ = "custom"
            if path in pyblish.api.environment_paths():
                _typ = "environment"

            elif path in pyblish.api.registered_paths():
                _typ = "registered"

            # Only display queried paths
            if _typ == "environment" and not environment_paths:
                continue

            if _typ == "registered" and not registered_paths:
                continue

            click.echo(PATH_TEMPLATE.format(
                path=path, typ=_typ))
            _paths.append(path)

    # Pass data to sub-commands
    ctx.obj["verbose"] = verbose
    ctx.obj["plugin_paths"] = plugin_paths