Commits

Anonymous committed 0016eda

Introduce Shared class to keep data shared between multiple VCSSupport instances.

Comments (0)

Files changed (1)

smart-live-rebuild.py

 	def out(msg):
 		sys.stderr.write(msg)
 
+class Shared:
+	envtmpf = None
+	opts = None
+
+	@classmethod
+	def opentmp(self):
+		self.envtmpf = tempfile.NamedTemporaryFile()
+
+	@classmethod
+	def closetmp(self):
+		self.envtmpf.close()
+
 class VCSSupport:
 	inherit = None
 	reqenv = []
 	optenv = []
 
-	envtmpf = tempfile.NamedTemporaryFile()
-
 	@classmethod
 	def match(self, inherits):
 		if self.inherit is None:
 		return self.inherit in inherits
 
 	def bashparse(self, envf, vars):
-		f = self.envtmpf
+		f = Shared.envtmpf
 		f.seek(0, 0)
 		f.truncate(0)
 		f.write(envf.read())
 	opt.add_option('-U', '--unprivileged-user', action='store_false', dest='reqroot', default=True,
 		help='Allow running as an unprivileged user.')
 	(opts, args) = opt.parse_args(argv[1:])
+	Shared.opts = opts
 
 	if opts.monochrome:
 		out.monochromize()
 
 	out.s1('Enumerating packages ...')
 
-	db = portage.db[portage.settings['ROOT']]['vartree'].dbapi
-	for cpv in db.cpv_all():
-		try:
-			inherits = db.aux_get(cpv, ['INHERITED'])[0].split()
-
-			for vcs in vcslf:
-				if vcs.match(inherits):
-					env = bz2.BZ2File(u'%s/environment.bz2' % db.getpath(cpv), 'r')
-					vcs = vcs(cpv, env)
-					env.close()
-					dir = vcs.getpath()
-					if dir not in rebuilds:
-						rebuilds[dir] = vcs
-					else:
-						rebuilds[dir].append(vcs)
-		except KeyboardInterrupt:
-			VCSSupport.envtmpf.close()
-			raise
-		except Exception as e:
-			out.err('Error enumerating %s: [%s] %s' % (cpv, e.__class__.__name__, e))
+	Shared.opentmp()
+	try:
+		db = portage.db[portage.settings['ROOT']]['vartree'].dbapi
+		for cpv in db.cpv_all():
+			try:
+				inherits = db.aux_get(cpv, ['INHERITED'])[0].split()
+
+				for vcs in vcslf:
+					if vcs.match(inherits):
+						env = bz2.BZ2File(u'%s/environment.bz2' % db.getpath(cpv), 'r')
+						vcs = vcs(cpv, env)
+						env.close()
+						dir = vcs.getpath()
+						if dir not in rebuilds:
+							rebuilds[dir] = vcs
+						else:
+							rebuilds[dir].append(vcs)
+			except KeyboardInterrupt:
+				raise
+			except Exception as e:
+				out.err('Error enumerating %s: [%s] %s' % (cpv, e.__class__.__name__, e))
+	finally:
+		Shared.closetmp()
 
-	VCSSupport.envtmpf.close()
 	out.s1('Updating repositories ...')
 	packages = []
 
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.