mirror of
https://gitlab.com/apparmor/apparmor.git
synced 2025-03-04 16:35:02 +01:00
ugly solution to py2 configparser by stripping 2 spaces off everyline into a tempfile
This commit is contained in:
parent
a33c95f8b1
commit
f4b89ce45b
2 changed files with 18 additions and 3 deletions
|
@ -506,7 +506,7 @@ def get_profile(prof_name):
|
|||
if repo_is_enabled():
|
||||
UI_BusyStart('Coonecting to repository.....')
|
||||
status_ok, ret = fetch_profiles_by_name(repo_url, distro, prof_name)
|
||||
UI_BustStop()
|
||||
UI_BusyStop()
|
||||
if status_ok:
|
||||
profile_hash = ret
|
||||
else:
|
||||
|
|
|
@ -51,7 +51,8 @@ class Config:
|
|||
if sys.version_info > (3,0):
|
||||
config.read(filepath)
|
||||
else:
|
||||
config.readfp(open_file_read(filepath))
|
||||
tmp_filepath = py2_parser(filepath)
|
||||
config.read(tmp_filepath.name)
|
||||
return config
|
||||
|
||||
def write_config(self, filename, config):
|
||||
|
@ -245,4 +246,18 @@ class Config:
|
|||
options = config.options(section)
|
||||
for option in options:
|
||||
line = ' ' + option + ' = ' + config[section][option] + '\n'
|
||||
f_out.write(line)
|
||||
f_out.write(line)
|
||||
|
||||
def py2_parser(filename):
|
||||
tmp = tempfile.NamedTemporaryFile('rw')
|
||||
f_out = open(tmp.name, 'w')
|
||||
if os.path.exists(filename):
|
||||
with open_file_read(filename) as f_in:
|
||||
for line in f_in:
|
||||
if line[:2] == ' ':
|
||||
line = line[2:]
|
||||
f_out.write(line)
|
||||
f_out.flush()
|
||||
return tmp
|
||||
|
||||
|
Loading…
Add table
Reference in a new issue