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