Michał Górny avatar Michał Górny committed 812debe

Use gentoopm whenever possible.

Comments (0)

Files changed (7)

smartliverebuild/cli.py

 from copy import copy
 from optparse import OptionParser, Option, OptionValueError
 
-from portage.data import portage_uid, portage_gid
+from gentoopm import get_package_manager
 
 from smartliverebuild import PV
 from smartliverebuild.config import Config, conf_getvcs
 	return opt.parse_args(argv[1:])
 
 def main(argv):
+	pm = get_package_manager()
+	pm_conf = pm.config
+
 	# initialize config with defaults
-	c = CLIConfig()
+	c = CLIConfig(pm_conf)
 
 	# parse opts to get the config file
 	(opts, args) = parse_options(argv)
 			pass
 
 	if opts.setuid:
+		portage_uid = pm_conf.userpriv_uid
+		portage_gid = pm_conf.userpriv_gid
 		if portage_uid and portage_gid and os.geteuid() != 0 and os.getuid() == portage_uid:
 			if not opts.pretend:
 				out.s1('Running as the portage user, assuming --pretend.')
 				out.err("Running as the portage user, --quickpkg probably won't work")
 
 	try:
-		packages = SmartLiveRebuild(opts, cliargs = args)
+		packages = SmartLiveRebuild(opts, pm, cliargs = args)
 	except SLRFailure:
 		return 1
 

smartliverebuild/config.py

 except ImportError: # py2
 	from ConfigParser import ConfigParser, NoOptionError
 
-import portage
-
 from smartliverebuild.output import out
 from smartliverebuild.vcsload import VCSLoader
 
 conf_getvcs = VCSLoader()
 
 class Config(ConfigParser):
-	def __init__(self, settings = None):
-		if settings is None:
-			settings = portage.settings
-
+	def __init__(self, pm_conf):
 		self._real_defaults = {
 			'allow_downgrade': 'same-pv',
 			'color': 'True',
 			'profile': 'smart-live-rebuild',
 			'quickpkg': 'False',
 			'remote_only': 'False',
-			'setuid': str('userpriv' in settings.features),
+			'setuid': str(pm_conf.userpriv_enabled),
 			'type': '',
 			'unprivileged_user': 'False'
 		}

smartliverebuild/core.py

 class SLRFailure(Exception):
 	pass
 
-def SmartLiveRebuild(opts, db = None, portdb = None, settings = None,
-		cliargs = None):
-	if db is None or portdb is None or settings is None:
-		trees = create_trees(
-				config_root = os.environ.get('PORTAGE_CONFIGROOT'),
-				target_root = os.environ.get('ROOT'))
-		tree = trees[max(trees)]
-		if db is None:
-			db = tree['vartree'].dbapi
-		if portdb is None:
-			portdb = tree['porttree'].dbapi
-		if settings is None:
-			settings = db.settings
-
+def SmartLiveRebuild(opts, pm, cliargs = None):
 	if not opts.color:
 		out.monochromize()
 
 	commpipe = None
 	userok = (os.geteuid() == 0)
 	if opts.setuid:
+		pm_conf = pm.config
+		portage_uid = pm_conf.userpriv_uid
+		portage_gid = pm_conf.userpriv_gid
 		if portage_uid and portage_gid:
 			if not userok:
 				if os.getuid() == portage_uid:
 			else:
 				out.s1('Updating the repositories using %s%d%s parallel jobs...' % (out.white, opts.jobs, out.s1reset))
 
-			atoms = db.cpv_all()
+			it = iter(pm.installed)
 			processes = []
 
 			packages = []
 						del processes[i]
 				return needsleep
 
-			bash = BashParser()
-
 			filters = (opts.filter_packages or []) + (cliargs or [])
 			filt = PackageFilter(filters)
 			getvcs = VCSLoader()
 
 			try:
-				try:
-					while atoms:
-						cpv = atoms.pop(0)
-						if not filt(cpv):
-							continue
-
-						try:
-							aux = db.aux_get(cpv, ['INHERITED', 'SLOT'])
-							inherits = aux[0].split()
-							slot = aux[1]
-							if slot:
-								slottedcpv = '%s:%s' % (cpv, slot)
-							else:
-								slottedcpv = cpv
-
-							for vcs in inherits:
-								vcscl = getvcs(vcs, allowed, remote_only = opts.remote_only)
-								if vcscl is not None:
-									env = bz2.BZ2File('%s/environment.bz2' % db.getpath(cpv), 'r')
-									bash.grabenv(env)
-									vcs = vcscl(slottedcpv, bash, opts)
-									env.close()
-
-									uri = str(vcs)
-									if uri not in rebuilds:
-										rebuilds[uri] = vcs
-										processes.append(vcs)
-										loop_iter()
-									elif rebuilds[uri] in processes:
-										rebuilds[uri] += vcs
-									elif rebuilds[uri].cpv[0] in packages:
-										packages.extend(vcs.cpv)
-									elif rebuilds[uri].cpv[0] in erraneous:
-										erraneous.extend(vcs.cpv)
-						except KeyboardInterrupt:
+				while True:
+					try:
+						pkg = next(it)
+					except StopIteration:
+						break
+					if not filt(pkg.key):
+						continue
+
+					try:
+						inherits = pkg.metadata['INHERITED'].split()
+						slot = pkg.metadata['SLOT']
+						slottedcpv = pkg.id
+						if slot: # XXX: atom manip.
+							slottedcpv = slottedcpv.replace('::', ':%s::' % slot)
+
+						for vcs in inherits:
+							vcscl = getvcs(vcs, allowed, remote_only = opts.remote_only)
+							if vcscl is not None:
+								vcs = vcscl(slottedcpv, pkg.environ, opts)
+
+								uri = str(vcs)
+								if uri not in rebuilds:
+									rebuilds[uri] = vcs
+									processes.append(vcs)
+									loop_iter()
+								elif rebuilds[uri] in processes:
+									rebuilds[uri] += vcs
+								elif rebuilds[uri].cpv[0] in packages:
+									packages.extend(vcs.cpv)
+								elif rebuilds[uri].cpv[0] in erraneous:
+									erraneous.extend(vcs.cpv)
+					except KeyboardInterrupt:
+						raise
+					except NonLiveEbuild as e:
+						out.err('%s: %s' % (pkg.id, e))
+					except Exception as e:
+						if opts.debug:
 							raise
-						except NonLiveEbuild as e:
-							out.err('%s: %s' % (cpv, e))
-						except Exception as e:
-							if opts.debug:
-								raise
-							out.err('Error enumerating %s: [%s] %s' % (cpv, e.__class__.__name__, e))
-							erraneous.append(cpv)
-				finally:
-					del bash
+						out.err('Error enumerating %s: [%s] %s' % (pkg.id, e.__class__.__name__, e))
+						erraneous.append(pkg.id)
 
 				while processes:
 					if loop_iter((opts.jobs == 1)):
 
 		def mypkgcut(slottedcpv, n):
 			""" Return n first components of split-joined slottedcpv. """
-			splitcpv = slottedcpv.rsplit(':', 1)
+			splitcpv = slottedcpv.split(':', 1)
 			splitcpv[0] = '-'.join(pkgsplit(splitcpv[0])[0:n])
 			return ':'.join(splitcpv)
 
 
 		# Check portdb for matches. Drop unmatched packages.
 		for p in list(packages):
-			if not portdb.match(p):
+			if pm.Atom(p) not in pm.stack:
 				out.err('No packages matching %s in portdb, skipping.' % p)
 				packages.remove(p)
 

smartliverebuild/filtering.py

 
 import fnmatch, re
 
-from portage.versions import catpkgsplit
+from portage.versions import catsplit
 
 wildcard_re = re.compile(r'^(!)?(?:([A-Za-z0-9_?*\[\]][A-Za-z0-9+_.?*\[\]-]*)/)?([A-Za-z0-9_?*\[\]][A-Za-z0-9+_?*\[\]-]*)$')
 
 
 			self.wildcard = wildcard
 
-		def __call__(self, cpv):
-			cat, pkg, ver, rev = catpkgsplit(cpv)
+		def __call__(self, cp):
+			cat, pkg = catsplit(cp)
 			m = bool(self.category.match(cat) and self.pn.match(pkg))
 			self.matched |= m
 			return m ^ self.exclusive
 			self._pmatchers = ()
 		self._default_pass = True
 
-	def __call__(self, cpv):
-		""" Execute filtering on CPV. """
+	def __call__(self, cp):
+		""" Execute filtering on CP. """
 		r = self._default_pass
 		for m in self._pmatchers:
 			if m.broken:
 				pass
 			elif m.exclusive:
-				r &= m(cpv)
+				r &= m(cp)
 			else:
-				r |= m(cpv)
+				r |= m(cp)
 		return r
 
 	@property

smartliverebuild/sets.py

 import os, re
 from portage import VERSION as portage_ver
 
+from gentoopm import get_package_manager
+
 # live git tree generates 'vX.Y_rcZ-N-...'
 # ebuilds use 'X.Y_rcZ_pN'
 vmatch = re.match(r'^v?((?:\d+\.)*\d+)(?:_rc(\d+))?(?:(?:_p|-)(\d+))?', str(portage_ver))
 	_operations = ["merge"]
 	description = "Package set containing live packages awaiting update"
 
-	def __init__(self, opts, vardbapi, portdbapi, settings):
+	def __init__(self, opts, pm):
 		self._options = opts
-		self._dbapi = vardbapi
-		self._portdb = portdbapi
-		self._settings = settings
+		self._pm = pm
 		PackageSet.__init__(self)
 
 	def load(self):
 
 		try:
 			if packages is None:
-				packages = SmartLiveRebuild(self._options,
-						db = self._dbapi, portdb = self._portdb,
-						settings = self._settings)
+				packages = SmartLiveRebuild(self._options, self._pm)
 		except SLRFailure:
 			pass
 		else:
 	def singleBuilder(cls, options, settings, trees):
 		# Clasically, apply twice. First time to get configfile path
 		# and profile; second time to override them.
-		c = Config(settings)
+		pm = get_package_manager()
+		c = Config(pm.config)
 		c.apply_dict(options)
 		c.parse_configfiles()
 		c.apply_dict(options)
 
-		vardb = trees['vartree'].dbapi
-		portdb = trees['porttree'].dbapi
-
-		return cls(c.get_options(), vardb, portdb, settings)
+		return cls(c.get_options, pm)

smartliverebuild/vcs/__init__.py

 		""" A list of CPVs which use this particular repository. """
 		return self._cpv
 
-	def __init__(self, cpv, bash, opts):
+	def __init__(self, cpv, environ, opts):
 		""" Initialize the VCS class for package `cpv', storing it as
-			self.cpv. Call `bash' BashParser instance to get the values
-			for environment variables (self.reqenv + self.optenv).
+			self.cpv. Get envvars from `environ' (self.reqenv + self.optenv).
 
 			`opts' should point to an ConfigValues instance.
 			
 		"""
 
 		self._cpv = [cpv]
-		self.env = bash(self.reqenv + self.optenv)
+		self.env = environ.copy(*(self.reqenv + self.optenv))
 		self._opts = opts
 
 		missingvars = [v for v in self.reqenv if self.env[v] == '']

smartliverebuild/vcs/mercurial.py

 class MercurialSupport(RemoteVCSSupport):
 	reqenv = ['EHG_REPO_URI', 'EHG_REVISION', 'HG_REV_ID']
 
-	trustopt = ['--config', 'trusted.users=portage']
+	trustopt = ['--config', 'trusted.users=portage'] # XXX: pm.config.userpriv_uid
 
 	def __str__(self):
 		return self.env['EHG_REPO_URI']
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.