Commit aaf6e9a0 authored by segfault's avatar segfault Committed by intrigeri
Browse files

Minor improvements / nitpicking

- Use argparse's "required" parameter instead of checking if the
  argument is None.
- Drop stream parameter from logging.basicConfig because sys.stderr is used by
  default.
- Don't catch exceptions only for printing them to stderr and exiting
  with exit code 1, because that is exactly what happens if an exception
  is not caught.
- Don't use sys.exit(main()) with a main function that doesn't return
  anything.

Clarification wrt. "Don't catch exceptions only for printing them […]": the
behavior _is_ different in that before this commit, we would hide the resulting
stacktrace. But there's no situation in which we expect main() to raise an
exception here, so IMO hiding exceptions was a bug. Thank you for fixing
it :) -- intrigeri
parent e5e98537
......@@ -19,8 +19,8 @@ def main():
description="Copy IUKs from Jenkins to our rsync server \
and verify that they match those built locally"
)
parser.add_argument("--hashes-file", type=str, action="store")
parser.add_argument("--jenkins-build-id", type=int, action="store")
parser.add_argument("--hashes-file", type=str, action="store", required=True)
parser.add_argument("--jenkins-build-id", type=int, action="store", required=True)
parser.add_argument("-q", "--quiet", action="store_true",
help="quiet output")
parser.add_argument("--debug", action="store_true", help="debug output")
......@@ -31,22 +31,11 @@ def main():
args = parser.parse_args()
if args.debug:
logging.basicConfig(level=logging.DEBUG, stream=sys.stderr,
format=LOG_FORMAT)
logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
elif args.quiet:
logging.basicConfig(level=logging.WARN, stream=sys.stderr,
format=LOG_FORMAT)
logging.basicConfig(level=logging.WARN, format=LOG_FORMAT)
else:
logging.basicConfig(level=logging.INFO, stream=sys.stderr,
format=LOG_FORMAT)
if args.hashes_file is None:
log.error("Please pass --hashes-file")
sys.exit(1)
if args.jenkins_build_id is None:
log.error("Please pass --jenkins-build-id")
sys.exit(1)
logging.basicConfig(level=logging.INFO, format=LOG_FORMAT)
if not Path(args.hashes_file).exists():
log.error("%s does not exist" % (args.hashes_file))
......@@ -127,8 +116,4 @@ def verify_iuks(desthost: str, hashes_file: str) -> None:
if __name__ == "__main__":
try:
sys.exit(main())
except Exception as e:
print(e, file=sys.stderr)
sys.exit(1)
main()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment