~yerinalexey/pcrond

808ffd39738ef5fd5fa51c04aded566d70bd7cf1 — Luca Vercelli 2 years ago e5d2ee5
cli arguments
2 files changed, 28 insertions(+), 10 deletions(-)

M README.rst
M scripts/pcrond.py
M README.rst => README.rst +1 -1
@@ 33,7 33,7 @@ Usage
.. code-block:: bash

    $ ./setup.py install --prefix=~/.local
    $ pcrond.py path/to/my/crontab/file
    $ pcrond.py -r path/to/my/crontab/file
    
(this assumes that ``~/.local/bin`` is in the PATH)


M scripts/pcrond.py => scripts/pcrond.py +27 -9
@@ 1,21 1,39 @@
#!/usr/bin/env python

from pcrond import scheduler

crontab_filename = None
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('filename', help='the crontab file')
    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

    global crontab_filename
    crontab_filename = args.filename

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__":
    parse_args()
    scheduler.load_crontab_file(crontab_filename)
    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()