python类X_OK的实例源码

zipout.py 文件源码 项目:compilers-class-hw 作者: anoopsarkar 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def run_all(self):
        # check that a compiled binary exists to run on the testcases
        argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
        if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
            logging.error("executable missing: {0}".format(argv))
            print >>sys.stderr, "Compile your source file to create an executable {0}".format(argv)
            sys.exit(1)

        # check if testcases has subdirectories
        testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))

        if len(testcase_subdirs) > 0:
            for subdir in testcase_subdirs:
                files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
                self.run_path(subdir, files)
        else:
            files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
            self.run_path(None, files)

        return True
zipout.py 文件源码 项目:compilers-class-hw 作者: anoopsarkar 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def run_all(self):
        # check that a compiled binary exists to run on the testcases
        argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
        if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
            logging.error("executable missing: {}".format(argv))
            print >>sys.stderr, "Compile your source file to create an executable {}".format(argv)
            sys.exit(1)

        # check if testcases has subdirectories
        testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))

        if len(testcase_subdirs) > 0:
            for subdir in testcase_subdirs:
                files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
                self.run_path(subdir, files)
        else:
            files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
            self.run_path(None, files)

        return True
zipout.py 文件源码 项目:compilers-class-hw 作者: anoopsarkar 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run_all(self):
        # check that a compiled binary exists to run on the testcases
        argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
        if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
            logging.error("executable missing: {0}".format(argv))
            print >>sys.stderr, "Compile your source file to create an executable {0}".format(argv)
            sys.exit(1)

        # check if testcases has subdirectories
        testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))

        if len(testcase_subdirs) > 0:
            for subdir in testcase_subdirs:
                files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
                self.run_path(subdir, files)
        else:
            files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
            self.run_path(None, files)

        return True
zipout.py 文件源码 项目:compilers-class-hw 作者: anoopsarkar 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def run_all(self):
        # check that a compiled binary exists to run on the testcases
        argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
        if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
            logging.error("executable missing: {0}".format(argv))
            print >>sys.stderr, "Compile your source file to create an executable {0}".format(argv)
            sys.exit(1)

        # check if testcases has subdirectories
        testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))

        if len(testcase_subdirs) > 0:
            for subdir in testcase_subdirs:
                files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
                self.run_path(subdir, files)
        else:
            files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
            self.run_path(None, files)

        return True
zipout.py 文件源码 项目:compilers-class-hw 作者: anoopsarkar 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def run_all(self):
        # check that a compiled binary exists to run on the testcases
        argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
        if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
            logging.error("executable missing: {}".format(argv))
            print >>sys.stderr, "Compile your source file to create an executable {}".format(argv)
            sys.exit(1)

        # check if testcases has subdirectories
        testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))

        if len(testcase_subdirs) > 0:
            for subdir in testcase_subdirs:
                files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
                self.run_path(subdir, files)
        else:
            files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
            self.run_path(None, files)

        return True
zipout.py 文件源码 项目:compilers-class-hw 作者: anoopsarkar 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
def run_all(self):
        # check that a compiled binary exists to run on the testcases
        argv = os.path.abspath(os.path.join(self.answer_dir, self.run_program))
        if not (os.path.isfile(argv) and os.access(argv, os.X_OK)):
            logging.error("executable missing: {}".format(argv))
            print >>sys.stderr, "Compile your source file to create an executable {}".format(argv)
            sys.exit(1)

        # check if testcases has subdirectories
        testcase_subdirs = iocollect.getdirs(os.path.abspath(self.testcase_dir))

        if len(testcase_subdirs) > 0:
            for subdir in testcase_subdirs:
                files = iocollect.getfiles(os.path.abspath(os.path.join(self.testcase_dir, subdir)))
                self.run_path(subdir, files)
        else:
            files = iocollect.getfiles(os.path.abspath(self.testcase_dir))
            self.run_path(None, files)

        return True
docker_client.py 文件源码 项目:apocalypse 作者: dhoomakethu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def which(program):
    """
    Checks if executable exists and is on the path.
    Thanks http://stackoverflow.com/a/377028/119592
    """
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)
    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
          return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file
    return None
utils.py 文件源码 项目:Legion 作者: MooseDojo 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def which(program):
        import os
        def is_exe(fpath):
            return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

        fpath, fname = os.path.split(program)
        if fpath:
            if is_exe(program):
                return program
        else:
            for path in os.environ["PATH"].split(os.pathsep):
                path = path.strip('"')
                exe_file = os.path.join(path, program)
                if is_exe(exe_file):
                    return exe_file

        return None
syswraps.py 文件源码 项目:ribolands 作者: bad-ants-fleet 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def which(program):
  """ Emulates the unix ``which`` command. Snatched from:
    `http://stackoverflow.com/questions/377017/
      test-if-executable-exists-in-python`

    :param program: executable
    :type program: string

    :returns: path-to-executable or None
  """
  def is_exe(fpath):
    return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

  fpath, fname = os.path.split(program)
  if fpath:
    if is_exe(program):
      return program
  else:
    for path in os.environ["PATH"].split(os.pathsep):
      path = path.strip('"')
      exe_file = os.path.join(path, program)
      if is_exe(exe_file):
        return exe_file

  return None
util.py 文件源码 项目:Taigabot 作者: FrozenPigs 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def py_where(program, path=None):
    # From: http://stackoverflow.com/a/377028/548792
    try:
        winprog_exts = tuple(p.upper() for p in os.environ['PATHEXT'].split(os.pathsep))
    except:
        winprog_exts = is_win and ('.BAT', 'COM', '.EXE') or ()

    def is_exec(fpath):
        return osp.isfile(fpath) and os.access(fpath, os.X_OK) and (
            os.name != 'nt' or not winprog_exts or any(fpath.upper().endswith(ext)
                                                       for ext in winprog_exts))

    progs = []
    if not path:
        path = os.environ["PATH"]
    for folder in path.split(os.pathsep):
        folder = folder.strip('"')
        if folder:
            exe_path = osp.join(folder, program)
            for f in [exe_path] + ['%s%s' % (exe_path, e) for e in winprog_exts]:
                if is_exec(f):
                    progs.append(f)
    return progs
utils.py 文件源码 项目:Comictagger 作者: dickloraine 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def which(program):

    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None
utils.py 文件源码 项目:OrganizeMediaFiles 作者: vpistis 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def which(program):
    """
    Check if a program/executable exists

    :param program:
    :return:
    """

    def is_exe(f_path):
        return os.path.isfile(f_path) and os.access(f_path, os.X_OK)

    fpath, fname = os.path.split(program)

    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None
uuid.py 文件源码 项目:Intranet-Penetration 作者: yuxiaokui 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _popen(command, args):
    import os
    path = os.environ.get("PATH", os.defpath).split(os.pathsep)
    path.extend(('/sbin', '/usr/sbin'))
    for dir in path:
        executable = os.path.join(dir, command)
        if (os.path.exists(executable) and
            os.access(executable, os.F_OK | os.X_OK) and
            not os.path.isdir(executable)):
            break
    else:
        return None
    # LC_ALL to ensure English output, 2>/dev/null to prevent output on
    # stderr (Note: we don't have an example where the words we search for
    # are actually localized, but in theory some system could do so.)
    cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
    return os.popen(cmd)
__init__.py 文件源码 项目:faster_rcnn_pytorch 作者: longcw 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def _which(program):
    import os
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None
utils.py 文件源码 项目:Insane 作者: Tsjerk 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def which(program):
    """Determine full path of executable *program* on :envvar:`PATH`.

    (Jay at http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python)
    """

    def is_exe(fpath):
        """
        Returns True is the path points to an executable file.
        """
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, _ = os.path.split(program)
    if fpath:
        real_program = realpath(program)
        if is_exe(real_program):
            return real_program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file
    return None
uuid.py 文件源码 项目:MKFQ 作者: maojingios 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def _popen(command, args):
    import os
    path = os.environ.get("PATH", os.defpath).split(os.pathsep)
    path.extend(('/sbin', '/usr/sbin'))
    for dir in path:
        executable = os.path.join(dir, command)
        if (os.path.exists(executable) and
            os.access(executable, os.F_OK | os.X_OK) and
            not os.path.isdir(executable)):
            break
    else:
        return None
    # LC_ALL to ensure English output, 2>/dev/null to prevent output on
    # stderr (Note: we don't have an example where the words we search for
    # are actually localized, but in theory some system could do so.)
    cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
    return os.popen(cmd)
local.py 文件源码 项目:pib 作者: datawire 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def ensure_requirements(self):
        """Make sure kubectl and minikube are available."""
        uname = run_result("uname").lower()
        for path, url in zip([MINIKUBE, KUBECTL], [
                "https://storage.googleapis.com/minikube/releases/"
                "v0.15.0/minikube-{}-amd64",
                "https://storage.googleapis.com/kubernetes-release/"
                "release/v1.5.1/bin/{}/amd64/kubectl"
        ]):
            if path.exists() and not os.access(str(path), os.X_OK):
                # Apparently failed halfway through previous download
                os.remove(str(path))
            if not path.exists():
                self.echo("Downloading {}...".format(path.name))
                check_call([
                    "curl", "--create-dirs", "--silent", "--output", str(path),
                    url.format(uname)
                ])
                path.chmod(0o755)
__init__.py 文件源码 项目:RON 作者: taokong 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def _which(program):
    import os
    def is_exe(fpath):
        return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

    fpath, fname = os.path.split(program)
    if fpath:
        if is_exe(program):
            return program
    else:
        for path in os.environ["PATH"].split(os.pathsep):
            path = path.strip('"')
            exe_file = os.path.join(path, program)
            if is_exe(exe_file):
                return exe_file

    return None
uuid.py 文件源码 项目:pupy 作者: ru-faraon 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def _popen(command, args):
    import os
    path = os.environ.get("PATH", os.defpath).split(os.pathsep)
    path.extend(('/sbin', '/usr/sbin'))
    for dir in path:
        executable = os.path.join(dir, command)
        if (os.path.exists(executable) and
            os.access(executable, os.F_OK | os.X_OK) and
            not os.path.isdir(executable)):
            break
    else:
        return None
    # LC_ALL to ensure English output, 2>/dev/null to prevent output on
    # stderr (Note: we don't have an example where the words we search for
    # are actually localized, but in theory some system could do so.)
    cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
    return os.popen(cmd)
uuid.py 文件源码 项目:pupy 作者: ru-faraon 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def _popen(command, args):
    import os
    path = os.environ.get("PATH", os.defpath).split(os.pathsep)
    path.extend(('/sbin', '/usr/sbin'))
    for dir in path:
        executable = os.path.join(dir, command)
        if (os.path.exists(executable) and
            os.access(executable, os.F_OK | os.X_OK) and
            not os.path.isdir(executable)):
            break
    else:
        return None
    # LC_ALL to ensure English output, 2>/dev/null to prevent output on
    # stderr (Note: we don't have an example where the words we search for
    # are actually localized, but in theory some system could do so.)
    cmd = 'LC_ALL=C %s %s 2>/dev/null' % (executable, args)
    return os.popen(cmd)


问题


面经


文章

微信
公众号

扫码关注公众号