Ejemplo n.º 1
0
def uptime_worker(args):
    global count_uptime
    msg("sleep {0}", int(args["time"]))
    sleep(int(args["time"]))
    count_uptime += 1
    return {
        "uptime": (clock() - start) * 1000.0
    }
Ejemplo n.º 2
0
def requests(args):
    if args[0] != 'uptime':
        msg("unknown request: {0}", args[0])
    else:
        msg("requests made to {0}: {1}", args[0], count_uptime)
Ejemplo n.º 3
0
port = 8000
server = create_server((addr, port))
server.bind_path('/', '..')
server.add_default_white_list()
server.link_empty_favicon_fallback()

start = clock()
@server.json_get('/api/uptime/')
def uptime(req, args):
    global count_uptime
    count_uptime += 1
    return {
        "uptime": req.log_elapsed_time_string((clock() - start) * 1000.0).strip()
    }

def complete_requests(_args, text):
  return [ "uptime" ] if "uptime".startswith(text) else []

count_uptime = 0
@server.cmd(1, complete_requests)
def requests(args):
    if args[0] != 'uptime':
        msg("unknown request: {0}", args[0])
    else:
        msg("requests made to {0}: {1}", args[0], count_uptime)

msg("starting server at {0}:{1}", addr if addr else 'localhost', port)
server.serve_forever()
msg("shutting down..")
server.server_close()
Ejemplo n.º 4
0
import argparse
import sys

setup_restart()

parser = argparse.ArgumentParser(prog="quick_server", description='Quick Server')
parser.add_argument('-a', type=str, default="localhost", help="specifies the server address")
parser.add_argument('-p', type=int, default=8080, help="specifies the server port")
parser.add_argument('--www', type=str, default='..', help="the folder to serve files from (defaults to parent folder)")
args = parser.parse_args()

addr = args.a
port = args.p
www = args.www

server = create_server((addr, port))
server.bind_path('/', www)

server.directory_listing = True
server.add_default_white_list()
server.link_empty_favicon_fallback()

server.suppress_noise = True
server.report_slow_requests = True

msg("{0}", " ".join(sys.argv))
msg("starting server at {0}:{1}", addr if addr else 'localhost', port)
server.serve_forever()
msg("shutting down..")
server.server_close()