コード例 #1
0
ファイル: vcc_repo.py プロジェクト: fpemud/config-sync
 def reset(self):
     try:
         VccRepo._vcc2git(self.dirName)
         VccUtil.removeDirContent(self.dirName, [".git"])
         self._callGit(self.dirName, "reset --hard", "stdout")
     finally:
         VccRepo._git2vcc(self.dirName)
コード例 #2
0
ファイル: vcc_common.py プロジェクト: fpemud/config-sync
    def _sys_from_sync_etc_dir(obj, dirname):
        dataEtcDir = os.path.join(obj._data_dir, "etc")
        dataEtcTargetDir = os.path.join(dataEtcDir,
                                        dirname.replace("/etc/", ""))

        if os.path.exists(dataEtcTargetDir):
            VccUtil.ensureDir("/etc")
            subprocess.check_call(["/bin/cp", "-r", dataEtcTargetDir, "/etc"])
        else:
            VccUtil.forceDelete(dirname)
コード例 #3
0
ファイル: vcc_repo.py プロジェクト: fpemud/config-sync
    def create_repo(dir_name):
        assert os.path.isabs(dir_name)
        assert os.path.isdir(dir_name)
        assert VccUtil.isDirEmpty(dir_name)

        VccRepo._callGit(dir_name, "init", "stdout")
        VccUtil.touchFile(os.path.join(dir_name, ".metadata"))
        VccRepo._callGit(dir_name, "add .", "stdout")
        VccRepo._callGit(dir_name, "commit -a -STATUS_CONFLICTm \"first commit of %s\" "%(dir_name), "stdout")
        VccRepo._git2vcc(dir_name)
コード例 #4
0
ファイル: vcc_common.py プロジェクト: fpemud/config-sync
    def _usr_from_sync_dir_in_config(obj, dirname):
        ocfgDir = os.path.join(obj._home_dir, ".config")
        cfgDir = os.path.join(obj._data_dir, "_config")
        targetDir = os.path.join(cfgDir, dirname.replace(".config", "_config"))
        dirname = os.path.join(obj._home_dir, dirname)

        if os.path.exists(targetDir):
            VccUtil.ensureDir(ocfgDir)
            subprocess.check_call(["/bin/cp", "-r", targetDir, ocfgDir])
        else:
            VccUtil.forceDelete(dirname)
コード例 #5
0
ファイル: vcc_common.py プロジェクト: fpemud/config-sync
    def _sys_from_sync_etc_files(obj, file_pattern):
        # fixme: pattern is not supported yet
        dataEtcDir = os.path.join(obj._data_dir, "etc")
        dataEtcTargetFile = os.path.join(dataEtcDir,
                                         dirname.replace("/etc/", ""))

        if os.path.exists(dataEtcTargetFile):
            VccUtil.ensureDir("/etc")
            subprocess.check_call(["/bin/cp", dataEtcTargetFile, "/etc"])
        else:
            VccUtil.forceDelete(dirname)
コード例 #6
0
ファイル: vcc_repo.py プロジェクト: fpemud/config-sync
    def _storeMetaDataImpl(self, dir_name, pdir_name, ignoreList, cfgObj):
        """dir_name is absolute path of directory, pdir_name is relative path of directory"""

        for fb in sorted(os.listdir(dir_name)):
            f = os.path.join(dir_name, fb)
            fr = os.path.join(pdir_name, fb)
            if any(x for x in ignoreList if fnmatch.fnmatch(f, x)):
                continue
            assert VccUtil.isTrival(f)

            tname = "dir" if (os.path.isdir(f) and not os.path.islink(f)) else "file"

            if os.path.islink(f):
                tname = "symlink"
            elif os.path.isdir(f):
                tname = "dir"
            elif os.path.isfile(f):
                tname = "file"
            else:
                assert False
            mode = oct(os.lstat(f).st_mode & 0777)
            username = pwd.getpwuid(os.lstat(f).st_uid)[0]
            grouppname = grp.getgrgid(os.lstat(f).st_gid)[0]

            cfgObj.add_section(fr)
            cfgObj.set(fr, "tname", tname)
            cfgObj.set(fr, "mode", mode)
            cfgObj.set(fr, "owner", "%s:%s"%(username, grouppname))
            #cfgObj.set(fr, "mtime", "")
            #cfgObj.set(fr, "xattr", "")

            if os.path.isdir(f) and not os.path.islink(f):
                self._storeMetaDataImpl(f, fr, ignoreList, cfgObj)
コード例 #7
0
ファイル: vcc_common.py プロジェクト: fpemud/config-sync
    def _usr_to_sync_dir_in_config(obj, dirname):
        cfgDir = os.path.join(obj._data_dir, "_config")
        targetDir = os.path.join(cfgDir, dirname.replace(".config", "_config"))
        dirname = os.path.join(obj._home_dir, dirname)

        if os.path.exists(dirname):
            VccUtil.forceDelete(targetDir)
            VccUtil.ensureDir(cfgDir)
            subprocess.check_call(["/bin/cp", "-r", dirname, cfgDir])
        else:
            VccUtil.forceDelete(targetDir)
            VccUtil.deleteDirIfEmpty(cfgDir)
コード例 #8
0
ファイル: vcc_common.py プロジェクト: fpemud/config-sync
    def _sys_to_sync_etc_files(obj, file_pattern):
        # fixme: pattern is not supported yet
        dataEtcDir = os.path.join(obj._data_dir, "etc")
        dataEtcTargetFile = os.path.join(dataEtcDir,
                                         file_pattern.replace("/etc/", ""))

        if os.path.exists(file_pattern):
            VccUtil.forceDelete(dataEtcTargetFile)
            VccUtil.ensureDir(dataEtcDir)
            subprocess.check_call(["/bin/cp", file_pattern, dataEtcDir])
        else:
            VccUtil.forceDelete(dataEtcTargetFile)
            VccUtil.deleteDirIfEmpty(dataEtcDir)
コード例 #9
0
ファイル: vcc_repo.py プロジェクト: fpemud/config-sync
    def _applyMetaData(self):
        """Won't follow symbolic links"""

        ignoreList = self._internal_ignore_list()

        metadataFile = os.path.join(self.dirName, ".metadata")
        cfgObj = ConfigParser.RawConfigParser()
        cfgObj.read(metadataFile)

        for fr in cfgObj.sections():
            f = os.path.join(self.dirName, fr)
            if any(x for x in ignoreList if fnmatch.fnmatch(f, x)):
                continue

            tname = cfgObj.get(fr, "tname")
            mode = cfgObj.get(fr, "mode")
            owner = cfgObj.get(fr, "owner")

            if tname == "symlink":
                assert VccUtil.isTrival(f) and os.path.islink(f)
            elif tname == "dir":
                if not os.path.exists(f):
                    # create directory, but don't modify mtime of parent directory
                    pdir = os.path.dir_name(f)
                    if pdir != self.dirName:
                        tmtime = os.path.getmtime(pdir)
                    os.mkdir(f)
                    if pdir != self.dirName:
                        VccUtil.setFileMtime(pdir, tmtime)
                else:
                    assert VccUtil.isTrival(f) and os.path.isdir(f) and not os.path.islink(f)
            elif tname == "file":
                assert VccUtil.isTrival(f) and os.path.isfile(f) and not os.path.islink(f)
            else:
                assert False
            if not os.path.islink(f):
                VccUtil.shell("/bin/chmod %s \"%s\""%(mode, f))
            VccUtil.shell("/bin/chown -h %s \"%s\""%(owner, f))
コード例 #10
0
ファイル: vcc_repo.py プロジェクト: fpemud/config-sync
def _callGit(dir_name, command, shellMode=""):
    gitDir = os.path.join(dir_name, ".git")
    cmdStr = "/bin/git --git-dir=\"%s\" --work-tree=\"%s\" %s"%(gitDir, dir_name, command)
    return VccUtil.shell(cmdStr, shellMode)