Last active
October 20, 2017 14:01
-
-
Save ViktorOgnev/02db12879dda7f000b48 to your computer and use it in GitHub Desktop.
parse windows registry file
This file contains hidden or 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
with open("/Users/viktorognev/work/Workspace/ci/chef/cookbooks/ci/files/default/pssconfig.reg") as fp: | |
res = "" | |
for line in fp.readlines(): | |
if '=' in line: | |
print line | |
name, value = line.split('=', 1) | |
if ':' in value: | |
if 'C:\\' in value: | |
vtype, data = "expand_string", value | |
else: | |
vtype, data = value.split(':') | |
if vtype not in ('dword'): | |
vtype, data = 'string', value | |
else: | |
vtype, data = "string", value | |
data = data.strip() | |
data = '"{0}"'.format(data) if '"' not in data else data | |
res += ' {:name => %(name)s, :type => :%(type)s, :data => %(data)s},\n' % {'name': | |
name, 'type': vtype, 'data': data} | |
elif any([symbol.isalnum() for symbol in line]): | |
line = line[1:-2].replace('\\', '\\\\') | |
if res: | |
res = res[:-2] + ''' | |
] | |
action :create | |
end | |
''' | |
res += ''' | |
registry_key "{0}" do | |
values [ | |
'''.format(line) | |
res = res[:-2] + ''' | |
] | |
action :create | |
end | |
''' | |
print res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment