mooli tayer has uploaded a new change for review.
Change subject: configfile: remove unneeded methods. ......................................................................
configfile: remove unneeded methods.
Change-Id: Icf08bfebc83a9af5eb3c7de48f9a51d2263766fd Signed-off-by: Mooli Tayer mtayer@redhat.com --- M lib/vdsm/tool/configurators/configfile.py M tests/toolTests.py 2 files changed, 2 insertions(+), 106 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/24/36324/1
diff --git a/lib/vdsm/tool/configurators/configfile.py b/lib/vdsm/tool/configurators/configfile.py index d8b7fdd..d1e0472 100644 --- a/lib/vdsm/tool/configurators/configfile.py +++ b/lib/vdsm/tool/configurators/configfile.py @@ -83,7 +83,6 @@ version, sectionStart='## beginning of configuration section by vdsm', sectionEnd='## end of configuration section by vdsm', - prefix='# VDSM backup', lineComment='by vdsm'): if not os.path.exists(filename): raise OSError( @@ -94,7 +93,6 @@ self._context = False self._sectionStart = sectionStart self._sectionEnd = sectionEnd - self._prefix = prefix # remove 'lineComment' at 4.0. see 'Backward compatibility' self._lineComment = lineComment self._version = version @@ -104,9 +102,6 @@ raise RuntimeError("can only enter once") self._entries = {} self._context = True - self._prefixRemove = None - self._prefixAdd = None - self._section = None self._oldmod = os.stat(self._filename).st_mode self._remove = None self._rmstate = BEFORE @@ -131,11 +126,6 @@ continue
if not self._remove or self._rmstate != WITHIN: - if self._prefixRemove: - if line.startswith(self._prefix): - line = line[len(self._prefix):] - if self._prefixAdd: - line = self._prefix + line m = confpat.match(line.rstrip()) if m: oldentries.add(m.group('key')) @@ -149,11 +139,6 @@
def _end(self): return "%s-%s\n" % (self._sectionEnd, self._version) - - def _writeSection(self, f): - f.write(self._start()) - f.write(self._section) - f.write(self._end())
def _writeEntries(self, f, oldentries): f.write(self._start()) @@ -170,8 +155,6 @@ try: oldlines, oldentries = self._getOldContent() with os.fdopen(fd, 'w', ) as f: - if self._section: - self._writeSection(f) f.writelines(oldlines) if self._entries: self._writeEntries(f, oldentries) @@ -199,32 +182,6 @@ all pairs are added in a comment wrapped section. """ self._entries[key] = val - - @context - def prependSection(self, section): - """ - add 'section' in the beginning of the file. - section is added in a comment wrapped section. - - Only one section is currently supported. - """ - self._section = section - - @context - def prefixLines(self): - """ - Add self.prefix to the beginning of each line. - No editing is done on new content added by this config file. - """ - self._prefixAdd = True - - @context - def unprefixLines(self): - """ - Remove self.prefix from each line starting with it. - No editing is done on new content added by this config file. - """ - self._prefixRemove = True
@context def removeConf(self): diff --git a/tests/toolTests.py b/tests/toolTests.py index 82a2668..89a93bf 100644 --- a/tests/toolTests.py +++ b/tests/toolTests.py @@ -452,66 +452,6 @@ "key4=val\n" "# end conf-3.4.4\n")
- def testPrefixAndPrepend(self): - self._writeConf("/var/log/libvirt/libvirtd.log {\n" - " weekly\n" - "}\n") - with ConfigFile(self.tname, - version='3.4.4', - sectionStart="# start conf", - sectionEnd="# end conf", - prefix="# comment ") as conf: - conf.prefixLines() - conf.prependSection("Some text to\n" - "add at the top\n") - with open(self.tname, 'r') as f: - self.assertEqual(f.read(), - "# start conf-3.4.4\n" - "Some text to\n" - "add at the top\n" - "# end conf-3.4.4\n" - "# comment /var/log/libvirt/libvirtd.log {\n" - "# comment weekly\n" - "# comment }\n") - - def testPrefixIdempotencey(self): - original = ( - "/var/log/libvirt/libvirtd.log {\n" - " weekly\n" - "}\n" - ) - self._writeConf(original) - with ConfigFile(self.tname, - version='3.4.4', - sectionStart="# start conf", - sectionEnd="# end conf", - prefix="# comment ") as conf: - conf.prefixLines() - with open(self.tname, 'r') as f: - self.assertEqual(f.read(), - "# comment /var/log/libvirt/libvirtd.log {\n" - "# comment weekly\n" - "# comment }\n") - with ConfigFile(self.tname, - version='3.4.4', - sectionStart="# start conf", - sectionEnd="# end conf", - prefix="# comment ") as conff: - conff.unprefixLines() - with open(self.tname, 'r') as f: - self.assertEqual(f.read(), original) - - def testRemoveEntireLinePrefix(self): - self._writeConf("# comment\n") - with ConfigFile(self.tname, - version='3.4.4', - sectionStart="# start conf", - sectionEnd="# end conf", - prefix="# comment") as conf: - conf.unprefixLines() - with open(self.tname, 'r') as f: - self.assertEqual(f.read(), "\n") - def testRemoveConfSection(self): self._writeConf("key=val\n" "remove me!(see 'Backward compatibility')# by vdsm\n" @@ -523,8 +463,7 @@ with ConfigFile(self.tname, version='3.4.4', sectionStart="# start conf", - sectionEnd="# end conf", - prefix="# comment") as conf: + sectionEnd="# end conf") as conf: conf.removeConf() with open(self.tname, 'r') as f: self.assertEqual(f.read(), "key=val\n" @@ -536,7 +475,7 @@ version='3.4.4', sectionStart="# start conf", sectionEnd="# end conf") - self.assertRaises(RuntimeError, conff.prefixLines) + self.assertRaises(RuntimeError, conff.addEntry, 'key', 'val') self.assertRaises(RuntimeError, conff.removeConf)
def testHasConf(self):