You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-10-23 21:28:56 +03:00
A ctrl-c raised KeyboardInterrupt out of main() and python printed the traceback, which is the whole path from main() down to the select() the harness happened to be waiting in and says nothing about a run that was stopped on purpose. Catch it and log "terminated on signal SIGINT" as the C does, exiting with the status the C exits with for TermError. An unexpected exception is a bug in the tool so the trace is what gets it fixed, but the trace ends with the message that says what went wrong, which is where the message gets lost. Show the message first and keep only the innermost frames, since the frames above them are the path from main() into the tool and are much the same for every error. The frame count says how many were dropped and how to get them, and the complete trace, which is what python printed before, is shown at debug level the same way the C shows a stack trace only at debug level. The rendering is error_trace() in common/error.py, beside ToolError, so every tool reports a bug in itself the same way. The CI wrapper asks for the complete trace since a run there cannot be repeated at debug level to get it, and the code builder handles the interrupt but not the trace since it has no log level to raise.
72 lines
2.7 KiB
Python
Executable File
72 lines
2.7 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""pgBackRest Documentation Builder.
|
|
|
|
Builds the documentation and renders it. The reference documents, the user guide, the release notes, and the manual page all come from
|
|
the same declarations the binary is generated from, so the documentation describes what the code does.
|
|
|
|
Exit status: 0 = success, greater = error."""
|
|
|
|
####################################################################################################################################
|
|
import os
|
|
import signal
|
|
import sys
|
|
|
|
# Do not cache bytecode. The tool runs from the source tree, where a __pycache__ would show up as an unexpected binary file in the
|
|
# linter and in the distribution. This must be set before the library modules are imported below.
|
|
sys.dont_write_bytecode = True
|
|
|
|
# Each tool keeps its library beside itself and may use the libraries below it in the hierarchy. Insert them first, lowest last, so the
|
|
# doc modules are found before anything else on the path.
|
|
for lib in ("build", "doc"):
|
|
sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), lib, "lib"))
|
|
|
|
from command.doc import cfg_load, cmd_doc # noqa: E402
|
|
from common.error import EXIT_ERROR, EXIT_TERM, ToolError, error_trace # noqa: E402
|
|
from common.log import * # noqa: E402
|
|
|
|
|
|
####################################################################################################################################
|
|
def main():
|
|
"""Build the documentation."""
|
|
|
|
# Die silently on SIGPIPE as C programs do, rather than raising when output is piped to a command that exits early
|
|
signal.signal(signal.SIGPIPE, signal.SIG_DFL)
|
|
|
|
path_repo = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
|
|
# Load the configuration. Logging is not initialized until this succeeds so print any error directly.
|
|
try:
|
|
config = cfg_load(sys.argv[1:], path_repo)
|
|
except ToolError as error:
|
|
print(error)
|
|
|
|
return EXIT_ERROR
|
|
|
|
log_init(config.log_level, config.log_timestamp)
|
|
log(INFO, "build documentation")
|
|
|
|
try:
|
|
cmd_doc(config)
|
|
except KeyboardInterrupt:
|
|
# A ctrl-c is what was asked for, so report it the way the C reports a signal rather than as a stack trace
|
|
log(ERROR, "terminated on signal SIGINT")
|
|
|
|
return EXIT_TERM
|
|
except ToolError as error:
|
|
log(ERROR, error)
|
|
|
|
return error.status
|
|
except Exception as error:
|
|
# An unexpected exception is a bug here rather than a problem with the documentation, so show the stack trace
|
|
log(ERROR, error_trace(error, config.log_level >= DEBUG))
|
|
|
|
return EXIT_ERROR
|
|
|
|
log(INFO, "build documentation end: completed successfully")
|
|
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|