Ejemplo n.º 1
0
    def doEnableSwap(self):
        if self.param.runMode not in ["normal", "setup"]:
            print("Operation is not supported in \"%s\" mode." %
                  (self.param.runMode),
                  file=sys.stderr)
            return 1

        layout = strict_hdds.get_storage_layout()
        if layout is None:
            print("Invalid storage layout.", file=sys.stderr)
            return 1

        self.param.swapManager.enableSwap(layout)

        if layout.name in ["bios-ext4", "efi-ext4"]:
            swapSizeStr = FmUtil.formatSize(os.path.getsize(layout.dev_swap))
            print("Swap File: %s (size:%s)" % (layout.dev_swap, swapSizeStr))
        elif layout.name in ["efi-bcache-btrfs", "efi-bcachefs"]:
            uuid = pyudev.Device.from_device_file(
                pyudev.Context(), layout.dev_swap).get("ID_FS_UUID")
            swapSizeStr = FmUtil.formatSize(
                FmUtil.getBlkDevSize(layout.dev_swap))
            print("Swap Partition: %s (UUID:%s, size:%s)" %
                  (layout.dev_swap, uuid, swapSizeStr))
        else:
            assert False

        return 0
Ejemplo n.º 2
0
    def uninstallRescueOs(self):
        if self.param.runMode not in ["normal", "setup"]:
            print("Operation is not supported in \"%s\" mode." %
                  (self.param.runMode),
                  file=sys.stderr)
            return 1

        self.param.sysChecker.basicCheckWithOverlayContent()

        layout = strict_hdds.get_storage_layout()
        bbkiObj = BbkiWrapper(layout)

        if not bbkiObj.isRescueOsInstalled():
            print("Rescue OS is not installed.", file=sys.stderr)
            return 1

        with BootDirWriter(layout):
            self.infoPrinter.printInfo(">> Uninstalling Rescue OS...")
            robust_layer.simple_fops.rm(bbkiObj.rescue_os_spec.root_dir)
            print("")

            self.infoPrinter.printInfo(">> Updating boot-loader...")
            bbkiObj.updateBootloaderAfterRescueOsChange()
            print("")

        return 0
Ejemplo n.º 3
0
    def doHddRemove(self, devpath):
        if self.param.runMode not in ["normal", "setup"]:
            print("Operation is not supported in \"%s\" mode." %
                  (self.param.runMode),
                  file=sys.stderr)
            return 1

        layout = strict_hdds.get_storage_layout()
        if layout is None:
            print("Invalid storage layout.", file=sys.stderr)
            return 1

        if layout.name in ["bios-ext4", "efi-ext4"]:
            raise Exception(
                "storage layout \"%s\" does not support this operation" %
                (layout.name))
        elif layout.name in ["efi-btrfs", "efi-bcache-btrfs", "efi-bcachefs"]:
            self.infoPrinter.printInfo(">> Removing harddisk...")
            layout.remove_disk(devpath)
            print("")
        else:
            assert False

        self.param.sysUpdater.updateAfterHddAddOrRemove(
            self.param.machineInfoGetter.hwInfo(), layout, BbkiWrapper())

        return 0
Ejemplo n.º 4
0
    def installRescueOs(self):
        if self.param.runMode not in ["normal", "setup"]:
            print("Operation is not supported in \"%s\" mode." %
                  (self.param.runMode),
                  file=sys.stderr)
            return 1

        self.param.sysChecker.basicCheckWithOverlayContent()

        # modify dynamic config
        self.infoPrinter.printInfo(">> Preparing...")
        if True:
            dcm = DynCfgModifier()
            dcm.updateMirrors()
            dcm.updateDownloadCommand()
            dcm.updateParallelism(self.param.machineInfoGetter.hwInfo())
            dcm.updateCcache()
        print("")

        # build
        layout = strict_hdds.get_storage_layout()
        bbkiObj = BbkiWrapper(layout)
        builder = RescueCdBuilder(RescueCdBuilder.DEV_TYPE_RESCUE_OS,
                                  self.param.tmpDirOnHdd,
                                  self.param.machineInfoGetter.hwInfo(),
                                  rescue_os_spec=bbkiObj.rescue_os_spec)

        self.infoPrinter.printInfo(">> Downloading files...")
        builder.downloadFiles()
        print("")

        self.infoPrinter.printInfo(">> Building Rescue OS...")
        builder.buildTargetSystem("amd64")
        print("")

        # install
        with BootDirWriter(layout):
            try:
                self.infoPrinter.printInfo(
                    ">> Installing Rescue OS into /boot...")
                builder.exportTargetSystem()
                print("")

                self.infoPrinter.printInfo(">> Updating boot-loader...")
                bbkiObj.updateBootloaderAfterRescueOsChange()
                print("")
            except Exception:
                shutil.rmtree(bbkiObj.rescue_os_spec.root_dir)
                raise

        return 0
Ejemplo n.º 5
0
    def doDisableSwap(self):
        if self.param.runMode not in ["normal", "setup"]:
            print("Operation is not supported in \"%s\" mode." %
                  (self.param.runMode),
                  file=sys.stderr)
            return 1

        layout = strict_hdds.get_storage_layout()
        if layout is None:
            print("Invalid storage layout.", file=sys.stderr)
            return 1

        if layout.dev_swap is None:
            return 0

        self.param.swapManager.disableSwap(layout)
        return 0
Ejemplo n.º 6
0
    def stablize(self):
        layout = strict_hdds.get_storage_layout()
        bbkiObj = BbkiWrapper(layout)

        self.infoPrinter.printInfo(">> Stablizing...")
        with BootDirWriter(layout):
            bbkiObj.setStable(True)
        print("")

        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("")
Ejemplo n.º 7
0
    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()
Ejemplo n.º 8
0
    def clean(self, bPretend):
        # 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("")

        # clean old kernel files
        self.infoPrinter.printInfo(">> Removing old kernel files...")
        if True:
            if self.param.runMode in ["normal", "setup"]:
                layout = strict_hdds.get_storage_layout()
            else:
                layout = None
            bbkiObj = BbkiWrapper(layout)
            resultFile = os.path.join(self.param.tmpDir, "result.txt")
            bFileRemoved = False

            with BootDirWriter(layout):
                self._exec(buildServer, self.opCleanKernel,
                           "%s %d" % (self.param.runMode, bPretend),
                           resultFile)
                if buildServer is None:
                    with open(resultFile, "r", encoding="iso8859-1") as f:
                        data = f.read()
                else:
                    data = buildServer.getFile(resultFile).decode("iso8859-1")
                bFileRemoved = self._parseKernelCleanResult(data)
                print("")

                if bFileRemoved:
                    if buildServer is not None:
                        self.infoPrinter.printInfo(
                            ">> Synchronizing down /boot, /lib/modules and /lib/firmware..."
                        )
                        buildServer.syncDownKernel()
                        print("")

                    self.infoPrinter.printInfo(">> Updating boot-loader...")
                    if self.param.runMode in ["normal", "setup"]:
                        bbkiObj.updateBootloaderAfterCleaning()
                    else:
                        print(
                            "WARNING: Running in \"%s\" mode, do NOT maniplate boot-loader!!!"
                            % (self.param.runMode))
                    print("")

            if layout is not None and layout.name in [
                    "efi-btrfs", "efi-bcache-btrfs", "efi-bcachefs"
            ]:
                dstList = layout.get_pending_esp_list()
                if bFileRemoved and 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("")

        # clean kcache
        self.infoPrinter.printInfo(">> Cleaning %s..." % (FmConst.kcacheDir))
        self._execAndSyncDownQuietly(buildServer,
                                     self.opCleanKcache,
                                     "%s %d" % (self.param.runMode, bPretend),
                                     directory=FmConst.kcacheDir)
        print("")

        # clean not-used packages and USE flags
        self.infoPrinter.printInfo(">> Cleaning packages...")
        self._exec(buildServer, self.opCleanPkgAndUse, "%d" % (bPretend))
        print("")

        # sync down system files
        if not bPretend and buildServer is not None:
            self.infoPrinter.printInfo(">> Synchronizing down system files...")
            buildServer.syncDownSystem()
            print("")

        # clean distfiles
        # sync down distfiles directory quietly since there's only deletion
        self.infoPrinter.printInfo(">> Cleaning %s..." % (FmConst.distDir))
        self._execAndSyncDownQuietly(buildServer,
                                     "eclean-dist",
                                     directory=FmConst.distDir)
        print("")

        # end remote build
        if buildServer is not None:
            buildServer.dispose()
Ejemplo n.º 9
0
    def doShow(self):
        '''
        >>> Example:

        System status: unstable

        Hardware:
            Unknown hardware
        Boot mode:
            UEFI
        Main OS:
            Linux (kernel-x86_64-4.4.6)
        Rescue OS:
            Installed
        Auxillary OSes:
            None

        Storage layout:
            Name: efi-bcache-lvm
            ESP partition: /dev/sdc1
            Swap partition: /dev/sdc2 (16.0GiB)
            Cache partition: /dev/sdc3 (102.7GiB)
            LVM PVs: /dev/sda,bcache0 /dev/sdb,bcache16 (total: 8.2TiB)
        Swap:
            Disabled
        Logging:
            To harddisk (/var/log)

        Backend graphics devices:
            /dev/dri/card1 /dev/dri/card2 (total: 16GiB 14.3TFLOPs)

        System users:       root, nobody
        System groups:      root, nobody, nogroup, wheel, users

        Repositories:
            fpemud-overlay    [Dirty]       (Last Update: 2016-01-01 00:00:00)
            local             [Not Exist]

        Overlays:
            wrobel    [Subversion] (https://overlays.gentoo.org/svn/dev/wrobel     )

        Selected packages:
            app-admin/ansible               (repo-gentoo)
            app-misc/sway                   (overlay-uly55e5)
        '''

        if self.param.runMode != "normal":
            print("WARNING: Running in \"%s\" mode!!!" % (self.param.runMode))
            print("")

        self.param.sysChecker.basicCheckWithOverlayContent()

        if self.param.runMode in ["normal", "setup"]:
            layout = strict_hdds.get_storage_layout()
            bbkiObj = BbkiWrapper(layout)

            s = "System status: "
            if bbkiObj.isStable():
                s += "stable"
            else:
                s += "unstable"
            print(s)
            print("")

            print("Hardware:")
            hwInfo = self.param.machineInfoGetter.hwInfo()
            if isinstance(hwInfo, HwInfoPcBranded):
                print("    %s %s" % (hwInfo.vendor, hwInfo.model))
            elif isinstance(hwInfo, HwInfoPcAssembled):
                print("    DIY PC")
            else:
                assert False
            print("")

            if True:
                print("Main OS:")
                be = bbkiObj.get_pending_boot_entry()
                if be is None:
                    be = "None"
                else:
                    be = "Linux (%s)" % (be.postfix)
                print("    %s" % (be))

                print("Rescue OS:")
                if bbkiObj.isRescueOsInstalled():
                    print("    Installed")
                else:
                    print("    Not installed")

                auxOsInfo = bbkiObj.getAuxOsInfo()
                if len(auxOsInfo) > 0:
                    print("Auxillary OSes:")
                    for item in auxOsInfo:
                        sys.stdout.write("    %s:" % (item.name))
                        for i in range(0, 20 - len(item.name)):
                            sys.stdout.write(" ")
                        print(item.partition_path)

                print("")

            if True:

                def __partSize(devpath):
                    sz = FmUtil.getBlkDevSize(devpath)
                    return FmUtil.formatSize(sz)

                print("Boot mode:")
                if layout.boot_mode == strict_hdds.StorageLayout.BOOT_MODE_EFI:
                    print("    UEFI")
                elif layout.boot_mode == strict_hdds.StorageLayout.BOOT_MODE_BIOS:
                    print("    BIOS")
                else:
                    assert False

                print("Storage layout:")
                print("    Name: %s" % (layout.name))
                print("    State: ready")
                if layout.name == "bios-ext4":
                    print("    Boot disk: %s" % (layout.boot_disk))
                    print("    Root partititon: %s (%s)" %
                          (layout.dev_rootfs, __partSize(layout.dev_rootfs)))
                elif layout.name == "efi-ext4":
                    print("    Boot disk: %s" % (layout.boot_disk))
                    print("    Root partititon: %s (%s)" %
                          (layout.dev_rootfs, __partSize(layout.dev_rootfs)))
                elif layout.name in ["efi-btrfs"]:
                    print("    Boot disk: %s" % (layout.boot_disk))
                    totalSize = 0
                    pvStrList = []
                    for hddDevPath in layout.get_hdd_list():
                        parti = layout.get_hdd_data_partition(hddDevPath)
                        pvStrList.append("%s" % (parti))
                        totalSize += FmUtil.getBlkDevSize(parti)
                    print("    HDDs: %s (total: %s)" %
                          (" ".join(pvStrList), FmUtil.formatSize(totalSize)))
                elif layout.name == "efi-bcache-btrfs":
                    if layout.get_ssd() is not None:
                        print("    SSD: %s (boot disk)" % (layout.get_ssd()))
                        if layout.get_ssd_swap_partition() is not None:
                            print(
                                "    Swap partition: %s (%s)" %
                                (layout.get_ssd_swap_partition(),
                                 __partSize(layout.get_ssd_swap_partition())))
                        else:
                            print("    Swap partition: None")
                        print("    Cache partition: %s (%s)" %
                              (layout.get_ssd_cache_partition(),
                               __partSize(layout.get_ssd_cache_partition())))
                    else:
                        print("    SSD: None")
                        print("    Boot disk: %s" % (layout.boot_disk))
                    totalSize = 0
                    pvStrList = []
                    for hddDevPath in layout.get_hdd_list():
                        bcacheDevPath = layout.get_hdd_bcache_dev(hddDevPath)
                        pvStrList.append(
                            "%s,%s" %
                            (hddDevPath, bcacheDevPath.replace("/dev/", "")))
                        totalSize += FmUtil.getBlkDevSize(bcacheDevPath)
                    print("    HDDs: %s (total: %s)" %
                          (" ".join(pvStrList), FmUtil.formatSize(totalSize)))
                elif layout.name == "efi-bcachefs":
                    if layout.get_ssd() is not None:
                        print("    SSD: %s (boot disk)" % (layout.get_ssd()))
                        if layout.get_ssd_swap_partition() is not None:
                            print(
                                "    Swap partition: %s (%s)" %
                                (layout.get_ssd_swap_partition(),
                                 __partSize(layout.get_ssd_swap_partition())))
                        else:
                            print("    Swap partition: None")
                        print("    Cache partition: %s (%s)" %
                              (layout.get_ssd_cache_partition(),
                               __partSize(layout.get_ssd_cache_partition())))
                    else:
                        print("    SSD: None")
                        print("    Boot disk: %s" % (layout.boot_disk))
                    totalSize = 0
                    pvStrList = []
                    for hddDevPath in layout.get_hdd_list():
                        parti = layout.get_hdd_data_partition(hddDevPath)
                        pvStrList.append("%s" % (parti))
                        totalSize += FmUtil.getBlkDevSize(parti)
                    print("    HDDs: %s (total: %s)" %
                          (" ".join(pvStrList), FmUtil.formatSize(totalSize)))
                else:
                    assert False

                print("Swap:")
                if self.param.runMode == "normal":
                    if layout.dev_swap is None:
                        print("    Disabled")
                    else:
                        serviceName = FmUtil.systemdFindSwapServiceInDirectory(
                            "/etc/systemd/system", layout.dev_swap)
                        if serviceName is None or not FmUtil.systemdIsServiceEnabled(
                                serviceName):
                            print("    Disabled")
                        else:
                            print("    Enabled (%s)" %
                                  (FmUtil.formatSize(layout.get_swap_size())))
                elif self.param.runMode == "setup":
                    print("    Disabled")
                else:
                    assert False

                # FIXME
                print("Logging:")
                if True:
                    print("    To harddisk (/var/log)")

                print("")

            if True:
                ret = FmUtil.findBackendGraphicsDevices()
                if len(ret) > 0:
                    totalMem = 0
                    totalFlopsForFp32 = 0
                    for path in ret:
                        rc = FmUtil.getVendorIdAndDeviceIdByDevNode(path)
                        if rc is None:
                            totalMem = None
                            break
                        info = DevHwInfoDb.getDevHwInfo(rc[0], rc[1])
                        if info is None:
                            totalMem = None
                            break
                        if "mem" not in info or not isinstance(
                                info["mem"], int):
                            totalMem = None
                            break
                        if "fp32" not in info or not isinstance(
                                info["fp32"], int):
                            totalMem = None
                            break
                        totalMem += info["mem"]
                        totalFlopsForFp32 += info["fp32"]

                    totalStr = "unknown"
                    if totalMem is not None:
                        totalStr = "%s %s" % (FmUtil.formatSize(
                            totalMem), FmUtil.formatFlops(totalFlopsForFp32))

                    print("Backend graphics devices:")
                    print("    %s (total: %s)" % (" ".join(ret), totalStr))
                    print("")
        elif self.param.runMode == "prepare":
            bbkiObj = BbkiWrapper(None)

            print("Main OS:")
            be = bbkiObj.get_newest_boot_entry()
            if be is None:
                be = "None"
            else:
                be = "Linux (%s)" % (be.postfix)
            print("    %s" % (be))
            print("")
        else:
            assert False

        with strict_pgs.PasswdGroupShadow() as pgs:
            print("System users:       %s" %
                  (", ".join(pgs.getSystemUserList())))
            print("System groups:      %s" %
                  (", ".join(pgs.getSystemGroupList())))
            print("")

        print("Repositories:")
        repoman = EbuildRepositories()
        repoList = repoman.getRepositoryList()
        if len(repoList) > 0:
            maxLen = FmUtil.strListMaxLen(repoList)
            for repoName in repoList:
                s1 = FmUtil.pad(repoName, maxLen)
                if repoman.isRepoExist(repoName):
                    print("    %s [Good     ] Last Update: %s" %
                          (s1,
                           FmUtil.getDirLastUpdateTime(
                               repoman.getRepoDir(repoName))))
                else:
                    print("    %s [Not Exist]" % (s1))
        else:
            print("    None")
        print("")

        print("Overlays:")
        layman = EbuildOverlays()
        overlayList = layman.getOverlayList()
        if len(overlayList) > 0:
            tlist2 = []
            tlist3 = []
            for lname in overlayList:
                if layman.getOverlayType(lname) == "static":
                    ltype = "Static"
                    lurl = ""
                else:
                    ltype, lurl = layman.getOverlayVcsTypeAndUrl(lname)
                    if ltype == "git":
                        ltype = "Git"
                    elif ltype == "svn":
                        ltype = "Subversion"
                    else:
                        assert False
                tlist2.append(ltype)
                tlist3.append(lurl)
            maxLen1 = FmUtil.strListMaxLen(overlayList)
            maxLen2 = FmUtil.strListMaxLen(tlist2)
            maxLen3 = FmUtil.strListMaxLen(tlist3)
            for i in range(0, len(overlayList)):
                s1 = FmUtil.pad(overlayList[i], maxLen1)
                s2 = FmUtil.pad(tlist2[i], maxLen2)
                s3 = FmUtil.pad(tlist3[i], maxLen3)
                print("    %s [%s %s] Last Update: %s" %
                      (s1, s2, s3,
                       FmUtil.getDirLastUpdateTime(
                           layman.getOverlayDir(overlayList[i]))))
        else:
            print("    None")
        print("")

        print("Selected packages:")
        if True:
            pkgList = FmUtil.portageReadWorldFile(FmConst.worldFile)
            maxLen = max([len(x) for x in pkgList])

            for repoName in repoman.getRepositoryList():
                tempList = []
                for pkg in pkgList:
                    if os.path.exists(
                            os.path.join(repoman.getRepoDir(repoName), pkg)):
                        print("    %s (repo-%s)" %
                              (FmUtil.pad(pkg, maxLen), repoName))
                    else:
                        tempList.append(pkg)
                pkgList = tempList

            for overlayName in layman.getOverlayList():
                tempList = []
                for pkg in pkgList:
                    if os.path.exists(
                            os.path.join(layman.getOverlayDir(overlayName),
                                         pkg)):
                        print("    %s (overlay-%s)" %
                              (FmUtil.pad(pkg, maxLen), overlayName))
                    else:
                        tempList.append(pkg)
                pkgList = tempList

            for pkg in pkgList:
                print("    %s" % (pkg))

        return 0
Ejemplo n.º 10
0
import strict_hdds
sys.path.append('/usr/lib64/fpemud-os-sysman')
from helper_bbki import BbkiWrapper
from helper_pkg_warehouse import PkgWarehouse
from helper_pkg_warehouse import EbuildRepositories
from helper_pkg_warehouse import EbuildOverlays
from helper_pkg_merger import PkgMerger

runMode = sys.argv[1]
item = sys.argv[2]

if item == "sync-bbki-repo":
    repoName = sys.argv[3]
    assert repoName == "main"
    if runMode in ["normal", "setup"]:
        layout = strict_hdds.get_storage_layout()
    else:
        layout = None
    repo = BbkiWrapper(layout).repositories[0]
    repo.sync()
    sys.exit(0)

if item == "sync-repo":
    repoName = sys.argv[3]
    repoman = EbuildRepositories()
    repoman.syncRepository(repoName)
    sys.exit(0)

if item == "sync-overlay":
    overlayName = sys.argv[3]
    EbuildOverlays().syncOverlay(overlayName)