~yerinalexey/pcrond

ref: 7a7d0e89498b8135667d4dee9af0e097be50ac9c pcrond/scripts/pcrond -rwxr-xr-x 1.5 KiB
7a7d0e89 — Alexey Yerin fix: remove .py from scripts/pcrond 6 months ago
                                                                                
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
#!/usr/bin/env python

import logging

VERSION = "1.0"
logger = logging.getLogger()


def parse_args():
    import argparse
    parser = argparse.ArgumentParser(description='Launch a crond-like daemon in userspace.')
    parser.add_argument('-r', '--crontabfile',
                        help='the crontab file (default ~/.local/crontab)',
                        default='~/.local/crontab')
    parser.add_argument('-l', '--logfile',
                        help='the log file (default ~/.local/pcrond.log)',
                        default='~/.local/pcrond.log')
    parser.add_argument('-v', '--version', action='store_true', help='print version then exit')
    parser.add_argument('-x', '--debug', action='store_true', help='enable debug logging')
    args = parser.parse_args()
    return args


def setup_logger(args):             # HOPE this affects modules too
    logginglevel = logging.DEBUG if args.debug else logging.INFO
    handler = logging.handlers.RotatingFileHandler(filename=args.logfile,
                                                   level=logginglevel,
                                                   maxBytes=2000,
                                                   backupCount=10)
    logger.addHandler(handler)


if __name__ == "__main__":
    args = parse_args()
    if args.version:
        print(VERSION)
        exit(0)
    setup_logger(args)

    from pcrond import scheduler
    scheduler.load_crontab_file(args.crontabfile)
    scheduler.main_loop()