From f1d704b0d73ca9b42bc90c0cb078295b6a8d99b1 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sat, 8 Aug 2009 21:45:57 +0000 Subject: Move global portage import to the top and add writemsg and writemsg_stdout imports for safe unicode output. svn path=/main/trunk/; revision=13952 --- bin/portageq | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) (limited to 'bin/portageq') diff --git a/bin/portageq b/bin/portageq index a166eb2b5..941c5b807 100755 --- a/bin/portageq +++ b/bin/portageq @@ -23,6 +23,26 @@ import os import types +# Avoid sandbox violations after python upgrade. +pym_path = os.path.join(os.path.dirname( + os.path.dirname(os.path.realpath(__file__))), "pym") +if os.environ.get("SANDBOX_ON") == "1": + sandbox_write = os.environ.get("SANDBOX_WRITE", "").split(":") + if pym_path not in sandbox_write: + sandbox_write.append(pym_path) + os.environ["SANDBOX_WRITE"] = \ + ":".join(filter(None, sandbox_write)) + del sandbox_write + +try: + import portage +except ImportError: + sys.path.insert(0, pym_path) + import portage +del pym_path + +from portage.util import writemsg, writemsg_stdout + #----------------------------------------------------------------------------- # # To add functionality to this tool, add a function below. @@ -534,9 +554,10 @@ def usage(argv): # Show our commands -- we do this by scanning the functions in this # file, and formatting each functions documentation. # + non_commands = frozenset(['exithandler', 'main', + 'usage', 'writemsg', 'writemsg_stdout']) commands = sorted(k for k, v in globals().iteritems() \ - if type(v) is types.FunctionType and \ - k not in ('usage', 'main', 'exithandler')) + if type(v) is types.FunctionType and k not in non_commands) for name in commands: # Drop non-functions @@ -584,24 +605,6 @@ def main(): sys.exit(os.EX_USAGE) os.environ["ROOT"] = sys.argv[2] - # Avoid sandbox violations after python upgrade. - from os import path as osp - pym_path = osp.join(osp.dirname( - osp.dirname(osp.realpath(__file__))), "pym") - if os.environ.get("SANDBOX_ON") == "1": - sandbox_write = os.environ.get("SANDBOX_WRITE", "").split(":") - if pym_path not in sandbox_write: - sandbox_write.append(pym_path) - os.environ["SANDBOX_WRITE"] = \ - ":".join(filter(None, sandbox_write)) - - global portage - try: - import portage - except ImportError: - sys.path.insert(0, pym_path) - import portage - args = sys.argv[2:] if args and not isinstance(args[0], unicode): for i in xrange(len(args)): -- cgit v1.2.3-1-g7c22