Commits

Michał Górny  committed 244d7e6

Move GetVCS() to core.

  • Participants
  • Parent commits b120683

Comments (0)

Files changed (4)

File smartliverebuild/cli.py

 
 from smartliverebuild import PV
 from smartliverebuild.config import Config
-from smartliverebuild.core import SmartLiveRebuild, SLRFailure
+from smartliverebuild.core import GetVCS, SmartLiveRebuild, SLRFailure
 from smartliverebuild.output import out
-from smartliverebuild.vcs 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.vcs import GetVCS
 
 class Config(ConfigParser):
 	def __init__(self, settings = None):

File smartliverebuild/core.py

 from portage.versions import catpkgsplit, pkgsplit
 
 from smartliverebuild.output import out
-from smartliverebuild.vcs import NonLiveEbuild, GetVCS
+from smartliverebuild.vcs import NonLiveEbuild, VCSSupport
 
 class SLRFailure(Exception):
 	pass
 		for m in self._broken:
 			yield m.wildcard
 
+vcs_cache = {}
+
+def GetVCS(eclassname, allowed = []):
+	if eclassname not in vcs_cache:
+		if allowed and eclassname not in allowed:
+			vcs_cache[eclassname] = None
+		else:
+			modname = 'smartliverebuild.vcs.%s' % eclassname.replace('-', '_')
+			try:
+				mod = __import__(modname, {}, {}, ['.'], 0)
+			except ImportError:
+				vcs_cache[eclassname] = None
+			else:
+				for k in dir(mod):
+					modvar = getattr(mod, k)
+					if issubclass(modvar, VCSSupport) and \
+							not issubclass(VCSSupport, modvar):
+						vcs_cache[eclassname] = modvar
+						break
+				else:
+					raise ImportError('Unable to find a matching class in %s' % mod)
+
+	return vcs_cache[eclassname]
+
 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/vcs/__init__.py

 			the program output.
 		"""
 		return ', '.join(self.cpv)
-
-vcs_cache = {}
-
-def GetVCS(eclassname, allowed = []):
-	if eclassname not in vcs_cache:
-		if allowed and eclassname not in allowed:
-			vcs_cache[eclassname] = None
-		else:
-			modname = 'smartliverebuild.vcs.%s' % eclassname.replace('-', '_')
-			try:
-				mod = __import__(modname, {}, {}, ['.'], 0)
-			except ImportError:
-				vcs_cache[eclassname] = None
-			else:
-				for k in dir(mod):
-					modvar = getattr(mod, k)
-					if issubclass(modvar, VCSSupport) and \
-							not issubclass(VCSSupport, modvar):
-						vcs_cache[eclassname] = modvar
-						break
-				else:
-					raise ImportError('Unable to find a matching class in %s' % mod)
-
-	return vcs_cache[eclassname]