Lines Matching refs:self
55 def __init__(self, name):
56 self.progname = name
57 self.indent = ("","","")
58 self.assign = (" = ","=")
59 self.dassign = self.assign[0]
60 self.comment = ("#",)
61 self.dcomment = self.comment[0]
62 self.eol = ("\n",)
63 self.deol = self.eol[0]
64 self.sectnamdel = ("[","]")
65 self.subsectdel = ("{","}")
66 self.backup_suffix = ".ipabkp"
68 def setProgName(self, name):
69 self.progname = name
71 def setIndent(self, indent):
73 self.indent = indent
75 self.indent = (indent, )
79 def setOptionAssignment(self, assign):
81 self.assign = assign
83 self.assign = (assign, )
84 self.dassign = self.assign[0]
86 def setCommentPrefix(self, comment):
88 self.comment = comment
90 self.comment = (comment, )
91 self.dcomment = self.comment[0]
93 def setEndLine(self, eol):
95 self.eol = eol
97 self.eol = (eol, )
98 self.deol = self.eol[0]
100 def setSectionNameDelimiters(self, delims):
101 self.sectnamdel = delims
103 def setSubSectionDelimiters(self, delims):
104 self.subsectdel = delims
106 def matchComment(self, line):
107 for v in self.comment:
112 def matchEmpty(self, line):
117 def matchSection(self, line):
119 if len(self.sectnamdel) != 2:
121 if not cl.startswith(self.sectnamdel[0]):
123 if not cl.endswith(self.sectnamdel[1]):
125 return cl[len(self.sectnamdel[0]):-len(self.sectnamdel[1])]
127 def matchSubSection(self, line):
128 if self.matchComment(line):
131 parts = line.split(self.dassign, 1)
135 if parts[1].strip() == self.subsectdel[0]:
140 def matchSubSectionEnd(self, line):
141 if self.matchComment(line):
144 if line.strip() == self.subsectdel[1]:
149 def getSectionLine(self, section):
150 if len(self.sectnamdel) != 2:
152 return self.sectnamdel[0]+section+self.sectnamdel[1]+self.deol
161 def dump(self, options, level=0):
163 if level >= len(self.indent):
164 level = len(self.indent)-1
168 output += self.sectnamdel[0]+o['name']+self.sectnamdel[1]+self.deol
169 output += self.dump(o['value'], level+1)
172 output += self.indent[level]+o['name']+self.dassign+self.subsectdel[0]+self.deol
173 output += self.dump(o['value'], level+1)
174 output += self.indent[level]+self.subsectdel[1]+self.deol
177 output += self.indent[level]+o['name']+self.dassign+o['value']+self.deol
180 output += self.dcomment+o['value']+self.deol
183 output += self.deol
189 def parseLine(self, line):
191 if self.matchEmpty(line):
194 value = self.matchComment(line)
198 parts = line.split(self.dassign, 1)
204 def findOpts(self, opts, type, name, exclude_sections=False):
215 def commentOpts(self, inopts, level = 0):
219 if level >= len(self.indent):
220 level = len(self.indent)-1
224 no = self.commentOpts(o['value'], level+1)
225 val = self.dcomment+self.sectnamdel[0]+o['name']+self.sectnamdel[1]
231 no = self.commentOpts(o['value'], level+1)
232 val = self.indent[level]+o['name']+self.dassign+self.subsectdel[0]
236 val = self.indent[level]+self.subsectdel[1]
240 val = self.indent[level]+o['name']+self.dassign+o['value']
253 def mergeOld(self, oldopts, newopts):
259 (num, no) = self.findOpts(newopts, o['type'], o['name'])
264 mo = self.mergeOld(o['value'], no['value'])
268 co = self.commentOpts(o['value'])
281 (num, no) = self.findOpts(newopts, 'option', o['name'], True)
291 'value':self.dcomment+o['name']+self.dassign+o['value']})
302 def mergeNew(self, opts, newopts):
309 (num, o) = self.findOpts(opts, no['type'], no['name'])
315 self.mergeNew(o['value'], no['value'])
321 (num, o) = self.findOpts(opts, no['type'], no['name'], True)
337 def merge(self, oldopts, newopts):
346 opts = self.mergeOld(oldopts, newopts)
347 self.mergeNew(opts, newopts)
351 def parse(self, f):
365 value = self.matchSection(line)
376 value = self.matchSubSection(line)
385 value = self.matchSubSectionEnd(line)
395 curopts.append(self.parseLine(line))
408 def changeConf(self, file, newopts):
416 shutil.copy2(file, file+self.backup_suffix)
420 oldopts = self.parse(f)
422 options = self.merge(oldopts, newopts)
424 output = self.dump(options)
443 def newConf(self, file, options):
451 shutil.copy2(file, file+self.backup_suffix)
463 output = self.dump(options)
484 def __init__(self):
485 IPAChangeConf.__init__(self, "SSSD")
486 self.comment = ("#",";")
487 self.backup_suffix = ".bak"
488 self.opts = []
490 def parseLine(self, line):
493 using any separator in self.assign, not just the default one
496 if self.matchEmpty(line):
499 value = self.matchComment(line)
503 mo = self.OPTCRE.match(line)
514 def readfp(self, fd):
515 self.opts.extend(self.parse(fd))
517 def read(self, filename):
519 self.readfp(fd)
522 def get(self, section, name):
523 index, item = self.get_option_index(section, name)
527 def set(self, section, name, value):
538 self.opts = self.merge(self.opts, [ modkw ])
540 def add_section(self, name, optkw, index=0):
546 self.opts.insert(index, addkw)
548 def delete_section(self, name):
549 self.delete_option('section', name)
551 def sections(self):
552 return [ o for o in self.opts if o['type'] == 'section' ]
554 def has_section(self, section):
555 return len([ o for o in self.opts if o['type'] == 'section' if o['name'] == section ]) > 0
557 def options(self, section):
558 for opt in self.opts:
562 def delete_option(self, type, name, exclude_sections=False):
563 return self.delete_option_subtree(self.opts, type, name)
565 def delete_option_subtree(self, subtree, type, name, exclude_sections=False):
566 index, item = self.findOpts(subtree, type, name, exclude_sections)
571 def has_option(self, section, name):
572 index, item = self.get_option_index(section, name)
577 def strip_comments_empty(self, optlist):
585 def get_option_index(self, parent_name, name, type='option'):
588 pindex, pdata = self.findOpts(self.opts, 'section', parent_name)
593 subtree = self.opts
594 return self.findOpts(subtree, type, name)