コード例 #1
0
ファイル: app.py プロジェクト: cheewee2000/LasaurApp
def run_with_callback(host):
    """ Start a wsgiref server instance with control over the main loop.
        This is a function that I derived from the bottle.py run()
    """
    handler = default_app()
    server = wsgiref.simple_server.make_server(host, NETWORK_PORT, handler)
    server.timeout = 0.01
    server.quiet = True
    print "-----------------------------------------------------------------------------"
    print "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: "
    print "http://%s:%d/      (local)" % ("127.0.0.1", NETWORK_PORT)
    if host == "":
        print "http://%s:%d/   (public)" % (socket.gethostbyname(socket.gethostname()), NETWORK_PORT)
    print "Use Ctrl-C to quit."
    print "-----------------------------------------------------------------------------"
    print
    try:
        webbrowser.open_new_tab("http://127.0.0.1:" + str(NETWORK_PORT))
    except webbrowser.Error:
        print "Cannot open Webbrowser, please do so manually."
    sys.stdout.flush()  # make sure everything gets flushed
    while 1:
        try:
            SerialManager.send_queue_as_ready()
            server.handle_request()
        except KeyboardInterrupt:
            break
    print "\nShutting down..."
    SerialManager.close()
コード例 #2
0
ファイル: app.py プロジェクト: darthrake/LasaurApp
def run_with_callback(host, port=4444, timeout=0.01):
    """ Start a wsgiref server instance with control over the main loop.
        This is a function that I derived from the bottle.py run()
    """
    handler = default_app()
    server = wsgiref.simple_server.make_server(host, port, handler)
    server.timeout = timeout
    print "-----------------------------------------------------------------------------"
    print "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: "    
    print "http://%s:%d/      (local)" % ('127.0.0.1', port)    
    if host == '':
        print "http://%s:%d/   (public)" % (socket.gethostbyname(socket.gethostname()), port)
    print "Use Ctrl-C to quit."
    print "-----------------------------------------------------------------------------"    
    print
    while 1:
        try:
            SerialManager.send_queue_as_ready()
            server.handle_request()
        except KeyboardInterrupt:
            break
    print "\nShutting down..."
    SerialManager.close()
コード例 #3
0
ファイル: app.py プロジェクト: bullestock/LasaurApp
def run_with_callback(host, port, rfidreader, logger, powertimer):
    """ Start a wsgiref server instance with control over the main loop.
        This is a function that I derived from the bottle.py run()
    """
    debug(True)
    handler = default_app()
    handler.catchall = False
    handler.rfidreader = rfidreader
    handler.logger = logger
    handler.powertimer = powertimer
    server = make_server(host, port, handler, handler_class=HackedWSGIRequestHandler)
    server.timeout = 0.01
    #server.quiet = True
    print "Persistent storage root is: " + storage_dir()
    print "-----------------------------------------------------------------------------"
    print "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: "
    print "http://%s:%d/      (local)" % ('127.0.0.1', port)
    # if host == '':
    #     try:
    #         print "http://%s:%d/   (public)" % (socket.gethostbyname(socket.gethostname()), port)
    #     except socket.gaierror:
    #         # print "http://beaglebone.local:4444/      (public)"
    #         pass
    print "Use Ctrl-C to quit."
    print "-----------------------------------------------------------------------------"
    print
    # auto-connect on startup
    global SERIAL_PORT
    if not SERIAL_PORT:
        SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND)
    SerialManager.connect(SERIAL_PORT, BITSPERSECOND)
    # open web-browser
    try:
        webbrowser.open_new_tab('http://127.0.0.1:'+str(port))
        pass
    except webbrowser.Error:
        print "Cannot open Webbrowser, please do so manually."
    sys.stdout.flush()  # make sure everything gets flushed
    server.timeout = 0
    while 1:
        try:
            SerialManager.send_queue_as_ready()
            server.handle_request()
            time.sleep(0.0004)
        except KeyboardInterrupt:
            break
    print "\nShutting down..."
    SerialManager.close()
コード例 #4
0
def run_with_callback(host, port):
    """ Start a wsgiref server instance with control over the main loop.
        This is a function that I derived from the bottle.py run()
    """
    handler = default_app()
    server = make_server(host,
                         port,
                         handler,
                         handler_class=HackedWSGIRequestHandler)
    server.timeout = 0.01
    server.quiet = True
    print "Persistent storage root is: " + storage_dir()
    print "-----------------------------------------------------------------------------"
    print "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: "
    print "http://%s:%d/      (local)" % ('127.0.0.1', port)
    # if host == '':
    #     try:
    #         print "http://%s:%d/   (public)" % (socket.gethostbyname(socket.gethostname()), port)
    #     except socket.gaierror:
    #         # print "http://beaglebone.local:4444/      (public)"
    #         pass
    print "Use Ctrl-C to quit."
    print "-----------------------------------------------------------------------------"
    print
    # auto-connect on startup
    global SERIAL_PORT
    if not SERIAL_PORT:
        SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND)
    SerialManager.connect(SERIAL_PORT, BITSPERSECOND)
    # open web-browser
    try:
        webbrowser.open_new_tab('http://127.0.0.1:' + str(port))
        pass
    except webbrowser.Error:
        print "Cannot open Webbrowser, please do so manually."
    sys.stdout.flush()  # make sure everything gets flushed
    server.timeout = 0
    while 1:
        try:
            SerialManager.send_queue_as_ready()
            server.handle_request()
            time.sleep(0.0004)
        except KeyboardInterrupt:
            break
    print "\nShutting down..."
    SerialManager.close()
コード例 #5
0
def run_with_callback(host):
    """ Start a wsgiref server instance with control over the main loop.
        This is a function that I derived from the bottle.py run()
    """
    handler = default_app()
    server = wsgiref.simple_server.make_server(host, NETWORK_PORT, handler)
    server.timeout = 0.01
    server.quiet = True
    print "-----------------------------------------------------------------------------"
    print "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: "
    print "http://%s:%d/      (local)" % ('127.0.0.1', NETWORK_PORT)
    if host == '':
        try:
            print "http://%s:%d/   (public)" % (socket.gethostbyname(
                socket.gethostname()), NETWORK_PORT)
        except socket.gaierror:
            # print "http://beaglebone.local:4444/      (public)"
            pass
    print "Use Ctrl-C to quit."
    print "-----------------------------------------------------------------------------"
    print
    try:
        webbrowser.open_new_tab('http://127.0.0.1:' + str(NETWORK_PORT))
        pass
    except webbrowser.Error:
        print "Cannot open Webbrowser, please do so manually."
    sys.stdout.flush()  # make sure everything gets flushed
    while 1:
        try:
            SerialManager.send_queue_as_ready()
            server.handle_request()
        except KeyboardInterrupt:
            break
    print "\nShutting down..."
    SerialManager.close()
コード例 #6
0
ファイル: app.py プロジェクト: mnakada/SmartLaserCO2
def run_with_callback(host, port):
    """ Start a wsgiref server instance with control over the main loop.
        This is a function that I derived from the bottle.py run()
    """
    handler = default_app()
    server = make_server(host, port, handler, handler_class=HackedWSGIRequestHandler)
    if CERTSDIR:
      server.socket = ssl.wrap_socket(server.socket,
        keyfile=KEYFILE,
        certfile=CERTSFILE,
        server_side=True,
        cert_reqs=ssl.CERT_REQUIRED,
        ca_certs=CA_CERTSFILE)
      loadAccounts()
      server.verify_request = verify_request
    server.timeout = 0.01
    server.quiet = True
    print "Persistent storage root is: " + storage_dir()
    print "-----------------------------------------------------------------------------"
    print "Bottle server starting up ..."
    print "Serial is set to %d bps" % BITSPERSECOND
    print "Point your browser to: "
    if CERTSDIR:
      print "https://%s:%d/" % (COMMON_NAME, port)
    elif COMMON_NAME:
      print "http://%s:%d/" % (COMMON_NAME, port)
    else:
      print "http://%s:%d/" % ('127.0.0.1', port)
    print "Use Ctrl-C to quit."
    print "-----------------------------------------------------------------------------"
    print
    # auto-connect on startup
    global SERIAL_PORT
    if not SERIAL_PORT:
        SERIAL_PORT = SerialManager.match_device(GUESS_PREFIX, BITSPERSECOND)
    SerialManager.connect(SERIAL_PORT, BITSPERSECOND)
# I:Mega Start
    time.sleep(1.0)
# I:Mega End
#    # open web-browser
#    try:
#        webbrowser.open_new_tab('http://127.0.0.1:'+str(port))
#        pass
#    except webbrowser.Error:
#        print "Cannot open Webbrowser, please do so manually."
    sys.stdout.flush()  # make sure everything gets flushed
    server.timeout = 0
    lastPowerStatus = 0
    powerStateChange = 0
    while 1:
        try:
            serial_handler('1')
            SerialManager.send_queue_as_ready()
            server.handle_request()
            if HARDWARE == 'raspberrypi':
              powerStatus = RPiPowerControl.interval_check()
              if powerStatus != lastPowerStatus:
                powerStateChange = 1
                lastPowerStatus = powerStatus
            if powerStateChange:
              powerStateChange = checkStatus()
            time.sleep(0.0004)
        except KeyboardInterrupt:
            if HARDWARE == 'raspberrypi':
              RPiPowerControl.gpio_cleanup()
            break
        except:
            import traceback
            traceback.print_exc()
            break
    print "\nShutting down..."
    if redirect_pid:
      os.kill(redirect_pid, signal.SIGTERM)
    SerialManager.close()