Skip to content

Instantly share code, notes, and snippets.

@Kanst
Last active December 26, 2015 03:19
Show Gist options
  • Save Kanst/7085199 to your computer and use it in GitHub Desktop.
Save Kanst/7085199 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
#! -*- coding: utf-8 -*-
import re
f = open("input.xml", "r")
text = f.readlines()
f.close()
count = re.compile('^.*(?<=\t| )<boot dev=(\'|\")hd(\'|\").*$')
edit_type = re.compile('(?<=\t| )<(kernel|initrd|cmdline).*$')
out_text = []
ignore_tag = ['<initrd>', '<kernel>', '<cmdline>']
boot = False
# Удаление всех тегов из ignore_tag и установка <boot dev=\'hd\''
for x in text:
if re.match(count,x) == None:
if (all(s not in x for s in ignore_tag)):
out_text.append(x)
elif boot:
add_boot = re.sub(edit_type, '<boot dev=\'hd\'/>', x)
boot = True
out_text.append(add_boot)
else:
boot = True
out_text.append(x)
f2 = open("output.xml", "w")
f2.writelines(out_text)
f2.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment