in source/code/troubleshooter/modules/install/check_files.py [0:0]
def get_data(f, variables, files, links, dirs):
curr_section = None
with open(f, 'r') as data_file:
for line in data_file:
line = line.rstrip('\n')
# skip comments
cstart = line.find('#')
if (cstart != -1):
line = line[:cstart]
# skip empty lines
if (line == ''):
continue
# new section
if (line.startswith('%')):
curr_section = line[1:]
continue
# line contains variable, needs to be replaced with content
while ('${{' in line):
vstart = line.index('${{')
vend = line.index('}}') + 2
l = line[vstart:vend]
v = line[vstart+3:vend-2]
if (v in list(variables.keys())):
line = line.replace(l, variables[v])
else:
break
# variable line
if (curr_section == "Variables"):
# parsed_line: [variable name, content]
parsed_line = (line.replace(' ','')).split(':')
variables[parsed_line[0]] = (parsed_line[1]).strip("'")
continue
# file line
elif (curr_section == "Files"):
# parsed_line: [filepath, install filepath, permissions, user, group]
parsed_line = (line.replace(' ','')).split(';')
files[parsed_line[0]] = parsed_line[2:5]
continue
# link line
elif (curr_section == "Links"):
# parsed_line: [filepath, install filepath, permissions, user, group]
parsed_line = (line.replace(' ','')).split(';')
links[parsed_line[0]] = parsed_line[2:5] + [parsed_line[1]]
continue
# directory line
elif (curr_section == "Directories"):
# parsed_line: [filepath, permissions, user, group]
parsed_line = (line.replace(' ','')).split(';')
dirs[parsed_line[0]] = parsed_line[1:4]
continue
# installation code
else:
# check for changes in owners or permissions
if (line.startswith('chmod ')):
# parsed_line: ['chmod', (recursive,) new permissions, filepath]
parsed_line = line.split()
path = parsed_line[-1]
# skip over anything with undefined variables
if (not path.startswith('/')):
continue
new_perms = parsed_line[-2]
if (parsed_line[1] == '-R'):
# recursively apply new perms
for f in (files.keys()):
if (f.startswith(path)):
files[f][0] = new_perms
for l in (links.keys()):
if (l.startswith(path)):
links[l][0] = new_perms
for d in (dirs.keys()):
if (d.startswith(path)):
dirs[d][0] = new_perms
else: # not recursive
if path in files:
files[path][0] = new_perms
elif path in links:
links[path][0] = new_perms
elif path in dirs:
dirs[path][0] = new_perms