yacron2 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
yacron2/__init__.py ADDED
File without changes
yacron2/__main__.py ADDED
@@ -0,0 +1,80 @@
1
+ import argparse
2
+ import asyncio
3
+ import asyncio.subprocess
4
+ import logging
5
+ import os
6
+ import signal
7
+ import sys
8
+
9
+ import yacron2.version
10
+ from yacron2.cron import ConfigError, Cron
11
+
12
+ CONFIG_DEFAULT = "/etc/yacron2.d"
13
+
14
+
15
+ def main_loop(loop):
16
+ parser = argparse.ArgumentParser(prog="yacron2")
17
+ parser.add_argument(
18
+ "-c",
19
+ "--config",
20
+ default=CONFIG_DEFAULT,
21
+ metavar="FILE-OR-DIR",
22
+ help="configuration file, or directory containing configuration files",
23
+ )
24
+ parser.add_argument("-l", "--log-level", default="INFO")
25
+ parser.add_argument(
26
+ "-v", "--validate-config", default=False, action="store_true"
27
+ )
28
+ parser.add_argument("--version", default=False, action="store_true")
29
+ args = parser.parse_args()
30
+
31
+ logging.basicConfig(level=getattr(logging, args.log_level))
32
+ # logging.getLogger("asyncio").setLevel(logging.WARNING)
33
+ logger = logging.getLogger("yacron2")
34
+
35
+ if args.version:
36
+ print(yacron2.version.version)
37
+ sys.exit(0)
38
+
39
+ if args.config == CONFIG_DEFAULT and not os.path.exists(args.config):
40
+ print(
41
+ "yacron2 error: configuration file not found, please provide one "
42
+ "with the --config option",
43
+ file=sys.stderr,
44
+ )
45
+ parser.print_help(sys.stderr)
46
+ sys.exit(1)
47
+
48
+ try:
49
+ cron = Cron(args.config)
50
+ except ConfigError as err:
51
+ logger.error("Configuration error: %s", str(err))
52
+ sys.exit(1)
53
+
54
+ if args.validate_config:
55
+ logger.info("Configuration is valid.")
56
+ sys.exit(0)
57
+
58
+ loop.add_signal_handler(signal.SIGINT, cron.signal_shutdown)
59
+ loop.add_signal_handler(signal.SIGTERM, cron.signal_shutdown)
60
+ try:
61
+ loop.run_until_complete(cron.run())
62
+ finally:
63
+ loop.remove_signal_handler(signal.SIGINT)
64
+ loop.remove_signal_handler(signal.SIGTERM)
65
+
66
+
67
+ def main(): # pragma: no cover
68
+ if sys.platform == "win32":
69
+ _loop = asyncio.ProactorEventLoop()
70
+ asyncio.set_event_loop(_loop)
71
+ else:
72
+ _loop = asyncio.new_event_loop()
73
+ try:
74
+ main_loop(_loop)
75
+ finally:
76
+ _loop.close()
77
+
78
+
79
+ if __name__ == "__main__": # pragma: no cover
80
+ main()