FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Ubuntu User

 
 
LinkBack Thread Tools
 
Old 11-28-2007, 10:05 PM
Jeremy Katz
 
Default 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
---
iutil.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++
1 files changed, 60 insertions(+), 0 deletions(-)

diff --git a/iutil.py b/iutil.py
index 926b0c6..f617487 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:
--
1.5.3.4

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

Thread Tools




All times are GMT. The time now is 08:23 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org