From 7545829764b243b6d44a4680dfa09f8fecc0faa9 Mon Sep 17 00:00:00 2001 From: Thomas Vander Stichele Date: Tue, 4 Dec 2012 00:12:38 +0000 Subject: [PATCH] * morituri/common/config.py: Add methods to get/set defeating of audio cache. Make sure that we set read offset even if section is already there. --- ChangeLog | 6 +++++ morituri/common/config.py | 57 +++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5082140..455919c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2012-12-04 Thomas Vander Stichele + + * morituri/common/config.py: + Add methods to get/set defeating of audio cache. + Make sure that we set read offset even if section is already there. + 2012-12-03 Thomas Vander Stichele * morituri/common/task.py: diff --git a/morituri/common/config.py b/morituri/common/config.py index 3d052a7..dcf1cc4 100644 --- a/morituri/common/config.py +++ b/morituri/common/config.py @@ -71,17 +71,8 @@ class Config(log.Loggable): Strips the given strings of leading and trailing whitespace. """ - try: - section = self._findDriveSection(vendor, model, release) - except KeyError: - section = 'drive:' + urllib.quote('%s:%s:%s' % ( - vendor, model, release)) - self._parser.add_section(section) - __pychecker__ = 'no-local' - read_offset = str(offset) - for key in ['vendor', 'model', 'release', 'read_offset']: - self._parser.set(section, key, locals()[key].strip()) - + section = self._findOrCreateDriveSection(vendor, model, release) + self._parser.set(section, 'read_offset', str(offset)) self.write() def getReadOffset(self, vendor, model, release): @@ -92,6 +83,28 @@ class Config(log.Loggable): return int(self._parser.get(section, 'read_offset')) + def setDefeatsCache(self, vendor, model, release, defeat): + """ + Set whether the drive defeats the cache. + + Strips the given strings of leading and trailing whitespace. + """ + section = self._findOrCreateDriveSection(vendor, model, release) + self._parser.set(section, 'defeats_cache', str(defeat)) + self.write() + + def getDefeatsCache(self, vendor, model, release): + section = self._findDriveSection(vendor, model, release) + + return bool(self._parser.get(section, 'defeats_cache')) + + def write(self): + fd, path = tempfile.mkstemp(suffix=u'.moriturirc') + handle = os.fdopen(fd, 'w') + self._parser.write(handle) + handle.close() + shutil.move(path, self._path) + def _findDriveSection(self, vendor, model, release): for name in self._parser.sections(): if not name.startswith('drive:'): @@ -115,9 +128,19 @@ class Config(log.Loggable): raise KeyError - def write(self): - fd, path = tempfile.mkstemp(suffix=u'.moriturirc') - handle = os.fdopen(fd, 'w') - self._parser.write(handle) - handle.close() - shutil.move(path, self._path) + def _findOrCreateDriveSection(self, vendor, model, release): + try: + section = self._findDriveSection(vendor, model, release) + except KeyError: + section = 'drive:' + urllib.quote('%s:%s:%s' % ( + vendor, model, release)) + self._parser.add_section(section) + __pychecker__ = 'no-local' + for key in ['vendor', 'model', 'release']: + self._parser.set(section, key, locals()[key].strip()) + + self.write() + + return self._findDriveSection(vendor, model, release) + +