Ignore Broken Pipe errors
This commit is contained in:
parent
d530024168
commit
3a34e9e351
|
@ -1,6 +1,6 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
import sys, os, re, difflib, unicodedata
|
||||
import sys, os, re, difflib, unicodedata, errno
|
||||
|
||||
class Colors:
|
||||
class Null:
|
||||
|
@ -72,6 +72,7 @@ class FancyDiffer:
|
|||
|
||||
@staticmethod
|
||||
def diff_files (f1, f2, colors=Colors.Null):
|
||||
try:
|
||||
for (l1,l2) in zip (f1, f2):
|
||||
if l1 == l2:
|
||||
sys.stdout.writelines ([" ", l1])
|
||||
|
@ -83,6 +84,10 @@ class FancyDiffer:
|
|||
sys.stdout.writelines (["-", colors.red, l1, colors.end])
|
||||
for l in f1:
|
||||
sys.stdout.writelines (["-", colors.green, l1, colors.end])
|
||||
except IOError as e:
|
||||
if e.errno != errno.EPIPE:
|
||||
print >> sys.stderr, "%s: %s" (sys.argv[0], e.strerror)
|
||||
sys.exit (1)
|
||||
|
||||
|
||||
class DiffFilters:
|
||||
|
@ -112,8 +117,13 @@ class UtilMains:
|
|||
print "Usage: %s %s..." % (sys.argv[0], mnemonic)
|
||||
sys.exit (1)
|
||||
|
||||
try:
|
||||
for s in sys.argv[1:]:
|
||||
callback (FileHelpers.open_file_or_stdin (s))
|
||||
except IOError as e:
|
||||
if e.errno != errno.EPIPE:
|
||||
print >> sys.stderr, "%s: %s" (sys.argv[0], e.strerror)
|
||||
sys.exit (1)
|
||||
|
||||
@staticmethod
|
||||
def process_multiple_args (callback, mnemonic):
|
||||
|
@ -122,8 +132,13 @@ class UtilMains:
|
|||
print "Usage: %s %s..." % (sys.argv[0], mnemonic)
|
||||
sys.exit (1)
|
||||
|
||||
try:
|
||||
for s in sys.argv[1:]:
|
||||
callback (s)
|
||||
except IOError as e:
|
||||
if e.errno != errno.EPIPE:
|
||||
print >> sys.stderr, "%s: %s" (sys.argv[0], e.strerror)
|
||||
sys.exit (1)
|
||||
|
||||
@staticmethod
|
||||
def filter_multiple_strings_or_stdin (callback, mnemonic, \
|
||||
|
@ -135,6 +150,7 @@ class UtilMains:
|
|||
% (sys.argv[0], mnemonic, sys.argv[0])
|
||||
sys.exit (1)
|
||||
|
||||
try:
|
||||
if '--stdin' in sys.argv:
|
||||
sys.argv.remove ('--stdin')
|
||||
while (1):
|
||||
|
@ -147,6 +163,10 @@ class UtilMains:
|
|||
if concat_separator != False:
|
||||
args = [concat_separator.join (args)]
|
||||
print separator.join (callback (x) for x in (args))
|
||||
except IOError as e:
|
||||
if e.errno != errno.EPIPE:
|
||||
print >> sys.stderr, "%s: %s" (sys.argv[0], e.strerror)
|
||||
sys.exit (1)
|
||||
|
||||
|
||||
class Unicode:
|
||||
|
|
Loading…
Reference in New Issue