-
Notifications
You must be signed in to change notification settings - Fork 0
/
__main__.py
executable file
·63 lines (51 loc) · 1.89 KB
/
__main__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!venv/bin/python
"""Código para la gestionar el acceso a un recinto.
El sistema leera una tarjeta RFID, la cotejará con el sistema central, mandando la id de la tarjeta mediante Zigbee
Si la respuesta es afirmativa, abrirá la cerradura de la puerta representada con un serbo, y pintará el LED verde, en
caso contrário, pintará el led rojo"""
# Gestionamos el tipo de ejecución que se va a realizar
import argparse
# Cargamos la configuración
import logging
import sys
import config
from watchDog.watchDog import WatchDog
def get_parser():
"""
Creates a new argument parser.
"""
parser = argparse.ArgumentParser()
parser.add_argument('-R', '--remote', dest="remote",
help="Defino que tipo de ejecución se va a realizar, remota o local, True o False, "
"respectivamente",
default=config.remote)
return parser
logger = logging.getLogger(__name__)
logger.setLevel(config.log_level)
logger.addHandler(config.warn_file_handler)
logger.addHandler(config.log.StreamHandler())
def main(args=None):
"""
Main entry point for your project.
Args:
args : list
A of arguments as if they were input in the command line. Leave it
None to use sys.argv.
"""
assert (config.env is not None), "No se ha podido recuperar la información de configuración"
parser = get_parser()
args = parser.parse_args(args)
stapleton = WatchDog(remote=config.remote, logger=logger)
stapleton.wake_up()
if __name__ == "__main__":
try:
logger.info("Starting the program")
main()
logger.info("Ejecución finalizada")
sys.exit(0)
except KeyboardInterrupt:
logger.warning("Proceso abortado por el usuario")
sys.exit(0)
except Exception as e:
logger.error("Algo no fue como se esperaba:\n{}".format(e))
sys.exit(1)