コード例 #1
0
ファイル: test_make.py プロジェクト: ChrisCummins/labm8
 def test_make_clean(self,):
     fs.cd("tests/data/makeproj")
     make.make()
     self._test(True, fs.isfile("foo"))
     self._test(True, fs.isfile("foo.o"))
     make.clean()
     self._test(False, fs.isfile("foo"))
     self._test(False, fs.isfile("foo.o"))
     fs.cdpop()
コード例 #2
0
def test_make_clean():
    fs.cd("labm8/data/test/makeproj")
    make.make()
    assert fs.isfile("foo")
    assert fs.isfile("foo.o")
    make.clean()
    assert not fs.isfile("foo")
    assert not fs.isfile("foo.o")
    fs.cdpop()
コード例 #3
0
ファイル: test_fs.py プロジェクト: ChrisCummins/labm8
    def test_cd(self):
        cwd = os.getcwd()
        new = fs.abspath("..")

        self._test(new, fs.cd(".."))
        self._test(new, os.getcwd())

        self._test(cwd, fs.cdpop())
        self._test(cwd, os.getcwd())

        self._test(cwd, fs.cdpop())
        self._test(cwd, os.getcwd())

        self._test(cwd, fs.cdpop())
        self._test(cwd, os.getcwd())
コード例 #4
0
ファイル: fs_test.py プロジェクト: 50417/DeepFuzzSL
def test_cd():
    cwd = os.getcwd()
    new = fs.abspath("..")

    assert new == fs.cd("..")
    assert new == os.getcwd()

    assert cwd == fs.cdpop()
    assert cwd == os.getcwd()

    assert cwd == fs.cdpop()
    assert cwd == os.getcwd()

    assert cwd == fs.cdpop()
    assert cwd == os.getcwd()
コード例 #5
0
ファイル: make.py プロジェクト: ChrisCummins/phd
def make(target="all", dir=".", **kwargs):
    """
    Run make clean.

    Arguments:

        target (str, optional): Name of the target to build. Defaults
          to "all".
        dir (str, optional): Path to directory containing Makefile.
        **kwargs (optional): Any additional arguments to be passed to
          system.run().

    Returns:

        (int, str, str): The first element is the return code of the
          make command. The second and third elements are the stdout
          and stderr of the process.

    Raises:

        NoMakefileError: In case a Makefile is not found in the target
          directory.
        NoTargetError: In case the Makefile does not support the
          requested target.
        MakeError: In case the target rule fails.
    """
    if not fs.isfile(fs.path(dir, "Makefile")):
        raise NoMakefileError("No makefile in '{}'".format(fs.abspath(dir)))

    fs.cd(dir)

    # Default parameters to system.run()
    if "timeout" not in kwargs: kwargs["timeout"] = 300

    ret, out, err = system.run(["make", target], **kwargs)
    fs.cdpop()

    if ret > 0:
        if re.search(_BAD_TARGET_RE, err):
            raise NoTargetError("No rule for target '{}'"
                                .format(target))
        else:
            raise MakeError("Target '{}' failed".format(target))

        raise MakeError("Failed")

    return ret, out, err
コード例 #6
0
def make(target="all", dir=".", **kwargs):
    """
  Run make.

  Arguments:

      target (str, optional): Name of the target to build. Defaults
        to "all".
      dir (str, optional): Path to directory containing Makefile.
      **kwargs (optional): Any additional arguments to be passed to
        system.run().

  Returns:

      (int, str, str): The first element is the return code of the
        make command. The second and third elements are the stdout
        and stderr of the process.

  Raises:

      NoMakefileError: In case a Makefile is not found in the target
        directory.
      NoTargetError: In case the Makefile does not support the
        requested target.
      MakeError: In case the target rule fails.
  """
    if not fs.isfile(fs.path(dir, "Makefile")):
        raise NoMakefileError("No makefile in '{}'".format(fs.abspath(dir)))

    fs.cd(dir)

    # Default parameters to system.run()
    if "timeout" not in kwargs: kwargs["timeout"] = 300

    ret, out, err = system.run(["make", target], **kwargs)
    fs.cdpop()

    if ret > 0:
        if re.search(_BAD_TARGET_RE, err):
            raise NoTargetError("No rule for target '{}'".format(target))
        else:
            raise MakeError("Target '{}' failed".format(target))

        raise MakeError("Failed")

    return ret, out, err
コード例 #7
0
def unpack_archive(*components, **kwargs):
    """
    Unpack a compressed archive.

    Arguments:
        *components (str[]): Absolute path.
        compression (str, optional): Archive compression type.
    """
    path = fs.path(*components)
    compression = kwargs.get("compression", "bz2")

    # extract tar relative to it's directory
    fs.cd(fs.dirname(path))

    tar = tarfile.open(path, "r:" + compression)
    tar.extractall()
    tar.close()

    fs.cdpop()
コード例 #8
0
ファイル: tar.py プロジェクト: ChrisCummins/labm8
def unpack_archive(*components, **kwargs) -> str:
    """
    Unpack a compressed archive.

    Arguments:
        *components (str[]): Absolute path.
        **kwargs (dict, optional): Set "compression" to compression type.
            Default: bz2. Set "dir" to destination directory. Defaults to the
            directory of the archive.

    Returns:
        str: Path to directory.
    """
    path = fs.abspath(*components)
    compression = kwargs.get("compression", "bz2")
    dir = kwargs.get("dir", fs.dirname(path))

    fs.cd(dir)
    tar = tarfile.open(path, "r:" + compression)
    tar.extractall()
    tar.close()
    fs.cdpop()

    return dir
コード例 #9
0
def unpack_archive(*components, **kwargs) -> str:
    """
    Unpack a compressed archive.

    Arguments:
        *components (str[]): Absolute path.
        **kwargs (dict, optional): Set "compression" to compression type.
            Default: bz2. Set "dir" to destination directory. Defaults to the
            directory of the archive.

    Returns:
        str: Path to directory.
    """
    path = fs.abspath(*components)
    compression = kwargs.get("compression", "bz2")
    dir = kwargs.get("dir", fs.dirname(path))

    fs.cd(dir)
    tar = tarfile.open(path, "r:" + compression)
    tar.extractall()
    tar.close()
    fs.cdpop()

    return dir