#
# ipachangeconf - configuration file manipulation classes and functions
# partially based on authconfig code
# Copyright (c) 1999-2007 Red Hat, Inc.
# Author: Simo Sorce <ssorce@redhat.com>
#
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 only
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
import fcntl
import os
import string
import time
import shutil
import re
fd = -1
if create:
try:
if fd != -1:
try:
except OSError:
pass
#TODO: add subsection as a concept
# (ex. REALM.NAME = { foo = x bar = y } )
#TODO: put section delimiters as separating element of the list
# so that we can process multiple sections in one go
#TODO: add a comment all but provided options as a section option
class IPAChangeConf:
else:
raise ValueError('Indent must be a list of strings')
else:
else:
else:
return False
return True
return False
return False
return False
return False
return False
return False
return False
return False
return True
return False
return section
output = ""
for o in options:
if o['type'] == "section":
continue
if o['type'] == "subsection":
continue
if o['type'] == "option":
continue
if o['type'] == "comment":
continue
if o['type'] == "empty":
continue
return output
return {'name':'empty', 'type':'empty'}
if value:
raise SyntaxError('Syntax Error: Unknown line format')
num = 0
for o in opts:
return (num, o)
return (num, None)
num += 1
return (num, None)
opts = []
for o in inopts:
if o['type'] == 'section':
for n in no:
continue
if o['type'] == 'subsection':
for n in no:
continue
if o['type'] == 'option':
continue
if o['type'] == 'comment':
continue
if o['type'] == 'empty':
continue
return opts
opts = []
for o in oldopts:
if o['type'] == "section" or o['type'] == "subsection":
if not no:
continue
continue
for c in co:
continue
continue
if o['type'] == "comment" or o['type'] == "empty":
continue
if o['type'] == "option":
if not no:
continue
continue
continue
continue
return opts
cline = 0
if not o:
continue
continue
continue
if not o:
continue
continue
cline += 1
continue
#Use a two pass strategy
#First we create a new opts tree from oldopts removing/commenting
# the options as indicated by the contents of newopts
#Second we fill in the new opts tree with options as indicated
# in the newopts tree (this is becaus eentire (sub)sections may
# exist in the newopts that do not exist in oldopts)
return opts
#TODO: Make parse() recursive?
opts = []
sectopts = []
section = None
subsectopts = []
subsection = None
# Read in the old file.
for line in f:
# It's a section start.
if value:
if section is not None:
sectopts = []
continue
# It's a subsection start.
if value:
if subsection is not None:
raise SyntaxError('nested subsections are not supported yet')
subsectopts = []
continue
if value:
if subsection is None:
raise SyntaxError('Unmatched end subsection terminator found')
subsection = None
continue
# Copy anything else as is.
#Add last section if any
return opts
# Write settings to configuration file
# file is a path
# options is a set of dictionaries in the form:
# section is a section name like 'global'
savedsection = None
output = ""
f = None
try:
#Do not catch an unexisting file error, we want to fail in that case
# Write it out and close it.
f.seek(0)
f.truncate(0)
finally:
try:
if f:
f.close()
except IOError:
pass
return True
# Write settings to new file, backup old
# file is a path
# options is a set of dictionaries in the form:
# section is a section name like 'global'
savedsection = None
output = ""
f = None
try:
try:
# The orign file did not exist
pass
# Trunkate
f.seek(0)
f.truncate(0)
finally:
try:
if f:
f.close()
except IOError:
pass
return True
# A SSSD-specific subclass of IPAChangeConf
r'(?P<option>[^:=\s][^:=]*)' # very permissive!
# followed by separator
r'(?P<value>.*)$' # everything up to eol
)
"""
Overrides IPAChangeConf parseLine so that lines are splitted
using any separator in self.assign, not just the default one
"""
return {'name':'empty', 'type':'empty'}
if value:
if not mo:
raise SyntaxError('Syntax Error: Unknown line format')
try:
except IndexError:
raise SyntaxError('Syntax Error: Unknown line format')
if item:
return item['value']
'name' : section,
'value' : [{
'type' : 'option',
'name' : name,
'value' : value,
'action': 'set',
}],
'action': 'set',
}
'name' : name,
'value' : optkw,
}
return opt['value']
if item:
return index
return True
return False
retlist = []
continue
return retlist
subtree = None
if parent_name:
if not pdata:
return (-1, None)
else: