有谁知道用于 grub2 的 grub.cfg 文件的 python 解析器?
我正在尝试通过设备分区(根)获取“菜单项”,例如
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 (恢复模式)', '(hd0,msdos1) '), ('Ubuntu, with Linux 3.0.0-14-generic', '(hd0,msdos1)'), ('Ubuntu, with Linux 3.0.0-14-generic (恢复模式)', '(hd0, msdos1)'), ('Ubuntu, with Linux 3.0.0-13-generic', '(hd0,msdos1)'), ('Ubuntu, with Linux 3.0.0-13-generic (恢复模式)', '( hd0,msdos1)'), ('Ubuntu, with Linux 3.0.0-12-generic', '(hd0,msdos1)'), ('Ubuntu, with Linux 3.0.0-12-generic (恢复模式)', '(hd0,msdos1)'), ('内存测试 (memtest86+)', '(hd0,msdos1)'), ('内存测试 (memtest86+, 串行控制台 115200)', '(hd0,msdos1)'), ( 'Windows 7(在 /dev/sdc1 上)', '(hd2,msdos1)')]