Ejemplo n.º 1
0
 def enforceProfiles(self):
     _srcDir = os.path.join(util.getEnvPath("THIS_DIR"), "profiles")
     if not os.path.isdir(_srcDir):
         raise ValueError("Directory %s does not exist.", _srcDir)
     for _file in glob.iglob(os.path.join(_srcDir, "*.prf")):
         _targ = os.path.join(
             util.getEnvPath("UNISON_DIR"), os.path.basename(_file))
         shutil.copyfile(_file, _targ)
Ejemplo n.º 2
0
 def readConfig(self, configName, args):
     _cfgPath = os.path.join(
         util.getEnvPath("THIS_DIR"), "cfg", configName + ".ini")
     if not os.path.exists(_cfgPath):
         raise ValueError("Config with name %s not found in %r" % (
             configName, _cfgPath))
     return util.readConfigFile(_cfgPath, args)
Ejemplo n.º 3
0
 def runUnison(self):
     _logName = "_".join(["pyUnison", self.name]) + ".log"
     _logName = os.path.join(util.getEnvPath("UNISON_DIR"), _logName)
     _logFile = file(_logName, "wb")
     _tmpProf = self.createTmpProfile()
     _args = ["unison", _tmpProf, "-ui text"]
     if "UNISONBACKUPDIR" in self.env:
         if not os.path.exists(self.env["UNISONBACKUPDIR"]):
             os.makedirs(self.env["UNISONBACKUPDIR"])
         assert os.path.isdir(self.env["UNISONBACKUPDIR"])
     _proc = subprocess.Popen(
         args=" ".join(_args),
         env=self.env,
         shell=True,
         stdout=_logFile,
         stderr=subprocess.STDOUT
     )
     _rv = _proc.wait()
     _logFile.close()
     self.runResult = {
         "rv" : _rv,
         "args": _args,
         "env": self.env,
         "log": _logName,
         "name": self.name,
     }
     return _rv
Ejemplo n.º 4
0
    def __init__(self, name, args):
        _rootBase = args.pop("root")
        _rootNames = [_name
            for _name in args.iterkeys()
            if _name.startswith("root")
        ]
        _rootNames.sort()
        _roots = [args.pop(_name) for _name in _rootNames]
        self._syncs = []

        _env = args.pop("env", {})
        assert "UNISONBACKUPDIR" not in _env

        for _root in _roots:
            _plainRoot = _root
            for _ch in (os.sep, " ", "~"):
                _plainRoot = _plainRoot.replace(_ch, "_")

            _thisEnv = _env.copy()
            if util.envIsSet("UNISON_BACKUP_ROOT"):
                _thisEnv["UNISONBACKUPDIR"] = os.path.join(
                    util.getEnvPath("UNISON_BACKUP_ROOT"),
                    name,
                    _plainRoot
                )
            args["env"] = _thisEnv

            _proc = UnisonProcess(
                name="".join((name, _plainRoot)),
                root1=_rootBase,
                root2=_root,
                **args
            )
            self._syncs.append(_proc)
Ejemplo n.º 5
0
 def createTmpProfile(self):
     _name = "auto_%s.prf" % self.name
     _fileName = os.path.join(
         util.getEnvPath("UNISON_DIR"), _name)
     file(_fileName, "w").write(self.getProfileText())
     return _name
Ejemplo n.º 6
0
 def normRoot(self, root):
     if root.startswith("~"):
         root = os.path.join(util.getEnvPath("HOME"), root.lstrip("~/"))
     if not os.path.isdir(root) and not root.startswith("ssh://"):
         raise ValueError("Root %s does not exist." % root)
     return root