Commits

Anonymous committed 1ee859c

Support runtime finding and loading of VCS submodules.

Instead of using hardcoded module list, try to find modules matching
inherited eclass names in runtime and import them as necessary.

Comments (0)

Files changed (7)

SmartLiveRebuild/core.py

 from SmartLiveRebuild.output import out
 from SmartLiveRebuild.vcs import NonLiveEbuild
 
-def SmartLiveRebuild(opts, args, vcsl):
+def SmartLiveRebuild(opts, args):
 	if not opts.color:
 		out.monochromize()
 
 				os.close(commpipe[0])
 				os.setuid(puid)
 			if opts.type:
-				vcslf = [x for x in vcsl if x.inherit in opts.type]
+				allowed = frozenset(opts.type)
 			else:
-				vcslf = vcsl
+				allowed = None
 
 			out.s1('Enumerating the packages ...')
 
 			erraneous = []
 			rebuilds = {}
 
+			vcses = {}
 			envtmpf = tempfile.NamedTemporaryFile('w+b')
 			try:
 				db = portage.db[portage.settings['ROOT']]['vartree'].dbapi
 					try:
 						inherits = db.aux_get(cpv, ['INHERITED'])[0].split()
 
-						for vcs in vcslf:
-							if vcs.match(inherits):
+						for vcs in inherits:
+							if vcs not in vcses:
+								if allowed and vcs not in allowed:
+									vcses[vcs] = None
+								else:
+									try:
+										modname = 'SmartLiveRebuild.%s' % vcs
+										vcses[vcs] = __import__(modname, globals(), locals(), ['myvcs']).myvcs
+									except ImportError:
+										vcses[vcs] = None
+
+							if vcses[vcs] is not None:
 								env = bz2.BZ2File('%s/environment.bz2' % db.getpath(cpv), 'r')
-								vcs = vcs(cpv, env, envtmpf, opts)
+								vcs = vcses[vcs](cpv, env, envtmpf, opts)
 								env.close()
 								if opts.network or vcs.getsavedrev():
 									dir = vcs.getpath()

SmartLiveRebuild/cvs.py

 from SmartLiveRebuild.vcs import VCSSupport
 
 class CVSSupport(VCSSupport):
-	inherit = 'cvs'
 	reqenv = ['ECVS_AUTH', 'ECVS_CVS_COMMAND', 'ECVS_MODULE', 'ECVS_SERVER', 'ECVS_TOP_DIR', 'ECVS_USER']
 	optenv = ['ECVS_BRANCH', 'ECVS_CLEAN', 'ECVS_LOCAL', 'ECVS_LOCALNAME', 'ECVS_PASS',
 			'ECVS_RUNAS', 'ECVS_UP_OPTS', 'ECVS_VERSION']
 		cmd = '; '.join([trap_cmd, env_cmd, stdout_cmd, login_cmd, up_cmd])
 
 		return cmd
+
+myvcs = CVSSupport

SmartLiveRebuild/git.py

 from SmartLiveRebuild.vcs import VCSSupport, NonLiveEbuild
 
 class GitSupport(VCSSupport):
-	inherit = 'git'
 	reqenv = ['EGIT_BRANCH', 'EGIT_PROJECT', 'EGIT_STORE_DIR', 'EGIT_UPDATE_CMD']
 	optenv = ['EGIT_COMMIT', 'EGIT_DIFFSTAT_CMD', 'EGIT_HAS_SUBMODULES', 'EGIT_OPTIONS', 'EGIT_REPO_URI', 'EGIT_VERSION']
 
 
 	def diffstat(self, oldrev, newrev):
 		subprocess.Popen('%s %s..%s' % (self.env['EGIT_DIFFSTAT_CMD'] or 'git diff', oldrev, newrev), stdout=sys.stderr, shell=True).wait()
+
+myvcs = GitSupport

SmartLiveRebuild/mercurial.py

 from SmartLiveRebuild.vcs import VCSSupport, NonLiveEbuild
 
 class HgSupport(VCSSupport):
-	inherit = 'mercurial'
 	reqenv = ['EHG_PROJECT', 'EHG_PULL_CMD', 'EHG_REPO_URI']
 	optenv = ['EHG_REVISION']
 
 
 	def diffstat(self, oldrev, newrev):
 		subprocess.Popen(['hg', 'diff', '--stat', '-r', oldrev, '-r', newrev] + self.trustopt, stdout=sys.stderr).wait()
+
+myvcs = HgSupport

SmartLiveRebuild/subversion.py

 from SmartLiveRebuild.vcs import VCSSupport, NonLiveEbuild
 
 class SvnSupport(VCSSupport):
-	inherit = 'subversion'
 	reqenv = ['ESVN_STORE_DIR', 'ESVN_UPDATE_CMD', 'ESVN_WC_PATH']
 	optenv = ['ESVN_REVISION', 'ESVN_OPTIONS', 'ESVN_PASSWORD', 'ESVN_REPO_URI', 'ESVN_USER', 'ESVN_WC_REVISION']
 
 		if self.env['ESVN_USER']:
 			cmd += ' --user "%s" --password "%s"' % (self.env['ESVN_USER'], self.env['ESVN_PASSWORD'])
 		return cmd
+
+myvcs = SvnSupport

SmartLiveRebuild/vcs.py

 	pass
 
 class VCSSupport:
-	inherit = None
 	reqenv = []
 	optenv = []
 
-	@classmethod
-	def match(self, inherits):
-		if self.inherit is None:
-			raise NotImplementedError('VCS class needs to either override inherit or match()')
-		return self.inherit in inherits
-
 	def bashparse(self, envf, vars, f):
 		f.seek(0, 0)
 		f.truncate(0)
 
 	def __str__(self):
 		return ', '.join(self.cpv)
-
-

smart-live-rebuild

 from SmartLiveRebuild import PV
 from SmartLiveRebuild.output import out
 
-from SmartLiveRebuild.git import GitSupport
-from SmartLiveRebuild.mercurial import HgSupport
-from SmartLiveRebuild.subversion import SvnSupport
-from SmartLiveRebuild.cvs import CVSSupport
-
 from SmartLiveRebuild.core import SmartLiveRebuild
 
-vcsl = [GitSupport, HgSupport, SvnSupport, CVSSupport]
-
 def main(argv):
 	opt = OptionParser(
 			usage='%prog [options] -- [emerge options]',
 	if not opts.type:
 		opts.type = deftypes
 
-	return SmartLiveRebuild(opts, args, vcsl)
+	return SmartLiveRebuild(opts, args)
 
 if __name__ == '__main__':
 	sys.exit(main(sys.argv))