#!/usr/bin/env python
"""
    jldinotify - path change notification over json/stdout

    @author: Jean-Lou Dupont
"""
import os, sys, argparse
op=os.path

try:
    import jlddk
except:
    ### must be in dev mode then    
    this_dir=op.dirname(__file__)
    lib_path=op.abspath(op.join(this_dir, ".."))
    sys.path.insert(0, lib_path)
    import jlddk

########################################################################

DESC="Path change notification over JSON/stdout"
DEFAULTS={
          }

def main():
    try:
        import jlddk.do_setup
        import logging
        import jlddk.do_checks
        from jlddk.tools_sys import info_dump, dnorm
        
        parser=argparse.ArgumentParser(description=DESC, fromfile_prefix_chars='@')
        parser.add_argument('-sp',  dest='path_source',  type=str, help="Source path", required=True)
        
        parser.add_argument('-lc',  dest="logconfig", type=str,  help="Logging configuration file")
        parser.add_argument('-ll',  dest="loglevel",  type=str,  help="Logging Level", choices=["debug", "info", "warning", "error"], default="info")        
                
        args=parser.parse_args()
        
        info_dump(vars(args), 20)
        
        from jlddk.script_inotify import run
        run(**dnorm(vars(args)))

    except KeyboardInterrupt:
        logging.info("..Exiting")
        sys.exit(0)##no probs
        
    except Exception,e:
        logging.error(str(e))
        sys.exit(1)
        
sys.exit(main())
