[英]Is there a python grub.cfg parser?
有谁知道 grub2 的 grub.cfg 文件的 python 解析器?
我正在尝试通过设备分区(root)获取“menuentry”,例如
hd0,msdos1: ['Ubuntu, with Linux 3.0.0-15-generic',
'Ubuntu, with Linux 3.0.0-15-generic (recovery mode)',
'Ubuntu, with Linux 3.0.0-14-generic']
hd2,msdos1: ["Windows 7 (on /dev/sdc1)"]
等等
解决方案:
re.findall("menuentry ['\"](.*?)['\"].*?set root='(.*?)'", x, re.S)
[('Ubuntu, with Linux 3.0.0-15-generic', '(hd0,msdos1)'), ('Ubuntu, with Linux 3.0.0-15-generic (recovery mode)', '(hd0,msdos1) '), ('Ubuntu, with Linux 3.0.0-14-generic', '(hd0,msdos1)'), ('Ubuntu, with Linux 3.0.0-14-generic (recovery mode)', '(hd0, msdos1)'), ('Ubuntu, with Linux 3.0.0-13-generic', '(hd0,msdos1)'), ('Ubuntu, with Linux 3.0.0-13-generic (recovery mode)', '( hd0,msdos1)'), ('Ubuntu, with Linux 3.0.0-12-generic', '(hd0,msdos1)'), ('Ubuntu, with Linux 3.0.0-12-generic (recovery mode)', '(hd0,msdos1)'), ('内存测试(memtest86+)', '(hd0,msdos1)'), ('内存测试(memtest86+,串口控制台115200)', '(hd0,msdos1)'), ( 'Windows 7(在 /dev/sdc1 上)','(hd2,msdos1)')]
我不知道grub.cfg的Python解析器,但是您不需要解析整个文件以获取该信息。 这是您要查找的数据的格式:
menuentry "<name>" [options] {
...
set root='<root>'
...
}
因此,查找以menuentry
开头的行,从该行解析名称,然后扫描到下一行,其中带有}
for set root=
。
我想你可以试试解析器augeas libconfuse Devicetree
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.