Commit inicial
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Migrador y respaldador de cuentas IMAP.
|
||||
|
||||
Uso:
|
||||
python3 imap_migrate.py --aserver ... --auser ... --bserver ... --buser ...
|
||||
|
||||
Ejecutar --help para ver todos los parámetros disponibles.
|
||||
|
||||
Códigos de salida:
|
||||
0 = migración terminada correctamente
|
||||
1 = migración terminada con errores
|
||||
2 = error de parámetros
|
||||
3 = error de conexión
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import signal
|
||||
import sys
|
||||
|
||||
from config import parse_args
|
||||
from logger import setup_logging
|
||||
from migrator import Migrator
|
||||
|
||||
EXIT_OK = 0
|
||||
EXIT_WITH_ERRORS = 1
|
||||
EXIT_PARAM_ERROR = 2
|
||||
EXIT_CONNECTION_ERROR = 3
|
||||
|
||||
|
||||
def main(argv: list[str] | None = None) -> int:
|
||||
config = parse_args(argv)
|
||||
logger = setup_logging(config.log_dir, config.verbose)
|
||||
migrator = Migrator(config, logger)
|
||||
|
||||
def handle_sigint(signum, frame):
|
||||
logger.warning("CTRL+C recibido: terminando la operación actual y guardando el estado...")
|
||||
print("\nCTRL+C recibido, deteniendo de forma segura (esto puede tardar unos segundos)...")
|
||||
migrator.request_stop()
|
||||
|
||||
signal.signal(signal.SIGINT, handle_sigint)
|
||||
|
||||
try:
|
||||
return migrator.run()
|
||||
except Exception as exc: # salvaguarda ante fallos verdaderamente inesperados
|
||||
logger.exception(f"Error inesperado: {exc}")
|
||||
print(f"Error inesperado: {exc}", file=sys.stderr)
|
||||
return EXIT_WITH_ERRORS
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in New Issue
Block a user