#!/usr/bin/env python
"""
    Monitors topics of PUB/SUB communication 

    Command Line:
    
        jld0sub connect_to topic [topic ...]

        where 'connect_to' is a socket address e.g. tcp://localhost:5555


    Example:
    
        jld0sub tcp://127.0.0.1:9002 test test1 test2
        

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

try:
    import jldzeromq
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 jldzeromq

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

DESC="SUBcribe to topic(s)"
DEFAULTS={
          }

def main():
    try:
        import jldzeromq.do_setup
        import logging
        import jldzeromq.do_checks
        
        parser=argparse.ArgumentParser(description=DESC, fromfile_prefix_chars='@')
        parser.add_argument('-ss', dest='sock_source',  type=str,  help="Address for socket", required=True)        
        parser.add_argument('-tp', dest='topics',       type=str, nargs='+', help="Topic(s) to subscribe to", default="")
        args=parser.parse_args()
        
        from jldzeromq.tools_sys import dnorm
        from jldzeromq.script_sub 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())
