Exemplo n.º 1
0
    def save(self, pathname=None):
        """Saves the configuration data to a file. Existing configuration will
        be removed.

        Args:
            pathname: The file to save the configuration to.
        """
        pathname = pathname or self.pathname
        if os.path.exists(pathname):
            os.remove(pathname)
        with util.fopen(pathname, "w") as cfile:
            cfile.write(json.dumps(self.data, sort_keys=True, indent=4))
        logging.info("saved configuration to %s", pathname)
Exemplo n.º 2
0
 def __init__(self, pathname=None):
     self.data = self.DEFAULTS
     self.pathname = self.PATHNAME
     if pathname is None:
         logging.info("homekeeper configuration not specified; assuming " "defaults")
         return
     self.pathname = os.path.realpath(pathname)
     if not os.path.exists(self.pathname):
         logging.info("homekeeper configuration not found; assuming " "defaults")
         return
     try:
         logging.info("found homekeeper configuration at %s", self.pathname)
         self.data = json.loads(util.fopen(self.pathname).read())
     except ValueError:
         logging.info("homekeeper configuration invalid; assuming defaults")
     if "dotfiles_directory" in self.data:
         self.data["directory"] = self.data["dotfiles_directory"]
         del self.data["dotfiles_directory"]
     if self.directory == os.path.realpath(os.getenv("HOME")):
         logging.info("your dotfiles directory cannot be your home " "directory")
         self.data["directory"] = self.DEFAULTS["directory"]
         return