in export/securedrop_export/main.py [0:0]
def entrypoint():
"""
Entrypoint method (Note: a method is required for setuptools).
Configure logging, extract tarball, and run desired export service,
exiting with return code 0.
Non-zero exit values will cause the system to try alternative
solutions for mimetype handling, which we want to avoid.
The program is called with the archive name as the first argument.
"""
status, archive = None, None
try:
_configure_logging()
logger.info(f"Starting SecureDrop Export {__version__}")
data_path = sys.argv[1]
# Halt if target file is absent
if not os.path.exists(data_path):
logger.error("Archive not found at provided path.")
logger.debug(f"Archive missing, path: {data_path}")
status = Status.ERROR_FILE_NOT_FOUND
else:
logger.debug("Extract tarball")
archive = Archive(data_path).extract_tarball()
logger.debug("Validate metadata")
metadata = Metadata(archive.tmpdir).validate()
logger.info("Archive extraction and metadata validation successful")
# If all we're doing is starting the vm, we're done; otherwise,
# run the appropriate print or export routine
if metadata.command is not Command.START_VM:
archive.set_metadata(metadata)
logger.info(f"Start {metadata.command.value} service")
status = _start_service(archive)
logger.info(f"Status: {status.value}")
# A nonzero exit status will cause other programs
# to try to handle the files, which we don't want.
except Exception as ex:
logger.error(ex)
if isinstance(ex, ExportException):
logger.error(f"Encountered exception {ex.sdstatus.value}, exiting")
status = ex.sdstatus
else:
logger.error("Encountered exception during export, exiting")
status = Status.ERROR_GENERIC
finally:
_exit_gracefully(archive, status)