title: Is there a python grub.cfg parser?
body: <p>Does anyone know of a python parser for grub2's grub.cfg file?</p>
  
  <p>I'm trying to get the "menuentry" by device partition (root), e.g.</p>
  
  <pre><code>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)"]
  </code></pre>
  
  <p>etc.</p>
  
  <p>Solution:</p>
  
  <pre><code>re.findall("menuentry ['\"](.*?)['\"].*?set root='(.*?)'", x, re.S)
  </code></pre>
  
  <blockquote>
    <p>[('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)'),
    ('Memory test (memtest86+)', '(hd0,msdos1)'), ('Memory test
    (memtest86+, serial console 115200)', '(hd0,msdos1)'), ('Windows 7
    (on /dev/sdc1)', '(hd2,msdos1)')]</p>
  </blockquote>