Commits

Michał Górny  committed dbea228

Move VCSLoader into a separate module.

  • Participants
  • Parent commits c2eb471

Comments (0)

Files changed (4)

File smartliverebuild/cli.py

 
 from smartliverebuild import PV
 from smartliverebuild.config import Config
-from smartliverebuild.core import GetVCS, SmartLiveRebuild, SLRFailure
+from smartliverebuild.core import SmartLiveRebuild, SLRFailure
 from smartliverebuild.output import out
+from smartliverebuild.vcsload import GetVCS
 
 def check_downgrade(opt, optstr, val):
 	if val not in ('always', 'same-pv', 'never'):

File smartliverebuild/config.py

 
 import portage
 
-from smartliverebuild.core import GetVCS
 from smartliverebuild.output import out
+from smartliverebuild.vcsload import GetVCS
 
 class Config(ConfigParser):
 	def __init__(self, settings = None):

File smartliverebuild/core.py

 from smartliverebuild.filtering import PackageFilter
 from smartliverebuild.output import out
 from smartliverebuild.vcs import NonLiveEbuild
+from smartliverebuild.vcsload import GetVCS
 
 class SLRFailure(Exception):
 	pass
 
-class VCSLoader(object):
-	vcs_cache = {}
-
-	def __call__(self, eclassname, allowed = []):
-		if eclassname not in self.vcs_cache:
-			if allowed and eclassname not in allowed:
-				self.vcs_cache[eclassname] = None
-			else:
-				modname = 'smartliverebuild.vcs.%s' % eclassname.replace('-', '_')
-				try:
-					mod = __import__(modname, {}, {}, ['.'], 0)
-				except ImportError:
-					self.vcs_cache[eclassname] = None
-				else:
-					for k in dir(mod):
-						if k.endswith('Support') and \
-								k[:-7].lower() == eclassname.replace('-', ''):
-							self.vcs_cache[eclassname] = getattr(mod, k)
-							break
-					else:
-						raise ImportError('Unable to find a matching class in %s' % modname)
-
-		return self.vcs_cache[eclassname]
-
-GetVCS = VCSLoader()
-
 def SmartLiveRebuild(opts, db = None, portdb = None, settings = None,
 		cliargs = None):
 	if db is None or portdb is None or settings is None:

File smartliverebuild/vcsload.py

+#	vim:fileencoding=utf-8
+# (c) 2011 Michał Górny <mgorny@gentoo.org>
+# Released under the terms of the 3-clause BSD license or the GPL-2 license.
+
+class VCSLoader(object):
+	vcs_cache = {}
+
+	def __call__(self, eclassname, allowed = []):
+		if eclassname not in self.vcs_cache:
+			if allowed and eclassname not in allowed:
+				self.vcs_cache[eclassname] = None
+			else:
+				modname = 'smartliverebuild.vcs.%s' % eclassname.replace('-', '_')
+				try:
+					mod = __import__(modname, {}, {}, ['.'], 0)
+				except ImportError:
+					self.vcs_cache[eclassname] = None
+				else:
+					for k in dir(mod):
+						if k.endswith('Support') and \
+								k[:-7].lower() == eclassname.replace('-', ''):
+							self.vcs_cache[eclassname] = getattr(mod, k)
+							break
+					else:
+						raise ImportError('Unable to find a matching class in %s' % modname)
+
+		return self.vcs_cache[eclassname]
+
+GetVCS = VCSLoader()