Пример #1
0
    def launch_tray(self, debug=False):
        """Run tray.py.

        :param debug: if True, tray will run in debug mode (not detached)
        :type debug: bool

        .. seealso:: :func:`subprocess.Popen`
        """
        import subprocess
        from pypeapp import Logger
        from pypeapp import execute

        self._initialize()

        if debug:
            pype_setup = os.getenv('PYPE_SETUP_PATH')
            items = [pype_setup, "pypeapp", "tray.py"]
            fname = os.path.sep.join(items)

            execute([
                sys.executable,
                "-u",
                fname
                ])
            return

        DETACHED_PROCESS = 0x00000008  # noqa: N806

        pype_setup = os.getenv('PYPE_SETUP_PATH')
        items = [pype_setup, "pypeapp", "tray.py"]
        fname = os.path.sep.join(items)

        args = ["python", "-d", fname]
        if sys.platform.startswith('linux'):
            subprocess.Popen(
                args,
                universal_newlines=True,
                bufsize=1,
                # executable=sys.executable,
                env=os.environ,
                # stdin=None,
                stdout=None,
                stderr=None,
                preexec_fn=os.setpgrp
            )

        if sys.platform == 'win32':
            args = ["pythonw", "-d", fname]
            subprocess.Popen(
                args,
                universal_newlines=True,
                bufsize=1,
                cwd=None,
                # executable=sys.executable,
                env=os.environ,
                # stdin=None,
                stdout=open(Logger.get_file_path(), 'w+'),
                stderr=subprocess.STDOUT,
                creationflags=DETACHED_PROCESS
            )
Пример #2
0
    def run_shell(self):
        """Run shell applications."""
        from pypeapp.lib.Terminal import Terminal
        from pypeapp import execute

        self._initialize()
        t = Terminal()
        t.echo(">>> Running pype shell ...")
        if sys.platform == 'win32':
            execute(['powershell', '-NoLogo'])
        else:
            execute(['bash'])
Пример #3
0
    def texture_copy(self, project, asset, path):
        """Copy textures specified in path asset publish directory.

        It doesn't interact with avalon, just copying files.

        :param project: name of project
        :type project: str
        :param asset: name of asset
        :type asset: str
        :param path: path to textures
        :type path: str
        """
        from pypeapp import execute

        self._initialize()

        pype_setup = os.getenv('PYPE_SETUP_PATH')
        items = [
            pype_setup, "repos", "pype", "pype", "tools", "texture_copy",
            "app.py"
        ]
        fname = os.path.sep.join(items)

        returncode = execute([
            sys.executable, "-u", fname, "--project", project, "--asset",
            asset, "--path", path
        ])
        return returncode
Пример #4
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()
Пример #5
0
    def launch_eventserver(self):
        """
        This will run standalone ftrack eventserver.

        :returns: process return code
        :rtype: int

        .. deprecated:: 2.1
           Use :meth:`launch_eventservercli` instead.
        """
        from pypeapp import execute

        self._initialize()

        pype_setup = os.getenv('PYPE_ROOT')
        items = [
            pype_setup, "repos", "pype", "pype", "ftrack", "ftrack_server",
            "event_server.py"
        ]
        fname = os.path.sep.join(items)

        returncode = execute([
            sys.executable, "-u", fname
        ])
        return returncode
Пример #6
0
    def launch_settings_gui(self, develop):
        from pypeapp import execute
        self._initialize()

        pype_setup = os.getenv('PYPE_SETUP_PATH')
        items = [pype_setup, "repos", "pype", "pype", "tools", "settings"]
        fname = os.path.sep.join(items)

        args = [sys.executable, "-u", fname]
        if develop:
            args.append("--develop")
        returncode = execute(args)
        return returncode
Пример #7
0
def cli_publish(data, gui=True):
    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 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_lite"

    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
Пример #8
0
    def launch_eventservercli(self, args):
        """Run standalone ftrack eventserver headless.

        :param args: arguments passed to event server script. See event server
                     help for more info.
        :type args: list
        :returns: process return code
        :rtype: int
        """
        from pypeapp import execute
        self._initialize()

        pype_setup = os.getenv('PYPE_SETUP_PATH')
        items = [
            pype_setup, "repos", "pype", "pype", "modules", "ftrack",
            "ftrack_server", "event_server_cli.py"
        ]
        fname = os.path.sep.join(items)

        returncode = execute([sys.executable, "-u", fname] + args)
        return returncode
Пример #9
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")
Пример #10
0
    def make_docs(self):
        """Generate documentation using Sphinx.

        Documentation is generated for both **pype-setup** and **pype**.
        """
        from pypeapp.lib.Terminal import Terminal
        from pypeapp import execute

        self._initialize()
        t = Terminal()

        source_dir_setup = os.path.join(os.environ.get("PYPE_SETUP_PATH"),
                                        "docs", "source")
        build_dir_setup = os.path.join(os.environ.get("PYPE_SETUP_PATH"),
                                       "docs", "build")

        source_dir_pype = os.path.join(os.environ.get("PYPE_SETUP_PATH"),
                                       "repos", "pype", "docs", "source")
        build_dir_pype = os.path.join(os.environ.get("PYPE_SETUP_PATH"),
                                      "repos", "pype", "docs", "build")

        t.echo(">>> Generating documentation ...")
        t.echo("  - Cleaning up ...")
        execute(
            ['sphinx-build', '-M', 'clean', source_dir_setup, build_dir_setup],
            shell=True)
        execute(
            ['sphinx-build', '-M', 'clean', source_dir_pype, build_dir_pype],
            shell=True)
        t.echo("  - generating sources ...")
        execute([
            'sphinx-apidoc', '-M', '-f', '-d', '4', '--ext-autodoc',
            '--ext-intersphinx', '--ext-viewcode', '-o', source_dir_setup,
            'pypeapp'
        ],
                shell=True)
        vendor_ignore = os.path.join(os.environ.get("PYPE_SETUP_PATH"),
                                     "repos", "pype", "pype", "vendor")
        execute([
            'sphinx-apidoc', '-M', '-f', '-d', '6', '--ext-autodoc',
            '--ext-intersphinx', '--ext-viewcode', '-o', source_dir_pype,
            'pype', '{}{}*'.format(vendor_ignore, os.path.sep)
        ],
                shell=True)
        t.echo("  - Building html ...")
        execute(
            ['sphinx-build', '-M', 'html', source_dir_setup, build_dir_setup],
            shell=True)
        execute(
            ['sphinx-build', '-M', 'html', source_dir_pype, build_dir_pype],
            shell=True)
        t.echo(">>> Done. Documentation id generated:")
        t.echo("*** For pype-setup: [ {} ]".format(build_dir_setup))
        t.echo("*** For pype: [ {} ]".format(build_dir_pype))
Пример #11
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_lite"

    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
Пример #12
0
log = Logger().get_logger("Resolve")

CURRENT_DIR = os.getenv("RESOLVE_UTILITY_SCRIPTS_DIR", "")
python_dir = os.getenv("PYTHON36_RESOLVE")
python_exe = os.path.normpath(
    os.path.join(python_dir, "python.exe")
)

resolve = get_resolve_module()
PM = resolve.GetProjectManager()
P = PM.GetCurrentProject()

log.info(P.GetName())


# ______________________________________________________
# testing subprocessing Scripts
testing_py = os.path.join(CURRENT_DIR, "ResolvePageSwitcher.py")
testing_py = os.path.normpath(testing_py)
log.info(f"Testing path to script: `{testing_py}`")

returncode = execute(
    [python_exe, os.path.normpath(testing_py)],
    env=dict(os.environ)
)

# Check if output file exists
if returncode != 0:
    log.error("Executing failed!")