Beispiel #1
0
def avalon_api_publish(data, gui=True):
    ''' Launches Pyblish (GUI by default)
    :param data: Should include data for pyblish and standalone collector
    :type data: dict
    :param gui: Pyblish will be launched in GUI mode if set to True
    :type gui: bool
    '''
    io.install()

    # Create hash name folder in temp
    chars = "".join([random.choice(string.ascii_letters) for i in range(15)])
    staging_dir = tempfile.mkdtemp(chars)

    # create also json and fill with data
    json_data_path = staging_dir + os.path.basename(staging_dir) + '.json'
    with open(json_data_path, 'w') as outfile:
        json.dump(data, outfile)

    args = ["-pp", os.pathsep.join(pyblish.api.registered_paths())]

    envcopy = os.environ.copy()
    envcopy["PYBLISH_HOSTS"] = "standalonepublisher"
    envcopy["SAPUBLISH_INPATH"] = json_data_path

    if gui:
        av_publish.show()
    else:
        returncode = execute([sys.executable, "-u", "-m", "pyblish"] + args,
                             env=envcopy)

    io.uninstall()
Beispiel #2
0
def cli_publish(data, gui=True):
    io.install()

    pyblish.api.deregister_all_plugins()
    # Registers Global pyblish plugins
    pype.install()
    # Registers Standalone pyblish plugins
    for path in PUBLISH_PATHS:
        pyblish.api.register_plugin_path(path)

    project_plugins_paths = os.environ.get("PYPE_PROJECT_PLUGINS")
    project_name = os.environ["AVALON_PROJECT"]
    if project_plugins_paths and project_name:
        for path in project_plugins_paths.split(os.pathsep):
            if not path:
                continue
            plugin_path = os.path.join(path, project_name, "plugins")
            if os.path.exists(plugin_path):
                pyblish.api.register_plugin_path(plugin_path)
                api.register_plugin_path(api.Loader, plugin_path)
                api.register_plugin_path(api.Creator, plugin_path)

    # Create hash name folder in temp
    chars = "".join([random.choice(string.ascii_letters) for i in range(15)])
    staging_dir = tempfile.mkdtemp(chars)

    # create json for return data
    return_data_path = (staging_dir + os.path.basename(staging_dir) +
                        'return.json')
    # create also json and fill with data
    json_data_path = staging_dir + os.path.basename(staging_dir) + '.json'
    with open(json_data_path, 'w') as outfile:
        json.dump(data, outfile)

    args = ["-pp", os.pathsep.join(pyblish.api.registered_paths())]

    if gui:
        args += ["gui"]

    envcopy = os.environ.copy()
    envcopy["PYBLISH_HOSTS"] = "standalonepublisher"
    envcopy["SAPUBLISH_INPATH"] = json_data_path
    envcopy["SAPUBLISH_OUTPATH"] = return_data_path
    envcopy["PYBLISH_GUI"] = "pyblish_pype"

    returncode = execute([sys.executable, "-u", "-m", "pyblish"] + args,
                         env=envcopy)

    result = {}
    if os.path.exists(json_data_path):
        with open(json_data_path, "r") as f:
            result = json.load(f)

    io.uninstall()
    # TODO: check if was pyblish successful
    # if successful return True
    print('Check result here')
    return False
Beispiel #3
0
    def publish(self, request):
        """Triggers publishing script in subprocess.

        The subprocess freeze process and during publishing is not possible to
        handle other requests and is possible that freeze main application.

        TODO: Freezing issue may be fixed with socket communication.

        Example url:
        http://localhost:8021/adobe/publish (POST)
        """
        try:
            publish_env = self._prepare_publish_environments(
                request.request_data
            )
        except Exception as exc:
            log.warning(
                "Failed to prepare environments for publishing.",
                exc_info=True
            )
            abort(400, str(exc))

        output_data_path = publish_env["AC_PUBLISH_OUTPATH"]

        log.info("Pyblish is running")
        try:
            # Trigger subprocess
            # QUESTION should we check returncode?
            returncode = execute(
                [sys.executable, PUBLISH_SCRIPT_PATH],
                env=publish_env
            )

            # Check if output file exists
            if returncode != 0 or not os.path.exists(output_data_path):
                abort(500, "Publishing failed")

            log.info("Pyblish have stopped")

            return CallbackResult(
                data={"return_data_path": output_data_path}
            )

        except Exception:
            log.warning("Publishing failed", exc_info=True)
            abort(500, "Publishing failed")
def cli_publish(data, publish_paths, gui=True):
    PUBLISH_SCRIPT_PATH = os.path.join(
        os.path.dirname(os.path.dirname(__file__)), "publish.py")
    io.install()

    # Create hash name folder in temp
    chars = "".join([random.choice(string.ascii_letters) for i in range(15)])
    staging_dir = tempfile.mkdtemp(chars)

    # create also json and fill with data
    json_data_path = staging_dir + os.path.basename(staging_dir) + '.json'
    with open(json_data_path, 'w') as outfile:
        json.dump(data, outfile)

    envcopy = os.environ.copy()
    envcopy["PYBLISH_HOSTS"] = "standalonepublisher"
    envcopy["SAPUBLISH_INPATH"] = json_data_path
    envcopy["PYBLISHGUI"] = "pyblish_pype"
    envcopy["PUBLISH_PATHS"] = os.pathsep.join(publish_paths)
    if data.get("family", "").lower() == "editorial":
        envcopy["PYBLISH_SUSPEND_LOGS"] = "1"

    project_name = os.environ["AVALON_PROJECT"]
    env_copy = apply_project_environments_value(project_name, envcopy)

    args = get_pype_execute_args("run", PUBLISH_SCRIPT_PATH)
    result = execute(args, env=envcopy)

    result = {}
    if os.path.exists(json_data_path):
        with open(json_data_path, "r") as f:
            result = json.load(f)

    log.info(f"Publish result: {result}")

    io.uninstall()

    return False