[PATCH 1/3] Create execWithCallback() function in iutil.

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

 



Create an execWithCallback() function that takes in a callback function
and some data that is always passed to the callback function.  Change
execWithPulseProgress() to use execWithCallback().  The idea behind
execWithCallback() is to allow flexibility to creating non-pulse
progress bars or other UI indicators.
---
 iutil.py |   18 +++++++++++++++---
 1 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/iutil.py b/iutil.py
index 7ee1bf7..0b15bd8 100644
--- a/iutil.py
+++ b/iutil.py
@@ -242,8 +242,9 @@ def execWithCapture(command, argv, stdin = None, stderr = None, root='/'):
     closefds()
     return rc
 
-def execWithPulseProgress(command, argv, stdin = None, stdout = None,
-                          stderr = None, progress = None, root = '/'):
+def execWithCallback(command, argv, stdin = None, stdout = None,
+                     stderr = None, callback = None, callback_data = None,
+                     root = '/'):
     def chroot():
         os.chroot(root)
 
@@ -311,7 +312,8 @@ def execWithPulseProgress(command, argv, stdin = None, stdout = None,
 
         os.write(stdout, s)
         runningLog.write(s)
-        if progress: progress.pulse()
+        if callback:
+            callback(s, callback_data=callback_data)
 
         # break out early if the sub-process changes status.
         # no need to flush the stream if the process has exited
@@ -342,6 +344,16 @@ def execWithPulseProgress(command, argv, stdin = None, stdout = None,
 
     return 1
 
+def _pulseProgressCallback(data, callback_data=None):
+    if callback_data:
+        callback_data.pulse()
+
+def execWithPulseProgress(command, argv, stdin = None, stdout = None,
+                          stderr = None, progress = None, root = '/'):
+    execWithCallback(command, argv, stdin=stdin, stdout=stdout,
+                     stderr=stderr, callback=_pulseProgressCallback,
+                     callback_data=progress, root=root)
+
 ## Run a shell.
 def execConsole():
     try:
-- 
1.6.2.5

_______________________________________________
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