コード例 #1
0
 def _generateConfigByExpand(self, srcPath, destPath, noReplace, settings):
     content = file_util.readFromFile(srcPath)
     if content is None:
         Log.cout(Log.ERROR, 'Read config file %s failed' % srcPath)
         return False
     replacer = KeyValueReplacer(settings)
     content = replacer.replace(content)
     return file_util.writeToFile(destPath, content)
コード例 #2
0
 def getPkgCrontabs(self):
     pkgCrontabs = {}
     crontabDir = self._ainstRoot.getRootVarDir('cron')
     activeDir = self._ainstRoot.getRootVarAinstDir('active')
     cronFiles = file_util.listDir(crontabDir)
     if not cronFiles:
         return pkgCrontabs
     for cronFile in cronFiles:
         activePath = activeDir + '/' + cronFile
         linkPath = file_util.readLink(activePath)
         if linkPath and linkPath.startswith('../packages/'):
             cronFilePath = crontabDir + '/' + cronFile
             content = file_util.readFromFile(cronFilePath)
             if content:
                 pkgCrontabs[cronFile] = content
     return pkgCrontabs
コード例 #3
0
ファイル: root_info.py プロジェクト: luckylecher/cpp
    def load(self, path):
        if not file_util.isFile(path):
            Log.cout(Log.DEBUG, 'Root info file %s is not exists' % path)
            return RootInfo()
        content = file_util.readFromFile(path)
        if content is None:
            Log.cout(Log.ERROR, 'Read root info file %s failed' % path)
            return None

        rootInfo = RootInfo()
        lines = content.split('\n')
        for line in lines:
            line = line.strip()
            if line == '':
                continue
            rootInfo.installRootSet.add(line)
        return rootInfo
コード例 #4
0
ファイル: root_info.py プロジェクト: luckylecher/cpp
    def load(self, path):
        if not file_util.isFile(path):
            Log.cout(Log.DEBUG, 'Root info file %s is not exists' % path)
            return RootInfo()
        content = file_util.readFromFile(path)
        if content is None:
            Log.cout(Log.ERROR, 'Read root info file %s failed' % path)
            return None

        rootInfo = RootInfo()
        lines = content.split('\n')
        for line in lines:
            line = line.strip()
            if line == '':
                continue
            rootInfo.installRootSet.add(line)
        return rootInfo
コード例 #5
0
ファイル: unset_file_parser.py プロジェクト: luckylecher/cpp
    def parse(self, fileName):
        content = file_util.readFromFile(fileName)
        if content is None:
            Log.cout(Log.ERROR, 'Read unset file [%s] failed' % fileName)
            return None

        unsetDict = {}
        lines = content.split('\n')
        for line in lines:
            line = line.strip()
            if line == '' or line.startswith('#'):
                continue
            items = line.split('.')
            if len(items) < 2:
                continue
            pkgName = items[0]
            key = ('.').join(items[1:])
            unsetDict.setdefault(pkgName, set([])).add(key)

        return unsetDict
コード例 #6
0
ファイル: unset_file_parser.py プロジェクト: luckylecher/cpp
    def parse(self, fileName):
        content = file_util.readFromFile(fileName)
        if content is None:
            Log.cout(Log.ERROR, 'Read unset file [%s] failed' % fileName)
            return None

        unsetDict = {}
        lines = content.split('\n')
        for line in lines:
            line =  line.strip()
            if line == '' or line.startswith('#'):
                continue
            items = line.split('.')
            if len(items) < 2:
                continue
            pkgName = items[0]
            key = ('.').join(items[1:])
            unsetDict.setdefault(pkgName, set([])).add(key)
            
        return unsetDict
コード例 #7
0
    def parse(self, fileName):
        content = file_util.readFromFile(fileName)
        if content is None:
            Log.cout(Log.ERROR, 'Read aicf file [%s] failed' % fileName)
            return None

        aicfInfo = AicfInfo()
        lines = content.split('\n')
        for line in lines:
            line =  line.strip()
            if line == '' or line.startswith('#'):
                continue
            items = line.split()
            if items[0] == 'set':
                if not self._parseSettings(aicfInfo, items[1:]):
                    Log.cout(Log.ERROR, 'Parse aicf settings failed [%s]' % fileName)
                    return None
            elif items[0] == 'unset':
                if not self._parseUnSettings(aicfInfo, items[1:]):
                    Log.cout(Log.ERROR, 'Parse aicf unsettings failed [%s]' % fileName)
                    return None
            elif items[0] == 'autostart':
                if not self._parseAutoStart(aicfInfo, items[1:]):
                    Log.cout(Log.ERROR, 'Parse aicf autostart failed [%s]' % fileName)
                    return None
            elif items[0] == 'crontab':
                if not self._parseCrontabs(aicfInfo, items[1:]):
                    Log.cout(Log.ERROR, 'Parse aicf crontabs failed [%s]' % fileName)
                    return None
            elif items[0] == 'config':
                if not self._parseConfigs(aicfInfo, items[1:]):
                    Log.cout(Log.ERROR, 'Parse aicf config failed [%s]' % fileName)
                    return None
            elif items[0] == 'script':
                if not self._parseScripts(aicfInfo, items[1:]):
                    Log.cout(Log.ERROR, 'Parse aicf script failed [%s]' % fileName)
                    return None
            else:
                Log.cout(Log.ERROR, 'Parse aicf failed: illegal fields [%s]' % fileName)
                return None
        return aicfInfo
コード例 #8
0
 def parse(self, path):
     if not file_util.exists(path):
         Log.cout(Log.DEBUG, 'Path [%s] not exists' % path)
         return {}
     content = file_util.readFromFile(path)
     if content is None:
         Log.cout(Log.ERROR, 'Read setting file [%s] failed' % path)
         return None
     lines = content.split('\n')
     settingMap = {}
     for line in lines:
         if line.strip() == '':
             continue
         pos = line.find('=')
         if pos == -1:
             Log.cout(Log.ERROR, 'Setting file [%s ]illega' % path)
             return None
         key = line[0:pos]
         value = line[pos+1:]
         settingMap[key] = value
     return settingMap
コード例 #9
0
 def _getHostSet(self, host, hostFile):
     itemList = []
     if hostFile:
         for fileName in hostFile:
             content = file_util.readFromFile(fileName)
             if content is None:
                 Log.cout(Log.ERROR, 'Invaild hostfile %s' % fileName)
                 return None
             itemList.extend(content.split())
     if host:
         resultList = self._splitHost(host)
         if resultList:
             itemList.extend(resultList)
     ipSet = set()
     expander = HostExpander()
     for item in itemList:
         if not item or not item.strip():
             continue
         hostList = expander.expand(item.strip())
         if hostList:
             ipSet.update(set(hostList))
     return ipSet
コード例 #10
0
ファイル: remote_operator.py プロジェクト: luckylecher/cpp
 def _getHostSet(self, host, hostFile):
     itemList = []
     if hostFile:
         for fileName in hostFile:
             content = file_util.readFromFile(fileName)
             if content is None:
                 Log.cout(Log.ERROR, 'Invaild hostfile %s' % fileName)
                 return None
             itemList.extend(content.split())
     if host:
         resultList = self._splitHost(host)
         if resultList:
             itemList.extend(resultList)
     ipSet = set()
     expander = HostExpander()
     for item in itemList:
         if not item or not item.strip():
             continue
         hostList = expander.expand(item.strip())
         if hostList:
             ipSet.update(set(hostList))
     return ipSet
コード例 #11
0
ファイル: root_state.py プロジェクト: luckylecher/cpp
 def getRootStateFromFile(self, filePath):
     content = file_util.readFromFile(filePath)
     if not content:
         return None
     return self.toRootState(content)
コード例 #12
0
ファイル: root_state.py プロジェクト: luckylecher/cpp
 def getRootStateFromFile(self, filePath):
     content = file_util.readFromFile(filePath)
     if not content:
         return None
     return self.toRootState(content)