[Yum-devel] [PATCH 2/2] prefer checked out sources over system modules

Nils Philippsen nils at redhat.com
Wed Sep 28 11:27:21 UTC 2011


Try our best to import modules from a checked out source hierarchy if
scripts are started from within it. The indicator for this is a file
"yummain.py" existing in the parent directory of the script.
---
 bin/yum |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/bin/yum b/bin/yum
index 3aac45a..0f48779 100755
--- a/bin/yum
+++ b/bin/yum
@@ -1,5 +1,20 @@
 #!/usr/bin/python
 import sys
+import os
+
+insert_sys_yum_cli_path = True
+try:
+    if __name__ == '__main__':
+        mainmod = sys.modules['__main__']
+        mainmod_file = mainmod.__file__
+        srcdir = os.path.abspath(
+                os.path.join(os.path.dirname(mainmod_file), os.path.pardir))
+        if os.path.exists(os.path.join(srcdir, "yummain.py")):
+            sys.path.insert(0, srcdir)
+            insert_sys_yum_cli_path = False
+except (KeyError, AttributeError):
+    pass
+
 try:
     import yum
 except ImportError:
@@ -23,7 +38,9 @@ the yum faq at:
 """ % (sys.exc_value, sys.version)
     sys.exit(1)
 
-sys.path.insert(0, '/usr/share/yum-cli')
+if insert_sys_yum_cli_path:
+    sys.path.insert(0, '/usr/share/yum-cli')
+
 try:
     import yummain
     yummain.user_main(sys.argv[1:], exit_code=True)
-- 
1.7.6.2



More information about the Yum-devel mailing list