Пример #1
0
 def cache_clear(args):
     if len(args) > 1:
         msg("too many extra arguments! expected one got {0}",
             ' '.join(args))
         return
     msg("clear {0}cache{1}{2}", "" if args else "all ",
         " " if args else "s", args[0] if args else "")
     cache.clean_cache(args[0] if args else None)
Пример #2
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
    }
Пример #3
0
    def post_index(req, args):
        if "token" not in args["query"]:
            with token_lock:
                url = "{0}/?pix=0&token={1}".format(prefix,
                                                    server.create_token())
                req.send_response(307, "Ready to go!")
                req.send_header("Location", url)
                req.end_headers()
                raise PreventDefaultResponse()
        token = args["query"]["token"]
        with token_lock:
            tobj = token_obj(token)
            if "post" in args:

                def set_value(o, k, v):
                    if "/" not in k:
                        o[k] = v
                        return
                    kix = k.index("/")
                    tmp = k[:kix]
                    if tmp not in o:
                        o[tmp] = {}
                    set_value(o[tmp], k[kix + 1:], v)

                pobj = args["post"]
                pid = pobj["_pid"]
                for (k, v) in pobj.items():
                    if k == "_pid":
                        continue
                    if k.startswith("_nop"):
                        continue
                    set_value(tobj, "{0}/{1}".format(pid, k), v)
                write_token(token, tobj)
        pix = int(args["query"]["pix"])
        url = "?pix={0}&token={1}".format(pix + 1, token)
        res, _pid, last_page = create_page(spec, pix, url, token, tobj, title)
        if last_page:
            msg("{0} finished!", token)
        return Response(res, ctype="text/html")
Пример #4
0
from quick_server import create_server, msg, setup_restart

msg("{0}", " ".join(sys.argv)) # prints how the script was started
msg("starting server at {0}:{1}", addr if addr else 'localhost', port)
try:
    server.serve_forever() # starts the server -- only returns when the server stops (e.g., by typing `quit`, `restart`, or `CTRL-C`)
finally:
    msg("shutting down..")
    msg("{0}", " ".join(sys.argv)) # print how the script was called before exit -- this way you don't have to scroll up to remember when the server was running for a while
    server.server_close() # make sure to clean up all resources
Пример #5
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)
Пример #6
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()
Пример #7
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()
Пример #8
0
    ram_quota = args.ram_quota
    explainer_file = args.explainer
    sample = args.sample
    protocol = args.protocol

    cache_temp = "tmp"
    if os.path.exists("cache_path.txt"):
        with open("cache_path.txt") as cp:
            cache_temp = cp.read().strip()

    cid = args.input + ":" + explainer_file
    cache = QuickCache(None,
                       cid,
                       quota=cache_quota,
                       ram_quota=ram_quota,
                       temp=cache_temp,
                       warnings=msg)

    explainer_obj = explainer.Explainer(explainer_file, args.input, sample,
                                        cache, msg, protocol)
    server, prefix = get_server(addr, port, explainer_obj, cache)
    msg("{0}", " ".join(sys.argv))
    msg("starting server at http://{0}:{1}{2}/", addr if addr else 'localhost',
        port, prefix)
    try:
        server.serve_forever()
    finally:
        msg("shutting down..")
        msg("{0}", " ".join(sys.argv))
        server.server_close()
Пример #9
0
    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()
Пример #10
0
def requests(args: List[str]) -> None:
    if args[0] != 'uptime':
        msg("unknown request: {0}", args[0])
    else:
        msg("requests made to {0}: {1}", args[0], count_uptime)
Пример #11
0
@server.json_get('/api/:version/a/b/c/d')
def version(req: QuickServerRequestHandler, args: ReqArgs) -> Any:
    return {
        "version": args["segments"]["version"],
    }


@server.json_get('/api/foo/:foo')
def foo(req: QuickServerRequestHandler, args: ReqArgs) -> Any:
    return {
        "foo": args["segments"]["foo"],
    }


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


@server.cmd(1, complete_requests)
def requests(args: List[str]) -> None:
    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()
Пример #12
0
def uptime_worker(args: WorkerArgs) -> Any:
    global count_uptime
    msg("sleep {0}", int(args["time"]))
    sleep(int(args["time"]))
    count_uptime += 1
    return {"uptime": (clock() - start) * 1000.0}