This change fixes an exception that occurs if the user specifies
an outputfile in a non-existing directory. Also catch several other
related exceptions.
Fixes#9522.
We can't initialize Sentry during module initialization because our
`initialize_sentry` logs some status info. Setting the logging level
later on is then a no-op, breaking verbose and very-verbose logging.
This change fixes this by putting Sentry initialization into a
separate method that gets called after we set the log level.
Also refactor some common code into methods that appear in all our
executables.
This change imports `os` instead of `os.path`. This is the
recommended way. It also reduces confusion whether to use
`os.path.whatever()` or just `path.whatever()`.