cpuinfo.py 文件源码

python
阅读 36 收藏 0 点赞 0 评论 0

项目:zorro 作者: C-CINA 项目源码 文件源码
def __init__(self):
        if self.info is not None:
            return
        info = []
        try:
            #XXX: Bad style to use so long `try:...except:...`. Fix it!
            import _winreg

            prgx = re.compile(r"family\s+(?P<FML>\d+)\s+model\s+(?P<MDL>\d+)" \
                              "\s+stepping\s+(?P<STP>\d+)", re.IGNORECASE)
            chnd = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, self.pkey)
            pnum = 0
            while 1:
                try:
                    proc = _winreg.EnumKey(chnd, pnum)
                except _winreg.error:
                    break
                else:
                    pnum += 1
                    info.append({"Processor": proc})
                    phnd = _winreg.OpenKey(chnd, proc)
                    pidx = 0
                    while True:
                        try:
                            name, value, vtpe = _winreg.EnumValue(phnd, pidx)
                        except _winreg.error:
                            break
                        else:
                            pidx = pidx + 1
                            info[-1][name] = value
                            if name == "Identifier":
                                srch = prgx.search(value)
                                if srch:
                                    info[-1]["Family"] = int(srch.group("FML"))
                                    info[-1]["Model"] = int(srch.group("MDL"))
                                    info[-1]["Stepping"] = int(srch.group("STP"))
        except:
            print(  str(sys.exc_info()) +  '(ignoring)' )

        self.__class__.info = info
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号