Beispiel #1
0
    def init(self):
        if self._inited:
            return True, None

        if not self._root:
            return False, None

        markFilePath = self._root + '/' + self._ainstRootMarkFile
        initTrace = []
        if not file_util.isDir(self._root):
            if not file_util.makeDir(self._root):
                self.clearInit(initTrace)
                return False, None
            initTrace.append(self._root)
            if not file_util.writeToFile(markFilePath, ''):
                self.clearInit(initTrace)
                return False, None
            initTrace.append(markFilePath)
        else:
            if not file_util.isFile(markFilePath):
                subDirs = file_util.listDir(self._root)
                if subDirs and len(subDirs) > 0:
                    self.clearInit(initTrace)
                    return False, None
                if not file_util.writeToFile(markFilePath, ''):
                    self.clearInit(initTrace)
                    return False, None
                initTrace.append(markFilePath)

        if not self._initRoot(initTrace):
            return False, None
        os.environ[self._installRootEnvKey] = self._root
        self._inited = True
        return True, initTrace
Beispiel #2
0
 def dump(self, settingMap, destPath):
     if settingMap is None:
         return False
     content = ''
     for key, value in settingMap.iteritems():
         content += str(key) + '=' + str(value) + '\n'
     return file_util.writeToFile(destPath, content)
Beispiel #3
0
 def _onMakeCacheSuccess(self, cacheType):
     cachecookie = self._getRepoDataDir() + '/' + 'cachecookie'
     if not file_util.remove(cachecookie) or\
             not file_util.writeToFile(cachecookie, '') or\
             not file_util.chmod(cachecookie, 0666):
         Log.cout(Log.ERROR, 'Re-touch cachecookie failed')
         return False
Beispiel #4
0
    def _getMetaFile(self, repoMdObj, metaName, fileName):
        if not repoMdObj.repoMdDatas.has_key(metaName):
            return False
        metaObj = repoMdObj.repoMdDatas[metaName]
        destTmpFile = self._getRepoDataDir() + '/' + \
            metaObj.locationHref.split('/')[-1]
        metaUrl = self.repoConfig.baseurl + '/' + metaObj.locationHref
#        uncompressTmpFile = '.'.join(destTmpFile.split('.')[:-1]) + '.tmp'
        uncompressTmpFile = self._getRepoDataDir() + '/' + \
            fileName + '.tmp'
        if not file_util.remove(destTmpFile) or\
                not file_util.remove(uncompressTmpFile):
            return False
        if not self.fileFetcher.fetch(metaUrl, destTmpFile) or\
                not file_util.chmod(destTmpFile, 0666):
            return False
        try:
            if destTmpFile.split('.')[-1] == 'bz2':
                f = bz2.BZ2File(destTmpFile)
            else:
                f = gzip.open(destTmpFile)
            if not file_util.writeToFile(uncompressTmpFile, f.read()) or\
                    not file_util.chmod(uncompressTmpFile, 0666):
                f.close()
                return False
            f.close()
        except Exception:
            Log.cout(Log.ERROR, 'decompress %s failed' % destTmpFile)
            return False
        return self._checkSumValid(metaObj, uncompressTmpFile)
Beispiel #5
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)
Beispiel #6
0
def microbench(srcFile, benchFile, depth, cleanupFn, pathoFn, buildCmd):
    deleteFile(benchFile)

    d = 1
    while (d <= depth):
        # clean up after previous loop iteration
        cleanupFn()

        # build up pathological case
        src = pathoFn(d)
        print(src)
        writeToFile(srcFile, src)

        # time compilation
        measure(str(d), benchFile, buildCmd)

        d = d + 1
Beispiel #7
0
 def _generateConfigByTemplate(self, srcPath, destPath, noReplace, settings):
     out, err, code = process.runRedirected(srcPath)
     if code != 0:
         Log.cout(Log.ERROR, 'Generat template config file %s failed: %s' % (destPath, err))
         return False
     if not file_util.writeToFile(destPath, out):
         Log.cout(Log.ERROR, 'Write config file to %s failed' % destPath)
         return False
     return True
Beispiel #8
0
    def execute(self):
        if self._executed:
            return False
        self._executed = True

        Log.cout(Log.INFO, 'Save root state...')

        if not self._ainstRoot.checkRoot():
            Log.cout(Log.ERROR, 'Check ainst root failed')
            return False

        saveDir = self._ainstRoot.getRootVarAinstDir('save')
        settingsDir = self._ainstRoot.getRootVarAinstDir('settings')
        tmpDir = self._ainstRoot.getRootVarAinstDir('tmp')
        if not saveDir or not settingsDir or not tmpDir:
            Log.cout(Log.ERROR,
                     'There is not save, settings or tmp dir in installroot')
            return False

        if not self._ainstRoot.isValidAinstRoot():
            Log.cout(Log.ERROR,
                     '%s is invalid ainst root' % self._ainstRoot.getRoot())
            return False
        reader = AinstRootReader(self._ainstRoot)
        activePkgs = reader.getActivePackages()
        activePkgNames = [pkgName for pkgName, pkgVer, mtime in activePkgs]
        activePkgInfos = [(pkgVer, mtime)
                          for pkgName, pkgVer, mtime in activePkgs]
        activePkgInfos = sorted(activePkgInfos, key=lambda pkg: pkg[1])
        pkgSettings = reader.getPkgSettings(activePkgNames)

        state = RootState(time.time(), self._command,
                          self._ainstRoot.getRoot(), common.AINST_VERSION,
                          activePkgInfos, pkgSettings)
        content = RootStateStreamer().toString(state)
        if not content:
            Log.cout(Log.ERROR, 'Generate root state content failed')
            return False

        stateFileName = reader.getNextStateFileName()
        self._tmpFile = tmpDir + stateFileName
        if not file_util.writeToFile(self._tmpFile, content):
            Log.cout(Log.ERROR, 'Write state to %s failed' % self._tmpFile)
            return False

        saveFile = saveDir + stateFileName
        if self._saveFile:
            saveFile = self._saveFile

        if not file_util.move(self._tmpFile, saveFile):
            Log.cout(Log.ERROR, 'Move root state file %s failed' % saveFile)
            self.undo()
            return False

        self._stateFileName = saveFile
        return True
Beispiel #9
0
 def dump(self, rootInfo, path):
     content = ''
     for installRoot in rootInfo.installRootSet:
         content += installRoot + '\n'
     preUmask = os.umask(0)
     ret = file_util.writeToFile(path, content)
     os.umask(preUmask)
     if not ret:
         Log.cout(Log.ERROR, 'Dump to [%s] failed' % path)
     return ret
Beispiel #10
0
 def dump(self, rootInfo, path):
     content = ''
     for installRoot in rootInfo.installRootSet:
         content += installRoot + '\n'
     preUmask = os.umask(0)
     ret = file_util.writeToFile(path, content)
     os.umask(preUmask)
     if not ret:
         Log.cout(Log.ERROR, 'Dump to [%s] failed' % path)
     return ret
Beispiel #11
0
 def fetch(self, srcUrl, destFile):
     content = ''
     for i in range(self.tryTimes):
         ret, content = self._doFetch(srcUrl)
         if ret != FetchError.FETCH_TIMEOUT:
             break
     if ret != FetchError.FETCH_SUCCESS:
         err = FetchError.getErrorString(ret)
         Log.cout(Log.ERROR, 'Fetch [%s] failed: %s' % (srcUrl, err))
         return False
     return file_util.writeToFile(destFile, content)
Beispiel #12
0
 def fetch(self, srcUrl, destFile):
     content = ''
     for i in range(self.tryTimes):
         ret, content = self._doFetch(srcUrl)
         if ret != FetchError.FETCH_TIMEOUT:
             break
     if ret != FetchError.FETCH_SUCCESS:
         err = FetchError.getErrorString(ret)
         Log.cout(Log.ERROR, 'Fetch [%s] failed: %s' % (srcUrl, err))
         return False
     return file_util.writeToFile(destFile, content)
Beispiel #13
0
 def _onMakeCacheSuccess(self, cacheType):
     cachecookie = self._getRepoDataDir() + '/' + 'cachecookie';
     if not file_util.remove(cachecookie) or\
             not file_util.writeToFile(cachecookie, '') or\
             not file_util.chmod(cachecookie, 0666):
         Log.cout(Log.ERROR, 'Re-touch cachecookie failed')
         return False
     repomdTmpFile = self._getRepoDataDir() + '/' + \
         self.repomdLocation.split('/')[-1];
     if not file_util.rename(repomdTmpFile + '.tmp', repomdTmpFile):
         return False
     return self._processTmpFile(cacheType, True)
Beispiel #14
0
    def execute(self):
        if self._executed:
            return False
        self._executed = True

        Log.cout(Log.INFO, 'Save root state...')

        if not self._ainstRoot.checkRoot():
            Log.cout(Log.ERROR, 'Check ainst root failed')
            return False

        saveDir = self._ainstRoot.getRootVarAinstDir('save')
        settingsDir = self._ainstRoot.getRootVarAinstDir('settings')
        tmpDir = self._ainstRoot.getRootVarAinstDir('tmp')
        if not saveDir or not settingsDir or not tmpDir:
            Log.cout(Log.ERROR, 'There is not save, settings or tmp dir in installroot')
            return False

        if not self._ainstRoot.isValidAinstRoot():
            Log.cout(Log.ERROR, '%s is invalid ainst root' % self._ainstRoot.getRoot())
            return False
        reader = AinstRootReader(self._ainstRoot)
        activePkgs = reader.getActivePackages()
        activePkgNames = [pkgName for pkgName, pkgVer, mtime in activePkgs]
        activePkgInfos = [(pkgVer, mtime) for pkgName, pkgVer, mtime in activePkgs]
        activePkgInfos = sorted(activePkgInfos, key = lambda pkg : pkg[1])
        pkgSettings = reader.getPkgSettings(activePkgNames)

        state = RootState(time.time(), self._command, self._ainstRoot.getRoot(),
                          common.AINST_VERSION, activePkgInfos, pkgSettings)
        content = RootStateStreamer().toString(state)
        if not content:
            Log.cout(Log.ERROR, 'Generate root state content failed')
            return False
            
        stateFileName = reader.getNextStateFileName()
        self._tmpFile = tmpDir + stateFileName
        if not file_util.writeToFile(self._tmpFile, content):
            Log.cout(Log.ERROR, 'Write state to %s failed' % self._tmpFile)
            return False

        saveFile = saveDir + stateFileName
        if self._saveFile:
            saveFile = self._saveFile

        if not file_util.move(self._tmpFile, saveFile):
            Log.cout(Log.ERROR, 'Move root state file %s failed' % saveFile)
            self.undo()
            return False

        self._stateFileName = saveFile
        return True
Beispiel #15
0
    def _initRoot(self, initTrace):
        for name in self._rootDirs:
            if file_util.isDir(self._rootDirs[name]):
                continue
            if not file_util.makeDir(self._rootDirs[name]):
                self.clearInit(initTrace)
                return False
            initTrace.append(self._rootDirs[name])

        for name in self._rootVarDirs:
            if file_util.isDir(self._rootVarDirs[name]):
                continue
            if not file_util.makeDir(self._rootVarDirs[name]):
                self.clearInit(initTrace)
                return False
            initTrace.append(self._rootVarDirs[name])

        for name in self._rootVarAinstDirs:
            if file_util.isDir(self._rootVarAinstDirs[name]):
                continue
            if not file_util.makeDir(self._rootVarAinstDirs[name]):
                self.clearInit(initTrace)
                return False
            initTrace.append(self._rootVarAinstDirs[name])

        initRootState = self._rootVarAinstDirs['save'] + 'root-state-0'
        if not file_util.exists(initRootState):
            state = RootState(time.time(), '', self._root,
                              common.AINST_VERSION, [], {})
            content = RootStateStreamer().toString(state)
            if not content or not file_util.writeToFile(initRootState, content):
                self.clearInit(initTrace)
                return False
            initTrace.append(initRootState)

        if not self._clearTmp:
            if not file_util.remove(self._rootVarAinstDirs['tmp']) or\
                    not file_util.makeDir(self._rootVarAinstDirs['tmp']):
                self.clearInit(initTrace)
                return False
            self._clearTmp = True
        return True
Beispiel #16
0
    def _generateCrontabFile(self):
        if not self._aicfInfo or not self._aicfInfo.crontabs:
            return True

        content = ''
        content += self._ainstRoot.getInstallRootEnvKey() + \
            '=' + self._ainstRoot.getRoot() + '\n'
        ainstPath = self._ainstPkgDir + '/ainst/'
        content += self._ainstDirKey + '=' + ainstPath + '\n'
        for crontab in self._aicfInfo.crontabs:
            content += crontab + '\n'

        crontabFile = self._ainstRoot.getRootVarDir('cron') + self._pkg.name
        if not file_util.remove(crontabFile) or\
                not file_util.writeToFile(crontabFile, content):
            Log.cout(Log.ERROR,
                     'Generate crontab file %s failed' % crontabFile)
            return False
        self._generatedCrontab = True
        return True
Beispiel #17
0
        metaUrl = self.repoConfig.baseurl + '/' + metaObj.locationHref
        #        uncompressTmpFile = '.'.join(destTmpFile.split('.')[:-1]) + '.tmp'
        uncompressTmpFile = self._getRepoDataDir() + '/' + \
            fileName + '.tmp'
        if not file_util.remove(destTmpFile) or\
                not file_util.remove(uncompressTmpFile):
            return False
        if not self.fileFetcher.fetch(metaUrl, destTmpFile) or\
                not file_util.chmod(destTmpFile, 0666):
            return False
        try:
            if destTmpFile.split('.')[-1] == 'bz2':
                f = bz2.BZ2File(destTmpFile)
            else:
                f = gzip.open(destTmpFile)
            if not file_util.writeToFile(uncompressTmpFile, f.read()) or\
                    not file_util.chmod(uncompressTmpFile, 0666):
                f.close()
                return False
            f.close()
        except Exception:
            Log.cout(Log.ERROR, 'decompress %s failed' % destTmpFile)
            return False
        return self._checkSumValid(metaObj, uncompressTmpFile)

    def _needMakeCache(self, metatype):
        #check cachecookie
        cachecookie = self._getRepoDataDir() + '/' + 'cachecookie'
        if not file_util.exists(cachecookie):
            return (True, metatype)
        ctime = os.stat(cachecookie).st_ctime