示例#1
0
文件: autotest.py 项目: fpemud/pylkc
    def runTest(self):
        pylkc.init(self.rootDir)
        try:
            pylkc.conf_parse(self.rootDir)
            pylkc.conf_read(None)
            util.value_refresh()

            if True:
                sym = pylkc.sym_find("DEFAULT_HOSTNAME")
                self.assertIsNotNone(sym)
                self.assertEqual(sym.get_string_value(), "(none)")

                ret = sym.set_string_value("")
                self.assertTrue(ret)
                util.value_refresh()
                self.assertEqual(sym.get_string_value(), "")

            if True:
                sym = pylkc.sym_find("EXPERT")
                self.assertIsNotNone(sym)

                ret = sym.set_tristate_value(pylkc.tristate.yes)
                self.assertTrue(ret)
                util.value_refresh()
                self.assertEqual(sym.get_tristate_value(), pylkc.tristate.yes)

                ret = sym.set_tristate_value(pylkc.tristate.no)
                self.assertTrue(ret)
                util.value_refresh()
                self.assertEqual(sym.get_tristate_value(), pylkc.tristate.no)

            if True:
                ret = pylkc.sym_find("MODULES").set_tristate_value(pylkc.tristate.yes)
                self.assertTrue(ret)

                sym = pylkc.sym_find("CRYPTO")
                self.assertIsNotNone(sym)

                ret = sym.set_tristate_value(pylkc.tristate.yes)
                self.assertTrue(ret)
                util.value_refresh()
                self.assertEqual(sym.get_tristate_value(), pylkc.tristate.yes)

                ret = sym.set_tristate_value(pylkc.tristate.mod)
                self.assertTrue(ret)
                util.value_refresh()
                self.assertEqual(sym.get_tristate_value(), pylkc.tristate.mod)

                ret = sym.set_tristate_value(pylkc.tristate.no)
                self.assertTrue(ret) 
                util.value_refresh()
                self.assertEqual(sym.get_tristate_value(), pylkc.tristate.no)

            if True:
                menuObj = pylkc.menu_find_by_path("/General setup/Kernel compression mode", True)
                self.assertIsNotNone(menuObj)

            pylkc.conf_write(None)
        finally:
            pylkc.release()
示例#2
0
文件: checker.py 项目: fpemud/pylkc
def _getValue(symbolName):
    sym = pylkc.sym_find(symbolName)
    if sym.get_type() == pylkc.symbol.TYPE_UNKNOWN:
        assert False
    elif sym.get_type() == pylkc.symbol.TYPE_BOOLEAN:
        if sym.get_tristate_value() == pylkc.tristate.no:
            return "n"
        else:
            return "y"
    elif sym.get_type() == pylkc.symbol.TYPE_TRISTATE:
        if sym.get_tristate_value() == pylkc.tristate.no:
            return "n"
        elif sym.get_tristate_value() == pylkc.tristate.mod:
            return "m"
        elif sym.get_tristate_value() == pylkc.tristate.yes:
            return "y"
        else:
            assert False
    elif sym.get_type() == pylkc.symbol.TYPE_INT:
        return int(sym.get_string_value())
    elif sym.get_type() == pylkc.symbol.TYPE_HEX:
        assert False
    elif sym.get_type() == pylkc.symbol.TYPE_STRING:
        return sym.get_string_value()
    elif sym.get_type() == pylkc.symbol.TYPE_OTHER:
        assert False
    else:
        assert False
示例#3
0
def _getValue(symbolName):
    sym = pylkc.sym_find(symbolName)
    if sym.get_type() == pylkc.symbol.TYPE_UNKNOWN:
        assert False
    elif sym.get_type() == pylkc.symbol.TYPE_BOOLEAN:
        if sym.get_tristate_value() == pylkc.tristate.no:
            return "n"
        else:
            return "y"
    elif sym.get_type() == pylkc.symbol.TYPE_TRISTATE:
        if sym.get_tristate_value() == pylkc.tristate.no:
            return "n"
        elif sym.get_tristate_value() == pylkc.tristate.mod:
            return "m"
        elif sym.get_tristate_value() == pylkc.tristate.yes:
            return "y"
        else:
            assert False
    elif sym.get_type() == pylkc.symbol.TYPE_INT:
        return int(sym.get_string_value())
    elif sym.get_type() == pylkc.symbol.TYPE_HEX:
        assert False
    elif sym.get_type() == pylkc.symbol.TYPE_STRING:
        return sym.get_string_value()
    elif sym.get_type() == pylkc.symbol.TYPE_OTHER:
        assert False
    else:
        assert False
示例#4
0
    def _generateMenuInfoSymbol(self, lineNo, symbolName, value):
        sym = pylkc.sym_find(symbolName)
        if sym is None:
            raise SyntaxError(self, lineNo,
                              "symbol %s not found" % (symbolName))
        menuObj = pylkc.menu_find_by_sym(sym)
        if menuObj is None:
            raise SyntaxError(self, lineNo,
                              "symbol %s not found" % (symbolName))

        if sym.get_type() == pylkc.symbol.TYPE_BOOLEAN:
            newvlist = _merge_vlist(_str2vlist(value), ["n", "y"])
            if len(newvlist) == 0:
                raise SyntaxError(
                    self, lineNo,
                    "invalid value for BOOLEAN symbol %s" % (symbolName))
            value = _vlist2str(newvlist)
        elif sym.get_type() == pylkc.symbol.TYPE_INT and not _is_int(value):
            raise SyntaxError(
                self, lineNo,
                "invalid value \"%s\" for INT symbol %s" % (value, symbolName))

        item = self._Item()
        item.index = len(self.itemList)
        item.lineNo = lineNo
        item.symbolMenu = menuObj
        item.value = value
        item.vforce = True
        self.itemList.append(item)
示例#5
0
文件: generator.py 项目: fpemud/pylkc
 def _generateMenuInfoSymbols(self, lineNo, mstr, filterFunc, value):
     if mstr.startswith("/"):
         menuObj = pylkc.menu_find_by_path(mstr, True)
         if menuObj is None:
             raise SyntaxError(self, lineNo, "menu \"%s\" not found" % (mstr))
     else:
         menuObj = pylkc.menu_find_by_sym(pylkc.sym_find(mstr))
         if menuObj is None:
             raise SyntaxError(self, lineNo, "menu %s not found" % (mstr))
     self._generateMenuInfoSymbolsImpl(lineNo, menuObj, filterFunc, value)
示例#6
0
 def _generateMenuInfoSymbols(self, lineNo, mstr, filterFunc, value):
     if mstr.startswith("/"):
         menuObj = pylkc.menu_find_by_path(mstr, True)
         if menuObj is None:
             raise SyntaxError(self, lineNo,
                               "menu \"%s\" not found" % (mstr))
     else:
         menuObj = pylkc.menu_find_by_sym(pylkc.sym_find(mstr))
         if menuObj is None:
             raise SyntaxError(self, lineNo, "menu %s not found" % (mstr))
     self._generateMenuInfoSymbolsImpl(lineNo, menuObj, filterFunc, value)
示例#7
0
文件: generator.py 项目: fpemud/pylkc
    def _generateMenuInfoSymbol(self, lineNo, symbolName, value):
        sym = pylkc.sym_find(symbolName)
        if sym is None:
            raise SyntaxError(self, lineNo, "symbol %s not found" % (symbolName))
        menuObj = pylkc.menu_find_by_sym(sym)
        if menuObj is None:
            raise SyntaxError(self, lineNo, "symbol %s not found" % (symbolName))

        if sym.get_type() == pylkc.symbol.TYPE_BOOLEAN:
            newvlist = _merge_vlist(_str2vlist(value), ["n", "y"])
            if len(newvlist) == 0:
                raise SyntaxError(self, lineNo, "invalid value for BOOLEAN symbol %s" % (symbolName))
            value = _vlist2str(newvlist)
        elif sym.get_type() == pylkc.symbol.TYPE_INT and not _is_int(value):
            raise SyntaxError(self, lineNo, "invalid value \"%s\" for INT symbol %s" % (value, symbolName))

        item = self._Item()
        item.index = len(self.itemList)
        item.lineNo = lineNo
        item.symbolMenu = menuObj
        item.value = value
        item.vforce = True
        self.itemList.append(item)
示例#8
0
文件: generator.py 项目: fpemud/pylkc
def _presetSymbol(context, symbolName, symbolValue):
    sym = pylkc.sym_find(symbolName)
    assert context.symValueDict[sym][0] == symbolValue
    context.symValueRecord[sym] = symbolValue
    context.symAltValueRecord[sym] = [symbolValue]
示例#9
0
文件: generator.py 项目: fpemud/pylkc
def generate(ksrcDir, baseConfig, ruleFile, baseConfigFilename=None, output=None, eventHandler=None):
    if baseConfig == "file":
        assert baseConfigFilename is not None
    if output is None:
        output = os.path.join(ksrcDir, ".config")

    context = _Context()
    context.eventHandler = eventHandler
    if context.eventHandler is not None:
        context.eventHandler.progressChanged("initialized")

    pylkc.init(ksrcDir)
    try:
        pylkc.conf_parse(ksrcDir)

        # load base config
        if baseConfig == "defconfig":
            _makeDefConfig(ksrcDir, "")
        elif baseConfig == "allnoconfig":
            _makeAllNoConfig()
        elif baseConfig == "allnoconfig+module":
            _makeAllNoConfig()
            pylkc.sym_find("MODULES").set_tristate_value(pylkc.tristate.yes)
        elif baseConfig == "file":
            pylkc.conf_read(baseConfigFilename)
        else:
            assert False
        for sym in pylkc.all_symbols():
            sym.calc_value()
        if context.eventHandler is not None:
            context.eventHandler.progressChanged("base-config-loaded")

        # parse rule file
        context.parseRuleFile(ruleFile)
        if context.eventHandler is not None:
            context.eventHandler.progressChanged("rule-file-parsed")

        # record pre-set values
        if baseConfig == "allnoconfig":
            _presetSymbol(context, "EXPERT", "y")
            _presetSymbol(context, "EMBEDDED", "y")
        elif baseConfig == "allnoconfig+module":
            _presetSymbol(context, "EXPERT", "y")
            _presetSymbol(context, "EMBEDDED", "y")
            _presetSymbol(context, "MODULES", "y")
        else:
            pass

        # do operation
        while len(context.itemRunList) > 0:
            item = context.itemRunList.pop(0)
            if item.symbolMenu is not None:
                if item.value.startswith("\""):
                    _procSymbolNonYmn(context, item)
                elif _is_int(item.value):
                    _procSymbolNonYmn(context, item)
                else:
                    _procSymbolYmn(context, item)
            elif item.choiceMenu is not None:
                _procChoice(context, item)
            else:
                assert False

        pylkc.conf_write(output)

        # final check:
        # 1. check if any symbol is ignored by invisibility
        for item in context.itemRunList:
            if item.symbolMenu is not None:
                if item.symbolMenu in context.symValueRecord:
                    continue
                if item.symbolMenu.sym.get_type() not in [pylkc.symbol.TYPE_BOOLEAN, pylkc.symbol.TYPE_TRISTATE]:
                    continue
                if item.value == "n":
                    continue
                if not item.vforce:
                    continue
                raise NotExecutedError(context, item, "invisibility")
            elif item.choiceMenu is not None:
                if any(m in context.symValueRecord for m in item.choiceMenu.list):
                    continue
                raise NotExecutedError(context, item, "invisibility")
            else:
                assert False

        pylkc.conf_write(output)
        if context.eventHandler is not None:
            context.eventHandler.progressChanged("finished")
    finally:
        pylkc.release()
示例#10
0
def _presetSymbol(context, symbolName, symbolValue):
    sym = pylkc.sym_find(symbolName)
    assert context.symValueDict[sym][0] == symbolValue
    context.symValueRecord[sym] = symbolValue
    context.symAltValueRecord[sym] = [symbolValue]
示例#11
0
def generate(ksrcDir,
             baseConfig,
             ruleFile,
             baseConfigFilename=None,
             output=None,
             eventHandler=None):
    if baseConfig == "file":
        assert baseConfigFilename is not None
    if output is None:
        output = os.path.join(ksrcDir, ".config")

    context = _Context()
    context.eventHandler = eventHandler
    if context.eventHandler is not None:
        context.eventHandler.progressChanged("initialized")

    pylkc.init(ksrcDir)
    try:
        pylkc.conf_parse(ksrcDir)

        # load base config
        if baseConfig == "defconfig":
            _makeDefConfig(ksrcDir, "")
        elif baseConfig == "allnoconfig":
            _makeAllNoConfig()
        elif baseConfig == "allnoconfig+module":
            _makeAllNoConfig()
            pylkc.sym_find("MODULES").set_tristate_value(pylkc.tristate.yes)
        elif baseConfig == "file":
            pylkc.conf_read(baseConfigFilename)
        else:
            assert False
        for sym in pylkc.all_symbols():
            sym.calc_value()
        if context.eventHandler is not None:
            context.eventHandler.progressChanged("base-config-loaded")

        # parse rule file
        context.parseRuleFile(ruleFile)
        if context.eventHandler is not None:
            context.eventHandler.progressChanged("rule-file-parsed")

        # record pre-set values
        if baseConfig == "allnoconfig":
            _presetSymbol(context, "EXPERT", "y")
            _presetSymbol(context, "EMBEDDED", "y")
        elif baseConfig == "allnoconfig+module":
            _presetSymbol(context, "EXPERT", "y")
            _presetSymbol(context, "EMBEDDED", "y")
            _presetSymbol(context, "MODULES", "y")
        else:
            pass

        # do operation
        while len(context.itemRunList) > 0:
            item = context.itemRunList.pop(0)
            if item.symbolMenu is not None:
                if item.value.startswith("\""):
                    _procSymbolNonYmn(context, item)
                elif _is_int(item.value):
                    _procSymbolNonYmn(context, item)
                else:
                    _procSymbolYmn(context, item)
            elif item.choiceMenu is not None:
                _procChoice(context, item)
            else:
                assert False

        pylkc.conf_write(output)

        # final check:
        # 1. check if any symbol is ignored by invisibility
        for item in context.itemRunList:
            if item.symbolMenu is not None:
                if item.symbolMenu in context.symValueRecord:
                    continue
                if item.symbolMenu.sym.get_type() not in [
                        pylkc.symbol.TYPE_BOOLEAN, pylkc.symbol.TYPE_TRISTATE
                ]:
                    continue
                if item.value == "n":
                    continue
                if not item.vforce:
                    continue
                raise NotExecutedError(context, item, "invisibility")
            elif item.choiceMenu is not None:
                if any(m in context.symValueRecord
                       for m in item.choiceMenu.list):
                    continue
                raise NotExecutedError(context, item, "invisibility")
            else:
                assert False

        pylkc.conf_write(output)
        if context.eventHandler is not None:
            context.eventHandler.progressChanged("finished")
    finally:
        pylkc.release()
示例#12
0
文件: autotest.py 项目: fpemud/pylkc
    def runTest(self):
        pylkc.init(self.rootDir)
        try:
            pylkc.conf_parse(self.rootDir)
            pylkc.conf_read(None)

            mobj = pylkc.menu_find_by_path("/General setup")
            self.assertIn("Kernel compression mode", [m.get_prompt() for m in mobj.list])

            mobj = pylkc.menu_find_by_path("/General setup/Kernel compression mode")
            sobj = pylkc.sym_find("KERNEL_LZMA")
            self.assertTrue(mobj.sym.is_choice())
            self.assertTrue(sobj.is_choice_value())
            self.assertIn(sobj, [m.sym for m in mobj.list])

            mobj = pylkc.menu_find_by_sym(pylkc.sym_find("IKCONFIG"))
            self.assertEqual(len(mobj.list), 1)
            self.assertEqual(mobj.list[0].sym, pylkc.sym_find("IKCONFIG_PROC"))

            mobj = pylkc.menu_find_by_path("/General setup")
            self.assertTrue(mobj.is_visible())
            mobj = pylkc.menu_find_by_sym(pylkc.sym_find("MODULES"))
            self.assertTrue(mobj.is_visible())
            mobj = pylkc.menu_find_by_sym(pylkc.sym_find("EXT4_USE_FOR_EXT23"))
            self.assertFalse(mobj.is_visible())
            mobj = pylkc.menu_find_by_sym(pylkc.sym_find("CIFS_NFSD_EXPORT"))
            self.assertFalse(mobj.is_visible())

            sobj = pylkc.sym_find("DEFAULT_HOSTNAME")
            self.assertEqual(sobj.get_type(), pylkc.symbol.TYPE_STRING)
            sobj = pylkc.sym_find("MODULES")
            self.assertEqual(sobj.get_type(), pylkc.symbol.TYPE_BOOLEAN)
            sobj = pylkc.sym_find("MICROCODE")
            self.assertEqual(sobj.get_type(), pylkc.symbol.TYPE_BOOLEAN)
            sobj = pylkc.sym_find("PCI_STUB")
            self.assertEqual(sobj.get_type(), pylkc.symbol.TYPE_BOOLEAN)
            sobj = pylkc.sym_find("X86_RESERVE_LOW")
            self.assertEqual(sobj.get_type(), pylkc.symbol.TYPE_INT)
            sobj = pylkc.sym_find("PHYSICAL_START")
            self.assertEqual(sobj.get_type(), pylkc.symbol.TYPE_HEX)

            mobj = pylkc.menu_find_by_path("/General setup", True)
            self.assertIsNotNone(mobj)
            mobj = pylkc.menu_find_by_path("/Executable file formats \\/ Emulations", True)
            self.assertIsNotNone(mobj)
        finally:
            pylkc.release()