コード例 #1
0
ファイル: Watcher.py プロジェクト: dadicool/jasy
def watch(path, callback):
    
    header("Build Daemon")
    
    if Observer is None:
        error("You need to install Watchdog for supporting file system watchers")

    # We need to pause the session to make room for other jasy executions
    session.pause()

    # Initialize file system observer
    observer = Observer()
    observer.schedule(JasyEventHandler(), ".", recursive=True)
    observer.start()

    info("Started file system watcher for %s... [PID=%s]", path, os.getpid())
    info("Use 'ulimit -n 1024' to increase number of possible open files")

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()

    info("Stopped file system watcher for %s...", path)
    observer.join()
コード例 #2
0
ファイル: Web.py プロジェクト: dadicool/jasy
def serve(routes=None, port=8080, host="127.0.0.1"):
    
    header("HTTP Server")
    
    # We need to pause the session to make room for other jasy executions
    session.pause()

    # Shared configuration (global/app)
    config = {
        "global" : {
            "environment" : "production",
            "log.screen" : False,
            "server.socket_port": port,
            "server.socket_host": host,
            "engine.autoreload_on" : False
        },
        
        "/" : {
            "log.screen" : False
        }
    }
    
    # Update global config
    cherrypy.config.update(config)

    # Somehow this screen disabling does not work
    # This hack to disable all access/error logging works
    def empty(*param, **args): pass
    def inspect(*param, **args): 
        if args["severity"] > 20:
            error("Critical error occoured:")
            error(param[0])
    
    cherrypy.log.access = empty
    cherrypy.log.error = inspect
    cherrypy.log.screen = False

    # Initialize routing
    info("Initialize routing...")
    indent()
    root = Static("/", {})
    if routes:
        for key in routes:
            entry = routes[key]
            if "host" in entry:
                node = Proxy(key, entry)
            else:
                node = Static(key, entry)
            
            setattr(root, key, node)
    outdent()
    
    # Finally start the server
    app = cherrypy.tree.mount(root, "", config)
    cherrypy.process.plugins.PIDFile(cherrypy.engine, "jasylock-http-%s" % port).subscribe()
    
    cherrypy.engine.start()
    info("Started HTTP server at port %s... [PID=%s]", port, os.getpid())
    indent()
    cherrypy.engine.block()

    outdent()
    info("Stopped HTTP server at port %s.", port)
    
    # Resume session to continue work on next task (if given)
    session.resume()