summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@vyos.io>2021-03-30 22:12:17 +0700
committerGitHub <noreply@github.com>2021-03-30 22:12:17 +0700
commit62369cef4df5a5e781b42e38ef15231b4f5c0f0d (patch)
tree77cc679f0e4c370873c155a4dae8d23b68080bf9 /src/helpers
parent0c13a4fa454926f9891450b12ffc34ef7c54d523 (diff)
parenta32d5e824df9e16d4e6c9198f093fd9f1baffcc6 (diff)
downloadvyos-1x-62369cef4df5a5e781b42e38ef15231b4f5c0f0d.tar.gz
vyos-1x-62369cef4df5a5e781b42e38ef15231b4f5c0f0d.zip
Merge pull request #794 from erkin/current
T3354: Handle user break and prematurely closed stdin in strip-private
Diffstat (limited to 'src/helpers')
-rwxr-xr-xsrc/helpers/strip-private.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/helpers/strip-private.py b/src/helpers/strip-private.py
index 023298eec..420a039eb 100755
--- a/src/helpers/strip-private.py
+++ b/src/helpers/strip-private.py
@@ -79,13 +79,18 @@ def strip_lines(rules: tuple) -> None:
"""
Read stdin line by line and apply the given stripping rules.
"""
- for line in sys.stdin:
- if not args.keep_address:
- line = strip_address(line)
- for (condition, regexp, subst) in rules:
- if condition:
- line = regexp.sub(subst, line)
- print(line, end='')
+ try:
+ for line in sys.stdin:
+ if not args.keep_address:
+ line = strip_address(line)
+ for (condition, regexp, subst) in rules:
+ if condition:
+ line = regexp.sub(subst, line)
+ print(line, end='')
+ # stdin can be cut for any reason, such as user interrupt or the pager terminating before the text can be read.
+ # All we can do is gracefully exit.
+ except (BrokenPipeError, EOFError, KeyboardInterrupt):
+ sys.exit(1)
if __name__ == "__main__":
args = parser.parse_args()