Example #1
0
    def __init__(self, path, basecache=None):
        """
        Create a new JSON cache.

        Optionally supports populating the cache with values of an
        existing cache.

        Arguments:
           basecache (TransientCache, optional): Cache to populate this new
             cache with.
        """

        super(JsonCache, self).__init__()
        self.path = fs.abspath(path)

        if fs.exists(self.path):
            io.debug(("Loading cache '{0}'".format(self.path)))
            with open(self.path) as file:
                self._data = json.load(file)

        if basecache is not None:
            for key,val in basecache.items():
                self._data[key] = val

        # Register exit handler
        atexit.register(self.write)
Example #2
0
def main():
    """
    Reduce all databases to oracle.
    """
    dbs = [migrate(_db.Database(path)) for path in
           fs.ls(experiment.DB_DEST, abspaths=True)
           if not re.search("oracle.db$", path)
           and re.search(".db$", path)]
    merge(fs.abspath(experiment.DB_DEST, "oracle.db"),
          dbs, experiment.ORACLE_PATH)
Example #3
0
    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())
Example #4
0
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
Example #5
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
Example #6
0
 def test_basename(self):
     self._test("foo", fs.basename("foo"))
     self._test("foo", fs.basename(fs.abspath("foo")))
Example #7
0
 def test_abspath_homedir(self):
     self._test(os.path.expanduser("~"), fs.abspath("~"))
     self._test(os.path.join(os.path.expanduser("~"), "foo"),
                fs.abspath("~", "foo"))
Example #8
0
 def test_abspath(self):
     self._test(os.path.abspath(".") + "/foo/bar",
                fs.abspath("foo", "bar"))
     self._test(os.path.abspath(".") + "/foo/bar/car",
                fs.abspath("foo/bar", "car"))
Example #9
0
def load_config(path="~/.omnitunerc.json"):
    path = fs.abspath(path)
    if fs.isfile(path):
        return json.load(open(path))
    else:
        raise ConfigNotFoundError("File '{}' not found!".format(path))