From 2c38d6b11567a1ab1a88259049414843b7e0a104 Mon Sep 17 00:00:00 2001 From: Enji Cooper Date: Thu, 26 Mar 2020 17:13:14 -0700 Subject: [PATCH] Resolve variable name issues per PEP8 Move all logic under `if __name__ == "__main__"` to a `main(..)` function. The purpose of this is to not only address flake8/pylint reported issues with variable names, but also to enable testing of the function in isolation to ensure the logic acts as desired. Signed-off-by: Enji Cooper --- event_rpcgen.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/event_rpcgen.py b/event_rpcgen.py index c6ddc2a6..c2122292 100755 --- a/event_rpcgen.py +++ b/event_rpcgen.py @@ -1711,21 +1711,22 @@ class CommandLine: entry.PrintCode(impl_fp) impl_fp.close() -if __name__ == '__main__': - try: - CommandLine(sys.argv).run() - sys.exit(0) +def main(argv=None): + try: + CommandLine(argv).run() + return 0 except RpcGenError as e: sys.stderr.write(e) - sys.exit(1) - except EnvironmentError as e: if e.filename and e.strerror: sys.stderr.write("%s: %s" % (e.filename, e.strerror)) - sys.exit(1) elif e.strerror: sys.stderr.write(e.strerror) - sys.exit(1) else: raise + return 1 + + +if __name__ == "__main__": + sys.exit(main(argv=sys.argv))