def installPackage(self, pkgName, bTest): # modify dynamic config self.infoPrinter.printInfo(">> Preparing...") if True: dcm = DynCfgModifier() dcm.updateMirrors() dcm.updateDownloadCommand() dcm.updateParallelism(self.param.machineInfoGetter.hwInfo()) dcm.updateCcache() print("") # get build server if BuildServerSelector.hasBuildServerCfgFile(): self.infoPrinter.printInfo(">> Selecting build server...") buildServer = BuildServerSelector.selectBuildServer() print("") else: buildServer = None # sync up files to server if buildServer is not None: self.infoPrinter.printInfo(">> Synchronizing up...") buildServer.syncUp() buildServer.startWorking() print("") # emerge package self.infoPrinter.printInfo(">> Installing %s..." % (pkgName)) cmd = "/usr/libexec/fpemud-os-sysman/op-emerge-package.py" tmpOp = "1" if bTest else "0" if buildServer is not None: try: buildServer.sshExec(cmd, pkgName, tmpOp) finally: self.infoPrinter.printInfo( ">> Synchronizing down system files...") buildServer.syncDownSystem() print("") else: FmUtil.cmdExec(cmd, pkgName, tmpOp) # end remote build if buildServer is not None: buildServer.dispose()
def _execAndSyncDownQuietly(self, buildServer, *args, directory=None): if buildServer is None: FmUtil.cmdExec(*args) else: buildServer.sshExec(*args) buildServer.syncDownDirectory(directory, quiet=True)
def _exec(self, buildServer, *args, base64=False): if buildServer is None: FmUtil.cmdExec(*args) else: buildServer.sshExec(*args, base64=base64)
def update(self, bSync, bFetchAndBuild): if self.param.runMode in ["normal", "setup"]: layout = strict_hdds.get_storage_layout() else: layout = None bbkiObj = BbkiWrapper(layout) pkgwh = PkgWarehouse() overlayDb = CloudOverlayDb() # set system to unstable status if self.param.runMode in ["normal", "setup"]: if bbkiObj.isStable(): with BootDirWriter(layout): bbkiObj.setStable(False) # modify dynamic config self.infoPrinter.printInfo(">> Preparing...") if True: dcm = DynCfgModifier() dcm.updateMirrors() dcm.updateDownloadCommand() dcm.updateParallelism(self.param.machineInfoGetter.hwInfo()) dcm.updateCcache() print("") # get build server if BuildServerSelector.hasBuildServerCfgFile(): self.infoPrinter.printInfo(">> Selecting build server...") buildServer = BuildServerSelector.selectBuildServer() print("") else: buildServer = None # sync up and start working if buildServer is not None: self.infoPrinter.printInfo(">> Synchronizing up...") buildServer.syncUp() buildServer.startWorking() print("") # do sync if bSync: # sync bbki repositories with ParallelRunSequencialPrint() as prspObj: if buildServer is not None: startCoro = buildServer.asyncStartSshExec waitCoro = buildServer.asyncWaitSshExec else: startCoro = FmUtil.asyncStartCmdExec waitCoro = FmUtil.asyncWaitCmdExec for repo in bbkiObj.repositories: prspObj.add_task( startCoro, [ self.opSync, self.param.runMode, "sync-bbki-repo", repo.name ], waitCoro, pre_func=lambda x=repo.name: self.infoPrinter. printInfo(">> Synchronizing BBKI repository \"%s\"..." % (x)), post_func=lambda: print(""), ) # FIXME: there should be no sync down after realtime network filesystem support is done if buildServer is not None: buildServer.syncDownDirectory(FmConst.portageDataDir) # sync repository directories for repoName in pkgwh.repoman.getRepositoryList(): repoDir = pkgwh.repoman.getRepoDir(repoName) self.infoPrinter.printInfo( ">> Synchronizing repository \"%s\"..." % (repoName)) self._execAndSyncDownQuietly(buildServer, self.opSync, self.param.runMode, "sync-repo", repoName, directory=repoDir) print("") # update cloud overlay db self.infoPrinter.printInfo( ">> Synchronizing cloud overlay database...") overlayDb.update() print("") # sync overlay directories with ParallelRunSequencialPrint() as prspObj: if buildServer is not None: startCoro = buildServer.asyncStartSshExec waitCoro = buildServer.asyncWaitSshExec else: startCoro = FmUtil.asyncStartCmdExec waitCoro = FmUtil.asyncWaitCmdExec for repo in pkgwh.layman.getOverlayList(): if pkgwh.layman.getOverlayType(repo) == "static": continue prspObj.add_task( startCoro, [ self.opSync, self.param.runMode, "sync-overlay", repo ], waitCoro, pre_func=lambda x=repo: self.infoPrinter.printInfo( ">> Synchronizing overlay \"%s\"..." % (x)), post_func=lambda: print(""), ) # FIXME: there should be no sync down after realtime network filesystem support is done if buildServer is not None: buildServer.syncDownDirectory(FmConst.portageDataDir) # add pre-enabled overlays for repo, ourl in pkgwh.getPreEnableOverlays().items(): if not pkgwh.layman.isOverlayExist(repo): self.infoPrinter.printInfo( ">> Installing overlay \"%s\"..." % repo) vcsType = "git" if overlayDb.hasOverlay(repo): vcsType, ourl = overlayDb.getOverlayVcsTypeAndUrl(repo) if ourl is None: raise Exception("no URL for overlay %s" % repo) if buildServer is None: FmUtil.cmdExec(self.opSync, self.param.runMode, "add-trusted-overlay", repo, vcsType, ourl) else: buildServer.sshExec(self.opSync, "add-trusted-overlay", repo, vcsType, ourl) buildServer.syncDownWildcardList([ os.path.join(pkgwh.layman.getOverlayFilesDir(repo), "***"), pkgwh.layman.getOverlayDir(repo), pkgwh.layman.getOverlayCfgReposFile(repo), ], quiet=True) print("") # add pre-enabled overlays by pre-enabled package for repo, data in pkgwh.getPreEnablePackages().items(): ourl = data[0] if not pkgwh.layman.isOverlayExist(repo): self.infoPrinter.printInfo( ">> Installing overlay \"%s\"..." % repo) vcsType = "git" if overlayDb.hasOverlay(repo): vcsType, ourl = overlayDb.getOverlayVcsTypeAndUrl(repo) if ourl is None: raise Exception("no URL for overlay %s" % repo) if buildServer is None: FmUtil.cmdExec(self.opSync, self.param.runMode, "add-transient-overlay", repo, vcsType, ourl) else: buildServer.sshExec(self.opSync, self.param.runMode, "add-transient-overlay", repo, vcsType, ourl) buildServer.syncDownWildcardList([ os.path.join(pkgwh.layman.getOverlayFilesDir(repo), "***"), pkgwh.layman.getOverlayDir(repo), pkgwh.layman.getOverlayCfgReposFile(repo), ], quiet=True) print("") # add pre-enabled packages for repo, data in pkgwh.getPreEnablePackages().items(): tlist = [ x for x in data[1] if not pkgwh.layman.isOverlayPackageEnabled(repo, x) ] if tlist != []: self.infoPrinter.printInfo( ">> Enabling packages in overlay \"%s\"..." % repo) self._exec(buildServer, self.opSync, self.param.runMode, "enable-overlay-package", repo, *tlist) print("") if buildServer is not None: buildServer.syncDownDirectory(os.path.join( FmConst.portageDataDir, "overlay-*"), quiet=True) # refresh package related stuff self._execAndSyncDownQuietly(buildServer, self.opSync, self.param.runMode, "refresh-package-related-stuff", directory=FmConst.portageCfgDir) # eliminate "Performing Global Updates" self._execAndSyncDownQuietly( buildServer, self.opSync, self.param.runMode, "touch-portage-tree", directory=FmConst.portageDbDir) # FIXME # do fetch and build if True: resultFile = os.path.join(self.param.tmpDir, "result.txt") kernelCfgRules = json.dumps( self.param.machineInfoGetter.hwInfo().kernelCfgRules) # install kernel, initramfs and bootloader with BootDirWriter(layout): self.infoPrinter.printInfo(">> Installing %s-%s..." % (bbkiObj.get_kernel_atom().fullname, bbkiObj.get_kernel_atom().ver)) if True: self._exec(buildServer, self.opInstallKernel, self.param.runMode, kernelCfgRules, resultFile) # kernelBuilt, postfix = self._parseKernelBuildResult(self._readResultFile(buildServer, resultFile)) print("") if buildServer is not None: self.infoPrinter.printInfo( ">> Synchronizing down /boot, /lib/modules and /lib/firmware..." ) buildServer.syncDownKernel() print("") self.infoPrinter.printInfo(">> Creating initramfs...") if True: if self.param.runMode in ["normal", "setup"]: bbkiObj.installInitramfs() else: print( "WARNING: Running in \"%s\" mode, do NOT create initramfs!!!" % (self.param.runMode)) print("") self.infoPrinter.printInfo(">> Updating boot-loader...") if self.param.runMode in ["normal", "setup"]: bbkiObj.updateBootloader() else: print( "WARNING: Running in \"%s\" mode, do NOT maniplate boot-loader!!!" % (self.param.runMode)) print("") # synchronize boot partitions if layout.name in [ "efi-btrfs", "efi-bcache-btrfs", "efi-bcachefs" ]: dstList = layout.get_pending_esp_list() if len(dstList) > 0: with self.infoPrinter.printInfoAndIndent( ">> Synchronizing boot partitions..."): for dst in dstList: self.infoPrinter.printInfo( " - %s to %s..." % (layout.get_esp(), dst)) layout.sync_esp(dst) print("") # emerge @world self.infoPrinter.printInfo(">> Updating @world...") if buildServer is not None: try: buildServer.sshExec(self.opEmergeWorld) finally: self.infoPrinter.printInfo( ">> Synchronizing down system files...") buildServer.syncDownSystem() print("") else: FmUtil.cmdExec(self.opEmergeWorld) # re-emerge all "-9999" packages self.infoPrinter.printInfo(">> Updating all \"-9999\" packages...") if buildServer is not None: try: buildServer.sshExec(self.opEmerge9999) finally: self.infoPrinter.printInfo( ">> Synchronizing down system files...") buildServer.syncDownSystem() print("") else: FmUtil.cmdExec(self.opEmerge9999) # end remote build if buildServer is not None: buildServer.dispose()
bPretend = (sys.argv[1] != "0") assert not bPretend i = 1 while True: # remove unused packages pkgChanged = False print(" - Cycle %d: removing unused packages..." % (i)) if not bPretend: list1 = FmUtil.getFileList(FmConst.portageDbDir, 2, "d") FmUtil.cmdCall("emerge", "--depclean") list2 = FmUtil.getFileList(FmConst.portageDbDir, 2, "d") pkgChanged |= (list1 != list2) else: FmUtil.cmdExec("emerge", "--depclean", "--pretend") print("") # clean python if os.path.exists("/usr/share/eselect/modules/python.eselect"): print(" - Cycle %d: cleaning python..." % (i)) if not bPretend: FmUtil.cmdCall("eselect", "python", "cleanup") else: FmUtil.cmdCall("eselect", "python", "list") print("") # clean perl if os.path.exists("perl-cleaner"): print(" - Cycle %d: cleaning perl related packages..." % (i)) if not bPretend:
def _exec(self, buildServer, *args): if buildServer is None: FmUtil.cmdExec(*args) else: buildServer.sshExec(*args)
def installPkg(self, pkgName): with _FakeUsrSrcLinuxDirectory(): while self._updateUseFlag("emerge -p %s" % (pkgName)): pass FmUtil.cmdExec("emerge", pkgName)
def unmergePkg(self, pkgName): FmUtil.cmdExec("emerge", "-C", pkgName)