当前位置: 首页>>代码示例>>Python>>正文


Python subprocutils.which函数代码示例

本文整理汇总了Python中subprocutils.which函数的典型用法代码示例。如果您正苦于以下问题:Python which函数的具体用法?Python which怎么用?Python which使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了which函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: launch_buck

    def launch_buck(self, build_id):
        with Tracing('BuckTool.launch_buck'):
            with JvmCrashLogger(self, self._buck_project.root):
                if self._command_line.command == "clean" and \
                        not self._command_line.is_help():
                    self.kill_buckd()

                buck_version_uid = self._get_buck_version_uid()

                if self._command_line.is_version():
                    print("buck version {}".format(buck_version_uid))
                    return 0

                use_buckd = self._use_buckd
                if not self._command_line.is_help():
                    has_watchman = bool(which('watchman'))
                    if use_buckd and has_watchman:
                        running_version = self._buck_project.get_running_buckd_version()

                        if running_version != buck_version_uid:
                            self.kill_buckd()

                        if not self._is_buckd_running():
                            self.launch_buckd(buck_version_uid=buck_version_uid)
                    elif use_buckd and not has_watchman:
                        logging.warning("Not using buckd because watchman isn't installed.")
                    elif not use_buckd:
                        logging.warning("Not using buckd because NO_BUCKD is set.")

                env = self._environ_for_buck()
                env['BUCK_BUILD_ID'] = build_id

                if use_buckd and self._is_buckd_running():
                    return self._run_with_buckd(env)

                command = ["buck"]
                extra_default_options = [
                    "-Djava.io.tmpdir={0}".format(self._tmp_dir),
                    "-Dfile.encoding=UTF-8",
                    "-XX:SoftRefLRUPolicyMSPerMB=0",
                    "-XX:+UseG1GC",
                ]
                command.extend(self._get_java_args(buck_version_uid, extra_default_options))
                command.append("com.facebook.buck.cli.bootstrapper.ClassLoaderBootstrapper")
                command.append("com.facebook.buck.cli.Main")
                command.extend(sys.argv[1:])

                now = int(round(time.time() * 1000))
                env['BUCK_PYTHON_SPACE_INIT_TIME'] = str(now - self._init_timestamp)
                if True:
                    java = which("java")
                    if java is None:
                        raise BuckToolException('Could not find java on $PATH')
                    with Tracing('buck', args={'command': command}):
                        buck_exit_code = subprocess.call(command,
                                                         cwd=self._buck_project.root,
                                                         env=env,
                                                         executable=java)
                return buck_exit_code
开发者ID:robbertvanginkel,项目名称:buck,代码行数:59,代码来源:buck_tool.py

示例2: __init__

    def __init__(self, buck_bin_dir, buck_project, buck_reporter):
        self.buck_dir = platform_path(os.path.dirname(buck_bin_dir))

        super(BuckRepo, self).__init__(buck_project, buck_reporter)

        dot_git = os.path.join(self.buck_dir, ".git")
        self.is_git = (
            os.path.exists(dot_git)
            and os.path.isdir(dot_git)
            and which("git")
            and sys.platform != "cygwin"
        )
        self._is_buck_repo_dirty_override = os.environ.get("BUCK_REPOSITORY_DIRTY")
        if not self._fake_buck_version:
            # self._fake_buck_version has been set previously through BuckTool when the environment
            # variable BUCK_FAKE_VERSION is set.
            # If the environement variable is not set, we'll use the content of .fakebuckversion
            # at the root of the repository if it exists.
            fake_buck_version_file_path = os.path.join(
                self.buck_dir, ".fakebuckversion"
            )
            if os.path.exists(fake_buck_version_file_path):
                with open(fake_buck_version_file_path) as fake_buck_version_file:
                    self._fake_buck_version = fake_buck_version_file.read().strip()
                    logging.info(
                        "Using fake buck version (via .fakebuckversion): {}".format(
                            self._fake_buck_version
                        )
                    )
开发者ID:SeleniumHQ,项目名称:buck,代码行数:29,代码来源:buck_repo.py

示例3: _run_without_nailgun

 def _run_without_nailgun(self, argv, env):
     """
     Run the command by directly invoking `java` (rather than by sending a command via nailgun)
     """
     command = ["buck"]
     extra_default_options = [
         "-Djava.io.tmpdir={0}".format(self._tmp_dir),
         "-Dfile.encoding=UTF-8",
         "-XX:SoftRefLRUPolicyMSPerMB=0",
         "-XX:+UseG1GC",
     ]
     command.extend(self._get_java_args(self._get_buck_version_uid(), extra_default_options))
     command.append("com.facebook.buck.cli.bootstrapper.ClassLoaderBootstrapper")
     command.append("com.facebook.buck.cli.Main")
     command.extend(self._add_args_from_env(argv))
     now = int(round(time.time() * 1000))
     env['BUCK_PYTHON_SPACE_INIT_TIME'] = str(now - self._init_timestamp)
     java = which('java')
     if java is None:
         raise BuckToolException('Could not find java on $PATH')
     with Tracing('buck', args={'command': command}):
         return subprocess.call(command,
                                cwd=self._buck_project.root,
                                env=env,
                                executable=java)
开发者ID:ilya-klyuchnikov,项目名称:buck,代码行数:25,代码来源:buck_tool.py

示例4: find_ant

def find_ant():
    ant = which('ant')
    if not ant:
        message = "You do not have ant on your $PATH. Cannot build Buck."
        if sys.platform == "darwin":
            message += "\nTry running 'brew install ant'."
        raise RuntimeError(message)
    return ant
开发者ID:dsyang,项目名称:buck,代码行数:8,代码来源:version_aware_buck.py

示例5: is_git

def is_git(dirpath):
    dot_git = os.path.join(dirpath, ".git")
    if which("git") and sys.platform != "cygwin":
        if os.path.exists(dot_git) and os.path.isdir(dot_git):
            return True
        output = check_output(["git", "rev-parse", "--is-inside-work-tree"], cwd=dirpath)
        return output.strip() == "true"
    return False
开发者ID:sdwilsh,项目名称:buck,代码行数:8,代码来源:buck_version.py

示例6: _check_for_ant

 def _check_for_ant(self):
     ant = which('ant')
     if not ant:
         message = "You do not have ant on your $PATH. Cannot build Buck."
         if sys.platform == "darwin":
             message += "\nTry running 'brew install ant'."
         raise BuckToolException(message)
     return ant
开发者ID:rlugojr,项目名称:buck,代码行数:8,代码来源:buck_repo.py

示例7: is_git

def is_git(dirpath):
    dot_git = os.path.join(dirpath, '.git')
    return all([
        os.path.exists(dot_git),
        os.path.isdir(dot_git),
        which('git'),
        sys.platform != 'cygwin',
    ])
开发者ID:292388900,项目名称:buck,代码行数:8,代码来源:buck_version.py

示例8: launch_buck

    def launch_buck(self, build_id):
        with Tracing("BuckRepo.launch_buck"):
            if self._command_line.command == "clean" and not self._command_line.is_help():
                self.kill_buckd()

            buck_version_uid = self._get_buck_version_uid()

            use_buckd = self._use_buckd()
            if not self._command_line.is_help():
                has_watchman = bool(which("watchman"))
                if use_buckd and has_watchman:
                    buckd_run_count = self._buck_project.get_buckd_run_count()
                    running_version = self._buck_project.get_running_buckd_version()
                    new_buckd_run_count = buckd_run_count + 1

                    if buckd_run_count == MAX_BUCKD_RUN_COUNT or running_version != buck_version_uid:
                        self.kill_buckd()
                        new_buckd_run_count = 0

                    if new_buckd_run_count == 0 or not self._is_buckd_running():
                        self.launch_buckd(buck_version_uid=buck_version_uid)
                    else:
                        self._buck_project.update_buckd_run_count(new_buckd_run_count)
                elif use_buckd and not has_watchman:
                    print("Not using buckd because watchman isn't installed.", file=sys.stderr)
                elif not use_buckd:
                    print("Not using buckd because NO_BUCKD is set.", file=sys.stderr)

            env = self._environ_for_buck()
            env["BUCK_BUILD_ID"] = build_id

            buck_socket_path = self._buck_project.get_buckd_socket_path()

            if use_buckd and self._is_buckd_running() and os.path.exists(buck_socket_path):
                with Tracing("buck", args={"command": sys.argv[1:]}):
                    exit_code = 2
                    last_diagnostic_time = 0
                    while exit_code == 2:
                        with NailgunConnection("local:.buckd/sock", cwd=self._buck_project.root) as c:
                            exit_code = c.send_command(
                                "com.facebook.buck.cli.Main", sys.argv[1:], env=env, cwd=self._buck_project.root
                            )
                            if exit_code == 2:
                                now = time.time()
                                if now - last_diagnostic_time > DAEMON_BUSY_MESSAGE_SECONDS:
                                    print("Daemon is busy, waiting for it to become free...", file=sys.stderr)
                                    last_diagnostic_time = now
                                time.sleep(1)
                    return exit_code

            command = ["buck"]
            extra_default_options = ["-Djava.io.tmpdir={0}".format(self._tmp_dir)]
            command.extend(self._get_java_args(buck_version_uid, extra_default_options))
            command.append("com.facebook.buck.cli.bootstrapper.ClassLoaderBootstrapper")
            command.append("com.facebook.buck.cli.Main")
            command.extend(sys.argv[1:])

            return subprocess.call(command, cwd=self._buck_project.root, env=env, executable=which("java"))
开发者ID:philipjameson,项目名称:buck,代码行数:58,代码来源:buck_tool.py

示例9: setup_watchman_watch

def setup_watchman_watch():
    with Tracing('BuckTool._setup_watchman_watch'):
        if not which('watchman'):
            message = textwrap.dedent("""\
                Watchman not found, please install when using buckd.
                See https://github.com/facebook/watchman for details.""")
            if sys.platform == "darwin":
                message += "\n(brew install watchman on OS X)"
            # Bail if watchman isn't installed as we know java's
            # FileSystemWatcher will take too long to process events.
            raise BuckToolException(message)

        logging.debug("Using watchman.")
开发者ID:ilya-klyuchnikov,项目名称:buck,代码行数:13,代码来源:buck_tool.py

示例10: is_git

def is_git(dirpath):
    dot_git = os.path.join(dirpath, '.git')
    if which('git') and sys.platform != 'cygwin':
        if os.path.exists(dot_git) and os.path.isdir(dot_git):
            return True
        try:
            with open(os.devnull, 'w') as devnull:
                output = check_output(
                    ['git', 'rev-parse', '--is-inside-work-tree'],
                    cwd=dirpath,
                    stderr=devnull)
            return output.strip() == 'true'
        except CalledProcessError:
            pass
    return False
开发者ID:clonetwin26,项目名称:buck,代码行数:15,代码来源:buck_version.py

示例11: is_git

def is_git(dirpath):  # type: (str) -> bool
    dot_git = os.path.join(dirpath, ".git")
    if which("git") and sys.platform != "cygwin":
        if os.path.exists(dot_git) and os.path.isdir(dot_git):
            return True
        try:
            with open(os.devnull, "w") as devnull:
                output = check_output(
                    ["git", "rev-parse", "--is-inside-work-tree"],
                    cwd=dirpath,
                    stderr=devnull,
                )
            return output.strip() == "true"
        except CalledProcessError:
            pass
    return False
开发者ID:shs96c,项目名称:buck,代码行数:16,代码来源:buck_version.py

示例12: get_java_path

def get_java_path():
    java_home_path = os.getenv('JAVA_HOME')
    java_path = None
    if java_home_path is None:
        java_path = which('java')
        if java_path is None:
            raise BuckToolException('Could not find Java executable. \
Make sure it is on PATH or JAVA_HOME is set.')
    else:
        java_path = _get_java_exec_under_home(java_home_path)
        if not os.path.isfile(java_path):
            message = textwrap.dedent("""
            Could not find Java executable under JAVA_HOME at: '{}'.
            Please make sure your JAVA_HOME environment variable is set correctly.
            """).format(java_path)
            raise BuckToolException(message)
    return java_path
开发者ID:LegNeato,项目名称:buck,代码行数:17,代码来源:buck_tool.py

示例13: get_java_path

def get_java_path(required_java_version):
    java_home_path = os.getenv("JAVA_HOME")
    if java_home_path:
        # Though we try to respect JAVA_HOME, if the path looks like the wrong version of Java, try
        # to use a known location of the JDK for the right version instead.
        suspected_java_version = _get_suspected_java_version_from_java_path(
            java_home_path
        )
        if suspected_java_version and suspected_java_version != required_java_version:
            message = (
                'Warning: JAVA_HOME is set to "{}", which looks like a Java {} path, '
                + "but Buck requires Java {}."
            ).format(java_home_path, suspected_java_version, required_java_version)
            if os.getenv("BUCK_RESPECT_JAVA_HOME") != "1":
                message += " Ignoring JAVA_HOME. Set BUCK_RESPECT_JAVA_HOME to 1 to disable this behavior."
                java_home_path = None
            logging.warning(message)
    if java_home_path is None:
        # Default to a known location of the JDK for the right version of Java, regardless of what
        # version of Java is on the PATH.
        java_base_path = _get_known_java_path_for_version(required_java_version)
        java_path = None
        if java_base_path:
            java_path = _get_java_exec(java_base_path)
            if not os.path.isfile(java_path):
                java_path = None
        if not java_path:
            java_path = which("java")
        if java_path is None:
            raise BuckToolException(
                "Could not find Java executable. \
Make sure it is on PATH or JAVA_HOME is set."
            )
    else:
        java_path = _get_java_exec(java_home_path)
        if not os.path.isfile(java_path):
            message = textwrap.dedent(
                """
            Could not find Java executable under JAVA_HOME at: '{}'.
            Please make sure your JAVA_HOME environment variable is set correctly.
            Then restart buck (buck kill) and try again.
            """
            ).format(java_path)
            raise BuckToolException(message)
    return java_path
开发者ID:facebook,项目名称:buck,代码行数:45,代码来源:java_lookup.py

示例14: __init__

    def __init__(self, buck_bin_dir, buck_project):
        super(BuckRepo, self).__init__(buck_project)

        self._buck_dir = self._platform_path(os.path.dirname(buck_bin_dir))
        self._build_success_file = os.path.join(
            self._buck_dir, "build", "successful-build")

        dot_git = os.path.join(self._buck_dir, '.git')
        self._is_git = os.path.exists(dot_git) and os.path.isdir(dot_git) and which('git') and \
            sys.platform != 'cygwin'
        self._is_buck_repo_dirty_override = os.environ.get('BUCK_REPOSITORY_DIRTY')

        buck_version = buck_project.buck_version
        if self._is_git and not buck_project.has_no_buck_check and buck_version:
            revision = buck_version[0]
            branch = buck_version[1] if len(buck_version) > 1 else None
            self._checkout_and_clean(revision, branch)

        self._build()
开发者ID:rlugojr,项目名称:buck,代码行数:19,代码来源:buck_repo.py

示例15: get_java_path

def get_java_path():
    java_home_path = os.getenv("JAVA_HOME")
    if java_home_path is None:
        java_path = which("java")
        if java_path is None:
            raise BuckToolException(
                "Could not find Java executable. \
Make sure it is on PATH or JAVA_HOME is set."
            )
    else:
        java_path = _get_java_exec_under_home(java_home_path)
        if not os.path.isfile(java_path):
            message = textwrap.dedent(
                """
            Could not find Java executable under JAVA_HOME at: '{}'.
            Please make sure your JAVA_HOME environment variable is set correctly.
            Then restart buck (buck kill) and try again.
            """
            ).format(java_path)
            raise BuckToolException(message)
    return java_path
开发者ID:shs96c,项目名称:buck,代码行数:21,代码来源:buck_tool.py


注:本文中的subprocutils.which函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。