summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2009-08-08 21:45:57 +0000
committerZac Medico <zmedico@gentoo.org>2009-08-08 21:45:57 +0000
commitf1d704b0d73ca9b42bc90c0cb078295b6a8d99b1 (patch)
tree2a03d6e38c2a2766f042c0e2c3b6f8aa6f98e3fd
parentSimplify command introspection inside usage(). (diff)
downloadportage-f1d704b0d73ca9b42bc90c0cb078295b6a8d99b1.tar.gz
portage-f1d704b0d73ca9b42bc90c0cb078295b6a8d99b1.tar.bz2
portage-f1d704b0d73ca9b42bc90c0cb078295b6a8d99b1.zip
Move global portage import to the top and add writemsg and
writemsg_stdout imports for safe unicode output. svn path=/main/trunk/; revision=13952
-rwxr-xr-xbin/portageq43
1 files changed, 23 insertions, 20 deletions
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)):