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)
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)
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
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)
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
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