[PATCH 1/3] Merge run-hub with run-spoke as the code was almost identical

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

 



To start hub use the following command:

make runhub HUB_MODULE=summary

or

make runhub HUB_MODULE=summary HUB_CLASS=SummaryHub
---
 Makefile.am                          |    3 ++
 pyanaconda/ui/gui/tools/run-hub.py   |   65 +---------------------------------
 pyanaconda/ui/gui/tools/run-spoke.py |   39 ++++++++++++--------
 3 files changed, 29 insertions(+), 78 deletions(-)
 mode change 100755 => 120000 pyanaconda/ui/gui/tools/run-hub.py

diff --git a/Makefile.am b/Makefile.am
index 74612ad..59b5d0b 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -106,3 +106,6 @@ unittests-logpicker:
 # GUI TESTING
 runspoke:
 	ANACONDA_DATA=${PWD}/data ANACONDA_WIDGETS_DATA=${PWD}/widgets/data 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}
+
+runhub:
+	ANACONDA_DATA=${PWD}/data ANACONDA_WIDGETS_DATA=${PWD}/widgets/data 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-hub.py ${HUB_MODULE} ${HUB_CLASS}
diff --git a/pyanaconda/ui/gui/tools/run-hub.py b/pyanaconda/ui/gui/tools/run-hub.py
deleted file mode 100755
index b75470f..0000000
--- a/pyanaconda/ui/gui/tools/run-hub.py
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/python
-
-from gi.repository import AnacondaWidgets, Gtk
-import ctypes, sys
-
-# This is a hack to make sure the AnacondaWidgets library gets loaded
-ctypes.CDLL("libAnacondaWidgets.so.0", ctypes.RTLD_GLOBAL)
-
-# Logging always needs to be set up first thing, or there'll be tracebacks.
-from pyanaconda import anaconda_log
-anaconda_log.init()
-
-from pyanaconda.installclass import DefaultInstall
-from pyanaconda.storage import Storage
-from pyanaconda.threads import initThreading
-from pyanaconda.packaging.yumpayload import YumPayload
-from pyanaconda.platform import getPlatform
-from pykickstart.version import makeVersion
-
-# Don't worry with fcoe, iscsi, dasd, any of that crud.
-from pyanaconda.flags import flags
-flags.imageInstall = True
-flags.testing = True
-
-initThreading()
-
-# NOTE:  To run your hub, you need to do the proper import here (may need to
-# set $PYTHONPATH as well) and set hubClass 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.hubs.summary import SummaryHub
-#hubClass = SummaryHub
-hubClass = None
-
-platform = getPlatform()
-ksdata = makeVersion()
-storage = Storage(data=ksdata, platform=platform)
-storage.reset()
-instclass = DefaultInstall()
-
-payload = YumPayload(ksdata)
-payload.setup(storage)
-payload.install_log = sys.stdout
-
-if not hubClass:
-    print "You forgot to set hubClass to something."
-    sys.exit(1)
-
-hub = hubClass(ksdata, storage, payload, instclass)
-hub.register_event_cb("continue", lambda: Gtk.main_quit())
-hub.register_event_cb("quit", lambda: Gtk.main_quit())
-hub.initialize()
-
-if not hub.showable:
-    print "This hub is not showable, but I'll continue anyway."
-
-hub.refresh()
-hub.window.set_beta(True)
-hub.window.set_property("distribution", "TEST HARNESS")
-hub.window.show_all()
-
-Gtk.main()
-
-print "Hub kickstart fragment:\n%s" % ksdata
diff --git a/pyanaconda/ui/gui/tools/run-hub.py b/pyanaconda/ui/gui/tools/run-hub.py
new file mode 120000
index 0000000..4583bed
--- /dev/null
+++ b/pyanaconda/ui/gui/tools/run-hub.py
@@ -0,0 +1 @@
+run-spoke.py
\ No newline at end of file
diff --git a/pyanaconda/ui/gui/tools/run-spoke.py b/pyanaconda/ui/gui/tools/run-spoke.py
index 65cae6a..e8205a9 100755
--- a/pyanaconda/ui/gui/tools/run-spoke.py
+++ b/pyanaconda/ui/gui/tools/run-spoke.py
@@ -2,6 +2,7 @@
 
 from gi.repository import AnacondaWidgets, Gtk
 import ctypes, sys
+import os.path
 
 # Check command line arguments
 if len(sys.argv)<2:
@@ -29,8 +30,23 @@ flags.testing = True
 
 initThreading()
 
-# Figure out the name of spoke module entered on command line
-spokeModuleName = "pyanaconda.ui.gui.spokes.%s" % sys.argv[1]
+# Figure out the part we are about to show: hub/spoke?
+# And get the name of the module which represents it
+if os.path.basename(sys.argv[0]) == "run-spoke.py":
+    spokeModuleName = "pyanaconda.ui.gui.spokes.%s" % sys.argv[1]
+    from pyanaconda.ui.gui.spokes import NormalSpoke
+    spokeBaseClass = NormalSpoke
+    spokeText = "spoke"
+    SpokeText = "Spoke"
+elif os.path.basename(sys.argv[0]) == "run-hub.py":
+    spokeModuleName = "pyanaconda.ui.gui.hubs.%s" % sys.argv[1]
+    from pyanaconda.ui.gui.hubs import Hub
+    spokeBaseClass = Hub
+    spokeText = "hub"
+    SpokeText = "Hub"
+else:
+    print "You have to run this command as run-spoke.py or run-hub.py."
+    sys.exit(1)
 
 # Set default spoke class
 spokeClass = None
@@ -45,10 +61,9 @@ try:
 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):
+            if issubclass(v, spokeBaseClass) and v != spokeBaseClass:
                 spokeClassName = k
                 spokeClass = v
                 break
@@ -59,11 +74,11 @@ if not spokeClass:
     try:
         spokeClass = getattr(spokeModule, spokeClassName)
     except KeyError:
-        print "Spoke %s could not be found in %s" % (spokeClassName, spokeModuleName)
+        print "%s %s could not be found in %s" % (SpokeText, spokeClassName, spokeModuleName)
         sys.exit(1)
 
 
-print "Running spoke %s from %s" % (spokeClass, spokeModule)
+print "Running %s %s from %s" % (spokeText, spokeClass, spokeModule)
 
 platform = getPlatform()
 ksdata = makeVersion()
@@ -75,10 +90,6 @@ payload = YumPayload(ksdata)
 payload.setup(storage)
 payload.install_log = sys.stdout
 
-if not spokeClass:
-    print "You forgot to set spokeClass to something."
-    sys.exit(1)
-
 spoke = spokeClass(ksdata, storage, payload, instclass)
 if hasattr(spoke, "register_event_cb"):
     spoke.register_event_cb("continue", lambda: Gtk.main_quit())
@@ -86,7 +97,7 @@ if hasattr(spoke, "register_event_cb"):
 spoke.initialize()
 
 if not spoke.showable:
-    print "This spoke is not showable, but I'll continue anyway."
+    print "This %s is not showable, but I'll continue anyway." % spokeText
 
 spoke.refresh()
 spoke.window.set_beta(True)
@@ -96,6 +107,6 @@ spoke.window.show_all()
 Gtk.main()
 
 if hasattr(spoke, "status"):
-    print "Spoke status:\n%s\n" % spoke.status
-print "Spoke completed:\n%s\n" % spoke.completed
-print "Spoke kickstart fragment:\n%s" % ksdata
+    print "%s status:\n%s\n" % (SpokeText, spoke.status)
+print "%s completed:\n%s\n" % (SpokeText, spoke.completed)
+print "%s kickstart fragment:\n%s" % (SpokeText, ksdata)
-- 
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