Ejemplo n.º 1
0
    def _pkgs_get_available(self):
        """ If there is no package list in the working dir, download one."""

        if not path.exists(self.pkg_list):
            self._pkgs_update_available()

        return json.loads(dftlib.read(self.pkg_list))
Ejemplo n.º 2
0
    def __init__(self, path_root_dir, path_config):
        """ Set up paths and file objects to use. """

        self.config = json.loads(dftlib.read(path_config))
        self.path_defaults = self.config["paths"]["dirs"]["defaults"]

        self.df_paths = dftlib.make_df_paths(path_root_dir, "linux")
        self.path_inits = path.join(self.df_paths["init"], "init.txt")
        self.path_d_inits = path.join(self.df_paths["init"], "d_init.txt")

        self.inits = dftlib.read_lines(self.path_inits)
        self.d_inits = dftlib.read_lines(self.path_d_inits)
Ejemplo n.º 3
0
    def _pkgs_update_available(self):
        """ If avilable packages.json doesn't exist, download it.

            If it does exist download a fresh copy, and if the
            versions differ, write the contents of the new file
            to the old one.
        """

        dftlib.ensure_dir(self.workdir)
        pkgs_web = dftlib.get_url(self.config["urls"]["pkg_list"])

        if not path.exists(path.join(self.workdir, self.pkg_list)):
            dftlib.write(self.pkg_list, pkgs_web)
        else:
            pkgs_new = json.loads(pkgs_web)
            pkgs_cur = json.loads(dftlib.read(
                path.join(self.workdir, self.pkg_list)))

            if int(pkgs_new["version"]) > int(pkgs_cur["version"]):
                dftlib.write(self.pkg_list, json.dumps(pkgs_new))
Ejemplo n.º 4
0
 def _get_opts_from_file(self, path_optsfile):
     return json.loads(dftlib.read(path_optsfile))