[PATCH] [2nd] Improve the runspoke.py tool and make it callable from make

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Second version, I forgot to commit the last change.. oops.

make runspoke SPOKE_MODULE=source

or

make runspoke SPOKE_MODULE=source SPOKE_CLASS=InstallSource

- runspoke now accepts the name of the module containing
  the spoke the user wants to run on command line and
  will find the spoke automatically

- as an optional second argument, the script accepts the
  name of the spoke class

- install classes and gi introspection files are looked for
  in anaconda sources first, so there is no need to install
  the anaconda-widgets package to the system

- there was a circular dependency between yuminstall,
  backend and kickstart modules, which caused import yuminstall
  to fail, because:

  yuminstall called backend, which called kickstart, which
  requested NoSuchGroup from yuminstall. NoSuchGroup was
  present in the source, but much later, so it hadn't been
  evaluated yet and the import failed with missing symbol error.
---
 Makefile.am                          |    4 +++
 pyanaconda/installclass.py           |    8 +++++-
 pyanaconda/ui/gui/tools/run-spoke.py |   45 +++++++++++++++++++++++++++++-----
 pyanaconda/yuminstall.py             |   11 ++++-----
 4 files changed, 55 insertions(+), 13 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 1798740..4e2f6d6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -102,3 +102,7 @@ unittest:
 
 unittests-logpicker:
 	PYTHONPATH=tests/:.:utils/ nosetests tests/logpicker_test
+
+# GUI TESTING
+runspoke:
+	ANACONDA_INSTALL_CLASSES=${PWD}/pyanaconda/installclasses PYTHONPATH=.:pyanaconda/isys/.libs:widgets/python/:widgets/src/.libs/ LD_LIBRARY_PATH=widgets/src/.libs  UIPATH=pyanaconda/ui/gui/   GI_TYPELIB_PATH=widgets/src/ pyanaconda/ui/gui/tools/run-spoke.py ${SPOKE_MODULE} ${SPOKE_CLASS}
diff --git a/pyanaconda/installclass.py b/pyanaconda/installclass.py
index 7e8aca1..15dbe20 100644
--- a/pyanaconda/installclass.py
+++ b/pyanaconda/installclass.py
@@ -245,7 +245,11 @@ def availableClasses(showHidden=0):
 
     path = []
 
-    for dir in ["installclasses",
+    env_path = []
+    if "ANACONDA_INSTALL_CLASSES" in os.environ:
+        env_path += os.environ["ANACONDA_INSTALL_CLASSES"].split(":")
+
+    for dir in env_path + ["installclasses",
                 "/tmp/updates/pyanaconda/installclasses",
                 "/tmp/product/pyanaconda/installclasses",
                 "%s/pyanaconda/installclasses" % get_python_lib(plat_specific=1) ]:
@@ -297,6 +301,7 @@ def availableClasses(showHidden=0):
                 list.append(((obj.name, obj, obj.pixmap), sortOrder))
         except ImportError as e:
             log.warning ("module import of %s failed: %s" % (mainName, sys.exc_type))
+            raise
             if flags.debug: raise
             else: continue
 
@@ -316,6 +321,7 @@ def getBaseInstallClass():
     # figure out what installclass we should base on.
     allavail = availableClasses(showHidden = 1)
     avail = availableClasses(showHidden = 0)
+
     if len(avail) == 1:
         (cname, cobject, clogo) = avail[0]
         log.info("using only installclass %s" %(cname,))
diff --git a/pyanaconda/ui/gui/tools/run-spoke.py b/pyanaconda/ui/gui/tools/run-spoke.py
index aef62db..65cae6a 100755
--- a/pyanaconda/ui/gui/tools/run-spoke.py
+++ b/pyanaconda/ui/gui/tools/run-spoke.py
@@ -3,6 +3,11 @@
 from gi.repository import AnacondaWidgets, Gtk
 import ctypes, sys
 
+# Check command line arguments
+if len(sys.argv)<2:
+    print "Usage: $0 <spoke module name> [<spoke widget class>]"
+    sys.exit(1)
+
 # This is a hack to make sure the AnacondaWidgets library gets loaded
 ctypes.CDLL("libAnacondaWidgets.so.0", ctypes.RTLD_GLOBAL)
 
@@ -24,14 +29,42 @@ flags.testing = True
 
 initThreading()
 
-# NOTE:  To run your spoke, you need to do the proper import here (may need to
-# set $PYTHONPATH as well) and set spokeClass to be the class from that import.
-# I suppose this could be done automatically somehow, but that's hard and this
-# is a development testing tool.
-#from pyanaconda.ui.gui.spokes.software import SoftwareSelectionSpoke
-#spokeClass = SoftwareSelectionSpoke
+# Figure out the name of spoke module entered on command line
+spokeModuleName = "pyanaconda.ui.gui.spokes.%s" % sys.argv[1]
+
+# Set default spoke class
 spokeClass = None
 
+# Load spoke specified on the command line
+# If the spoke module was specified, but the spoke class was not,
+# try to find it using class hierarchy
+try:
+    spokeClassName = sys.argv[2]
+    __import__(spokeModuleName, fromlist = [spokeClassName])
+    spokeModule = sys.modules[spokeModuleName]
+except IndexError:
+    __import__(spokeModuleName)
+    spokeModule = sys.modules[spokeModuleName]
+    from pyanaconda.ui.gui.spokes import NormalSpoke
+    for k,v in vars(spokeModule).iteritems():
+        try:
+            if issubclass(v, NormalSpoke):
+                spokeClassName = k
+                spokeClass = v
+                break
+        except TypeError:
+            pass
+    
+if not spokeClass:
+    try:
+        spokeClass = getattr(spokeModule, spokeClassName)
+    except KeyError:
+        print "Spoke %s could not be found in %s" % (spokeClassName, spokeModuleName)
+        sys.exit(1)
+
+
+print "Running spoke %s from %s" % (spokeClass, spokeModule)
+
 platform = getPlatform()
 ksdata = makeVersion()
 storage = Storage(data=ksdata, platform=platform)
diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py
index d895e27..d8761ea 100644
--- a/pyanaconda/yuminstall.py
+++ b/pyanaconda/yuminstall.py
@@ -17,8 +17,6 @@
 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-from flags import flags
-
 import ConfigParser
 import sys
 import os
@@ -32,6 +30,10 @@ import tempfile
 import itertools
 import re
 
+class NoSuchGroup(Exception):
+    pass
+
+from flags import flags
 
 import anaconda_log
 import rpm
@@ -45,12 +47,12 @@ from yum.constants import *
 from yum.Errors import *
 from yum.misc import to_unicode
 from yum.yumRepo import YumRepository
-from backend import AnacondaBackend
 from product import isFinal, productName, productVersion, productStamp
 from constants import *
 from image import *
 from compssort import *
 import packages
+from backend import AnacondaBackend
 
 import gettext
 _ = lambda x: gettext.ldgettext("anaconda", x)
@@ -72,9 +74,6 @@ urlgrabber.grabber.default_grabber.opts.user_agent = "%s (anaconda)/%s" %(produc
 import iutil
 import isys
 
-class NoSuchGroup(Exception):
-    pass
-
 def size_string (size):
     def number_format(s):
         return locale.format("%s", s, 1)
-- 
1.7.10.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux