Created
November 26, 2014 19:13
-
-
Save bvaudour/95aad8b5ce05918cff4a to your computer and use it in GitHub Desktop.
Grub parsing rewrite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def read_grub(): | |
global menu_entries | |
grub_path = os.path.join(install_path, 'boot', 'grub', 'grub.cfg') | |
o = False | |
with open(grub_path, 'r') as f: | |
for l in f: | |
if l.strip()[:9] == 'menuentry' and l[-2] == '{': | |
o = True | |
e = {} | |
i1 = l.find("'") + 1 | |
i2 = l.find("'", i1) | |
e["title"] = l[i1:i2] | |
i = e["title"].find(' ') | |
if i > 0: | |
e["name"] = e["title"][:i] | |
else: | |
e["name"] = e["title"] | |
elif l.lstrip()[:5] == 'linux': | |
l = l.lstrip()[5:].lstrip() | |
i = l.find(' ') | |
e["linux"] = l[:i] | |
e["options"] = l[i+1:].rstrip('\n') | |
elif l.lstrip()[:6] == 'initrd': | |
e["initrd"] = l.lstrip()[6:].strip().rstrip('\n') | |
elif '}' in l and o: | |
o = False | |
menu_entries.append(e) | |
break | |
f.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment