public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] portage r11463 - main/branches/prefix/bin
@ 2008-08-24 13:26 Fabian Groffen (grobian)
  0 siblings, 0 replies; only message in thread
From: Fabian Groffen (grobian) @ 2008-08-24 13:26 UTC (permalink / raw
  To: gentoo-commits

Author: grobian
Date: 2008-08-24 13:26:44 +0000 (Sun, 24 Aug 2008)
New Revision: 11463

Modified:
   main/branches/prefix/bin/portageq
Log:
   Merged from trunk -r11455:11460

   | 11456   | Add a new filter_protected command which is similar to       |
   | zmedico | is_protected but works by reading filenames from stdin and   |
   |         | writing to stdout only the filenames that are protected.     |
   |         | This allows an unlimited number of files to be checked via a |
   |         | single portageq call.                                        |
   
   | 11457   | Flush stdout after the loop inside filter_protected()        |
   | zmedico | completes.                                                   |
   
   | 11458   | Fix the loop in filter_protected() to continue when          |
   | zmedico | necessary due to an error.                                   |
   
   | 11459   | Fix spelling typos in error messages.                        |
   | zmedico |                                                              |
   
   | 11460   | Fix grammar. Thanks to ABCD.                                 |
   | zmedico |                                                              |


Modified: main/branches/prefix/bin/portageq
===================================================================
--- main/branches/prefix/bin/portageq	2008-08-24 13:21:34 UTC (rev 11462)
+++ main/branches/prefix/bin/portageq	2008-08-24 13:26:44 UTC (rev 11463)
@@ -220,7 +220,7 @@
 	The filename must begin with <root>.
 	"""
 	if len(argv) != 2:
-		sys.stderr.write("ERROR: expeced 2 parameters, got %d!\n" % len(argv))
+		sys.stderr.write("ERROR: expected 2 parameters, got %d!\n" % len(argv))
 		sys.stderr.flush()
 		return 2
 
@@ -261,6 +261,66 @@
 
 is_protected.uses_root = True
 
+def filter_protected(argv):
+	"""<root>
+	Read filenames from stdin and write them to stdout if they are protected.
+	All filenames are delimited by \\n and must begin with <root>.
+	"""
+	if len(argv) != 1:
+		sys.stderr.write("ERROR: expected 1 parameter, got %d!\n" % len(argv))
+		sys.stderr.flush()
+		return 2
+
+	root, = argv
+	out = sys.stdout
+	err = sys.stderr
+	cwd = None
+	try:
+		cwd = os.getcwd()
+	except OSError:
+		pass
+
+	import shlex
+	from portage.util import ConfigProtect
+
+	settings = portage.settings
+	protect = shlex.split(settings.get("CONFIG_PROTECT", ""))
+	protect_mask = shlex.split(settings.get("CONFIG_PROTECT_MASK", ""))
+	protect_obj = ConfigProtect(root, protect, protect_mask)
+
+	protected = 0
+	errors = 0
+
+	for line in sys.stdin:
+		filename = line.rstrip("\n")
+		f = portage.normalize_path(filename)
+		if not f.startswith(os.path.sep):
+			if cwd is None:
+				err.write("ERROR: cwd does not exist!\n")
+				err.flush()
+				errors += 1
+				continue
+			f = os.path.join(cwd, f)
+			f = portage.normalize_path(f)
+
+		if not f.startswith(root):
+			err.write("ERROR: file paths must begin with <root>!\n")
+			err.flush()
+			errors += 1
+			continue
+
+		if protect_obj.isprotected(f):
+			protected += 1
+			out.write("%s\n" % filename)
+	out.flush()
+
+	if errors:
+		return 2
+
+	return 0
+
+filter_protected.uses_root = True
+
 def best_visible(argv):
 	"""<root> [<category/package>]+
 	Returns category/package-version (without .ebuild).




^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-08-24 13:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-24 13:26 [gentoo-commits] portage r11463 - main/branches/prefix/bin Fabian Groffen (grobian)

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox