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,17 +72,22 @@ class FancyDiffer:
|
|||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def diff_files (f1, f2, colors=Colors.Null):
|
def diff_files (f1, f2, colors=Colors.Null):
|
||||||
for (l1,l2) in zip (f1, f2):
|
try:
|
||||||
if l1 == l2:
|
for (l1,l2) in zip (f1, f2):
|
||||||
sys.stdout.writelines ([" ", l1])
|
if l1 == l2:
|
||||||
continue
|
sys.stdout.writelines ([" ", l1])
|
||||||
|
continue
|
||||||
|
|
||||||
sys.stdout.writelines (FancyDiffer.diff_lines (l1, l2, colors))
|
sys.stdout.writelines (FancyDiffer.diff_lines (l1, l2, colors))
|
||||||
# print out residues
|
# print out residues
|
||||||
for l in f1:
|
for l in f1:
|
||||||
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)
|
||||||
|
|
||||||
for s in sys.argv[1:]:
|
try:
|
||||||
callback (FileHelpers.open_file_or_stdin (s))
|
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
|
@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)
|
||||||
|
|
||||||
for s in sys.argv[1:]:
|
try:
|
||||||
callback (s)
|
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
|
@staticmethod
|
||||||
def filter_multiple_strings_or_stdin (callback, mnemonic, \
|
def filter_multiple_strings_or_stdin (callback, mnemonic, \
|
||||||
@ -135,18 +150,23 @@ class UtilMains:
|
|||||||
% (sys.argv[0], mnemonic, sys.argv[0])
|
% (sys.argv[0], mnemonic, sys.argv[0])
|
||||||
sys.exit (1)
|
sys.exit (1)
|
||||||
|
|
||||||
if '--stdin' in sys.argv:
|
try:
|
||||||
sys.argv.remove ('--stdin')
|
if '--stdin' in sys.argv:
|
||||||
while (1):
|
sys.argv.remove ('--stdin')
|
||||||
line = sys.stdin.readline ()
|
while (1):
|
||||||
if not len (line):
|
line = sys.stdin.readline ()
|
||||||
break
|
if not len (line):
|
||||||
print callback (line)
|
break
|
||||||
else:
|
print callback (line)
|
||||||
args = sys.argv[1:]
|
else:
|
||||||
if concat_separator != False:
|
args = sys.argv[1:]
|
||||||
args = [concat_separator.join (args)]
|
if concat_separator != False:
|
||||||
print separator.join (callback (x) for x in (args))
|
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:
|
class Unicode:
|
||||||
|
Loading…
Reference in New Issue
Block a user