]> granicus.if.org Git - python/commitdiff
During display, if EPIPE is raised, it's probably because a pager was
authorFred Drake <fdrake@acm.org>
Fri, 26 Mar 1999 22:36:00 +0000 (22:36 +0000)
committerFred Drake <fdrake@acm.org>
Fri, 26 Mar 1999 22:36:00 +0000 (22:36 +0000)
killed.  Discard the error in that case, but propogate it otherwise.

Tools/scripts/dutree.py

index 3098f2b6210d036dcfe92fceda129a09ba834325..5912382a215fa1f2d087bb4f74a2d23b7551b738 100755 (executable)
@@ -1,7 +1,7 @@
 #! /usr/bin/env python
 # Format du output in a tree shape
 
-import os, string, sys
+import os, string, sys, errno
 
 def main():
        p = os.popen('du ' + string.join(sys.argv[1:]), 'r')
@@ -16,7 +16,11 @@ def main():
                if comps[0] == '': comps[0] = '/'
                if comps[len(comps)-1] == '': del comps[len(comps)-1]
                total, d = store(size, comps, total, d)
-       display(total, d)
+       try:
+               display(total, d)
+       except IOError, e:
+               if e.errno != errno.EPIPE:
+                       raise
 
 def store(size, comps, total, d):
        if comps == []:
@@ -52,4 +56,5 @@ def show(total, d, prefix):
                if d.has_key(key):
                        show(tsub, d[key][1], psub)
 
-main()
+if __name__ == "__main__":
+       main()