1. Michał Górny
  2. smart-live-rebuild

Commits

Michał Górny  committed 968ad38

Move Config.apply_optparse() to a new CLIConfig subclass.

  • Participants
  • Parent commits 22e75ed
  • Branches master

Comments (0)

Files changed (2)

File SmartLiveRebuild/cli.py

View file
 # (c) 2010 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 3-clause BSD license or the GPL-2 license.
 
-import os
+import itertools, os
 from copy import copy
 from optparse import OptionParser, Option, OptionValueError
 
 	TYPE_CHECKER = copy(Option.TYPE_CHECKER)
 	TYPE_CHECKER['vcslist'] = check_vcslist
 
+class CLIConfig(Config):
+	def apply_optparse(self, values):
+		for k in self.defaults():
+			try:
+				v = getattr(values, k)
+				if v is None:
+					raise ValueError
+			except (AttributeError, ValueError):
+				pass
+			else:
+				if isinstance(v, list):
+					v = ','.join(itertools.chain(*v))
+				self.set(self._current_section, k, str(v))
+
 def parse_options(argv):
 	opt = OptionParser(
 			usage='%prog [options] -- [emerge options]',
 
 def main(argv):
 	# initialize config with defaults
-	c = Config()
+	c = CLIConfig()
 
 	# parse opts to get the config file
 	(opts, args) = parse_options(argv)

File SmartLiveRebuild/core.py

View file
 # (c) 2010 Michał Górny <mgorny@gentoo.org>
 # Released under the terms of the 3-clause BSD license or the GPL-2 license.
 
-import bz2, errno, fcntl, itertools, os.path, pickle, select, shutil, signal, subprocess, sys, tempfile, time
+import bz2, errno, fcntl, os.path, pickle, select, shutil, signal, subprocess, sys, tempfile, time
 import portage
 
 try:
 		self._current_section = 'DEFAULT'
 		ConfigParser.__init__(self, self._real_defaults)
 
-	def apply_optparse(self, values):
-		for k in self.defaults():
-			try:
-				v = getattr(values, k)
-				if v is None:
-					raise ValueError
-			except (AttributeError, ValueError):
-				pass
-			else:
-				if isinstance(v, list):
-					v = ','.join(itertools.chain(*v))
-				self.set(self._current_section, k, str(v))
-
 	def apply_dict(self, values):
 		for k, v in values.items():
 			self.set(self._current_section, k, str(v))