summaryrefslogtreecommitdiffstats
path: root/iutil.py
diff options
context:
space:
mode:
authorJeremy Katz <katzj@redhat.com>2007-11-28 12:33:17 -0500
committerJeremy Katz <katzj@redhat.com>2007-11-29 16:12:01 -0500
commit6b890e2d83b8f15abf697a3d5bb0a321dad47b44 (patch)
tree3bf17a41a612fb2c5ba4e544de13caff27a85365 /iutil.py
parent506e264879a586c2ec390ae489c900fa5b1cedba (diff)
downloadanaconda-6b890e2d83b8f15abf697a3d5bb0a321dad47b44.tar.gz
anaconda-6b890e2d83b8f15abf697a3d5bb0a321dad47b44.tar.xz
anaconda-6b890e2d83b8f15abf697a3d5bb0a321dad47b44.zip
add iutil.execWithPulseProgress to do a pulsing progress bar
this is helpful for operations like filesystem checking and resizing when we don't have a good way to do a nice bounded progress bar
Diffstat (limited to 'iutil.py')
-rw-r--r--iutil.py60
1 files changed, 60 insertions, 0 deletions
diff --git a/iutil.py b/iutil.py
index 926b0c612..f6174879f 100644
--- a/iutil.py
+++ b/iutil.py
@@ -96,6 +96,66 @@ def execWithCapture(command, argv, stdin = 0, stderr = 2, root='/'):
pipe.wait()
return rc
+def execWithPulseProgress(command, argv, stdin = 0, stdout = 1, stderr = 2,
+ progress = None, root = '/'):
+ def chroot():
+ os.chroot(root)
+
+ argv = list(argv)
+ if type(stdin) == type("string"):
+ if os.access(stdin, os.R_OK):
+ stdin = open(stdin)
+ else:
+ stdin = 0
+ if type(stdout) == type("string"):
+ stdout = open(stdout, "w")
+ if type(stderr) == type("string"):
+ stderr = open(stderr, "w")
+
+ p = os.pipe()
+ childpid = os.fork()
+ if not childpid:
+ os.close(p[0])
+ os.dup2(p[1], 1)
+ os.dup2(stderr.fileno(), 2)
+ os.close(p[1])
+ stderr.close()
+
+ os.execvp(command, [command] + argv)
+ os._exit(1)
+
+ os.close(p[1])
+
+ while 1:
+ try:
+ s = os.read(p[0], 1)
+ except OSError, args:
+ (num, str) = args
+ if (num != 4):
+ raise IOError, args
+
+ stdout.write(s)
+ if progress: progress.pulse()
+
+ if len(s) < 1:
+ break
+
+ try:
+ (pid, status) = os.waitpid(childpid, 0)
+ except OSError, (num, msg):
+ log.critical("exception from waitpid: %s %s" %(num, msg))
+
+ progress and progress.pop()
+
+ # *shrug* no clue why this would happen, but hope that things are fine
+ if status is None:
+ return 0
+
+ if os.WIFEXITED(status):
+ return os.WEXITSTATUS(status)
+
+ return 1
+
## Run a shell.
def execConsole():
try: