Ejemplo n.º 1
0
def which(program, path=None):
  """
  Returns the full path of shell commands.

  Replicates the functionality of system which (1) command. Looks
  for the named program in the directories indicated in the $PATH
  environment variable, and returns the full path if found.

  Examples:

      >>> system.which("ls")
      "/bin/ls"

      >>> system.which("/bin/ls")
      "/bin/ls"

      >>> system.which("not-a-real-command")
      None

      >>> system.which("ls", path=("/usr/bin", "/bin"))
      "/bin/ls"

  Arguments:

      program (str): The name of the program to look for. Can
        be an absolute path.
      path (sequence of str, optional): A list of directories to
        look for the pgoram in. Default value is system $PATH.

  Returns:

     str: Full path to program if found, else None.
  """
  # If path is not given, read the $PATH environment variable.
  path = path or os.environ["PATH"].split(os.pathsep)
  abspath = True if os.path.split(program)[0] else False
  if abspath:
    if fs.isexe(program):
      return program
  else:
    for directory in path:
      # De-quote directories.
      directory = directory.strip('"')
      exe_file = os.path.join(directory, program)
      if fs.isexe(exe_file):
        return exe_file

  return None
Ejemplo n.º 2
0
def which(program, path=None):
    """
    Returns the full path of shell commands.

    Replicates the functionality of system which (1) command. Looks
    for the named program in the directories indicated in the $PATH
    environment variable, and returns the full path if found.

    Examples:

        >>> system.which("ls")
        "/bin/ls"

        >>> system.which("/bin/ls")
        "/bin/ls"

        >>> system.which("not-a-real-command")
        None

        >>> system.which("ls", path=("/usr/bin", "/bin"))
        "/bin/ls"

    Arguments:

        program (str): The name of the program to look for. Can
          be an absolute path.
        path (sequence of str, optional): A list of directories to
          look for the pgoram in. Default value is system $PATH.

    Returns:

       str: Full path to program if found, else None.
    """
    # If path is not given, read the $PATH environment variable.
    path = path or os.environ["PATH"].split(os.pathsep)
    abspath = True if os.path.split(program)[0] else False
    if abspath:
        if fs.isexe(program):
            return program
    else:
        for directory in path:
            # De-quote directories.
            directory = directory.strip('"')
            exe_file = os.path.join(directory, program)
            if fs.isexe(exe_file):
                return exe_file

    return None
Ejemplo n.º 3
0
 def test_isexe(self):
     self._test(True, fs.isexe("/bin/ls"))
     self._test(False, fs.isexe("/home"))
     self._test(False, fs.isexe("/not/a/real/path (I hope!)"))
Ejemplo n.º 4
0
def test_isexe():
    assert fs.isexe("/bin/ls")
    assert not fs.isexe("/home")
    assert not fs.isexe("/not/a/real/path (I hope!)")
Ejemplo n.º 5
0
def test_binaries_exist():
    for binary in BINARIES:
        assert fs.isexe(binary)
Ejemplo n.º 6
0
 def test_binaries_exist(self):
     for binary in self.BINARIES:
         self.assertTrue(fs.isexe(binary))
Ejemplo n.º 7
0
from experimental.dsmith import Colors
from labm8 import fs


runtime_t = NewType('runtime_t', float)
status_t = NewType('status_t', int)
return_t = namedtuple('return_t', ['runtime', 'status', 'stdout', 'stderr'])

# build paths
exec_path = dsmith.root_path("third_party", "clsmith", "build", "CLSmith")
cl_launcher_path = dsmith.root_path("third_party", "clsmith", "build",
                                    "cl_launcher")
include_path = dsmith.root_path("third_party", "clsmith", "runtime")

# sanity checks
assert fs.isexe(exec_path)
assert fs.isexe(cl_launcher_path)
assert fs.isfile(fs.path(include_path, "CLSmith.h"))


def clsmith_cli(*args, timeout: int = 60, exec_path=exec_path) -> List[str]:
  return ["timeout", "--signal=9", str(timeout), exec_path] + list(args)


def clsmith(*args, exec_path=exec_path) -> return_t:
  """
      Returns:
          return_t: A named tuple consisting of runtime (float),
              status (int), stdout (str), and stderr (str).
  """
  start_time = time()