Beremiz_service.py
changeset 1437 04177743b066
parent 1434 6e0cd0ceabb7
child 1438 19ebe96b41c0
equal deleted inserted replaced
1436:e15ca67197b9 1437:04177743b066
    34            -p        - port number default:3000
    34            -p        - port number default:3000
    35            -h        - print this help text and quit
    35            -h        - print this help text and quit
    36            -a        - autostart PLC (0:disable 1:enable) (default:0)
    36            -a        - autostart PLC (0:disable 1:enable) (default:0)
    37            -x        - enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1)
    37            -x        - enable/disable wxTaskbarIcon (0:disable 1:enable) (default:1)
    38            -t        - enable/disable Twisted web interface (0:disable 1:enable) (default:1)
    38            -t        - enable/disable Twisted web interface (0:disable 1:enable) (default:1)
       
    39            -e        - python extension (absolute path .py)
    39 
    40 
    40            working_dir - directory where are stored PLC files
    41            working_dir - directory where are stored PLC files
    41 """%sys.argv[0]
    42 """%sys.argv[0]
    42 
    43 
    43 try:
    44 try:
    44     opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:h")
    45     opts, argv = getopt.getopt(sys.argv[1:], "i:p:n:x:t:a:e:h")
    45 except getopt.GetoptError, err:
    46 except getopt.GetoptError, err:
    46     # print help information and exit:
    47     # print help information and exit:
    47     print str(err) # will print something like "option -a not recognized"
    48     print str(err) # will print something like "option -a not recognized"
    48     usage()
    49     usage()
    49     sys.exit(2)
    50     sys.exit(2)
    55 autostart = False
    56 autostart = False
    56 enablewx = True
    57 enablewx = True
    57 havewx = False
    58 havewx = False
    58 enabletwisted = True
    59 enabletwisted = True
    59 havetwisted = False
    60 havetwisted = False
       
    61 
       
    62 extensions=[]
    60 
    63 
    61 for o, a in opts:
    64 for o, a in opts:
    62     if o == "-h":
    65     if o == "-h":
    63         usage()
    66         usage()
    64         sys.exit()
    67         sys.exit()
    77         enablewx = int(a)
    80         enablewx = int(a)
    78     elif o == "-t":
    81     elif o == "-t":
    79         enabletwisted = int(a)
    82         enabletwisted = int(a)
    80     elif o == "-a":
    83     elif o == "-a":
    81         autostart = int(a)
    84         autostart = int(a)
       
    85     elif o == "-e":
       
    86         extensions.append(a)
    82     else:
    87     else:
    83         usage()
    88         usage()
    84         sys.exit()
    89         sys.exit()
    85 
    90 
    86 CWD = os.path.split(os.path.realpath(__file__))[0]
    91 CWD = os.path.split(os.path.realpath(__file__))[0]
   630                 sys.excepthook(*sys.exc_info())
   635                 sys.excepthook(*sys.exc_info())
   631         self.run = run_with_except_hook
   636         self.run = run_with_except_hook
   632     threading.Thread.__init__ = init
   637     threading.Thread.__init__ = init
   633 installThreadExcepthook()
   638 installThreadExcepthook()
   634 
   639 
       
   640 # Load extensions
       
   641 for extfilename in extensions:
       
   642     extension_folder = os.path.split(os.path.realpath(extfilename))[0]
       
   643     sys.path.append(extension_folder)
       
   644     execfile(extfilename, locals())
       
   645 
   635 if havetwisted or havewx:
   646 if havetwisted or havewx:
   636     pyro_thread=Thread(target=pyroserver.Loop)
   647     pyro_thread=Thread(target=pyroserver.Loop)
   637     pyro_thread.start()
   648     pyro_thread.start()
   638 
   649 
   639     if havetwisted:
   650     if havetwisted: