Esempio n. 1
0
    def do_GET(self):

        # parse command-line args passed in url query string as an 'args' parameter
        def query2opt(query):
            args = shlex.split(query['args'][0])
            return __main__.get_opt(args)

        # parse url, extracting path and query portions
        _, _, path, _, query, _ = urlparse.urlparse(self.path)
        query = urlparse.parse_qs(query)

        # query to root is redirected to default session 0
        if path=='/':
            self.send_response(301) # permanent
            self.send_header('Location', '/0')

        # open a new view in a new window
        # expects command-line arg string in url parameter "args"
        # parse off the query, open new session based on that, then redirect to bare session url
        elif path=='/open':
            opt = query2opt(query) # parse url "args" parameter
            ses = Ses(opt, server=True) # new session
            self.send_response(302) # temporary redirect
            self.send_header('Location', ses.path)

        # top-level page: return the container, which includes
        #   progress message area - loaded via /ses/progress url in progress phase (below)
        #   content area - loaded via /ses/content url in content phase (below)
        elif path in Ses.sessions:
            ses = Ses.sessions[path]
            self.prepare(ses)
            html.container(ses)

        # info for a given time t
        elif path.endswith('/info'):
            path = path.rsplit('/', 1)[0]
            ses = Ses.sessions[path]
            t = float(query['t'][0])
            self.prepare(ses)
            html.info(ses, t)

        # raw info for a given time t
        elif path.endswith('/raw'):
            path = path.rsplit('/', 1)[0]
            ses = Ses.sessions[path]
            t = float(query['t'][0])
            self.prepare(ses)
            html.raw(ses, t, kind='raw')

        elif path.endswith('/metadata'):
            path = path.rsplit('/', 1)[0]
            ses = Ses.sessions[path]
            t = float(query['t'][0])
            self.prepare(ses)
            html.raw(ses, t, kind='metadata')

        # progress phase: load the data in preparation for generating content
        # while emitting progress messages. We also accept new view parameters to open
        # new view in current window as command-line arg string in url parameter "args"
        elif path.endswith('/progress'):
            path = path.rsplit('/', 1)[0]
            ses = Ses.sessions[path]
            if 'args' in query:
                ses.opt = query2opt(query) # parse url "args" parameter
            self.prepare(ses)
            html.load(ses)

        # content phase: generate actual html view from graph data loadedin progress phase
        elif path.endswith('/content'):
            path = path.rsplit('/', 1)[0]
            ses = Ses.sessions[path]
            self.prepare(ses)
            html.page(ses)

        # a window closed
        elif '/close/' in path:
            if Handler.exit_on_close:
                path, _, what = path.rsplit('/', 2)
                util.msg('closing', path, '('+what+')')
                if path in Ses.sessions:
                    del Ses.sessions[path]
                if not Ses.sessions:
                    util.msg('all sessions closed, exiting')
                    os._exit(0)

        # otherwise not found
        else:
            self.send_response(404) # not found
Esempio n. 2
0
def raw(node, translator):
    result = html.raw(node.astext())
    translator._append(result, node)
    return result
Esempio n. 3
0
    def do_GET(self):

        # parse command-line args passed in url query string as an 'args' parameter
        def query2opt(query):
            args = shlex.split(query['args'][0])
            return __main__.get_opt(args)

        # parse url, extracting path and query portions
        _, _, path, _, query, _ = urlparse.urlparse(self.path)
        query = urlparse.parse_qs(query)

        # query to root is redirected to default session 0
        if path == '/':
            self.send_response(301)  # permanent
            self.send_header('Location', '/0')

        # open a new view in a new window
        # expects command-line arg string in url parameter "args"
        # parse off the query, open new session based on that, then redirect to bare session url
        elif path == '/open':
            opt = query2opt(query)  # parse url "args" parameter
            ses = Ses(opt, server=True)  # new session
            self.send_response(302)  # temporary redirect
            self.send_header('Location', ses.path)

        # top-level page: return the container, which includes
        #   progress message area - loaded via /ses/progress url in progress phase (below)
        #   content area - loaded via /ses/content url in content phase (below)
        elif path in Ses.sessions:
            ses = Ses.sessions[path]
            self.prepare(ses)
            html.container(ses)

        # info for a given time t
        elif path.endswith('/info'):
            path = path.rsplit('/', 1)[0]
            ses = Ses.sessions[path]
            t = float(query['t'][0])
            self.prepare(ses)
            html.info(ses, t)

        # raw info for a given time t
        elif path.endswith('/raw'):
            path = path.rsplit('/', 1)[0]
            ses = Ses.sessions[path]
            t = float(query['t'][0])
            self.prepare(ses)
            html.raw(ses, t, kind='raw')

        elif path.endswith('/metadata'):
            path = path.rsplit('/', 1)[0]
            ses = Ses.sessions[path]
            t = float(query['t'][0])
            self.prepare(ses)
            html.raw(ses, t, kind='metadata')

        # progress phase: load the data in preparation for generating content
        # while emitting progress messages. We also accept new view parameters to open
        # new view in current window as command-line arg string in url parameter "args"
        elif path.endswith('/progress'):
            path = path.rsplit('/', 1)[0]
            ses = Ses.sessions[path]
            if 'args' in query:
                ses.opt = query2opt(query)  # parse url "args" parameter
            self.prepare(ses)
            html.load(ses)

        # content phase: generate actual html view from graph data loadedin progress phase
        elif path.endswith('/content'):
            path = path.rsplit('/', 1)[0]
            ses = Ses.sessions[path]
            self.prepare(ses)
            html.page(ses)

        # a window closed
        elif '/close/' in path:
            if Handler.exit_on_close:
                path, _, what = path.rsplit('/', 2)
                util.msg('closing', path, '(' + what + ')')
                if path in Ses.sessions:
                    del Ses.sessions[path]
                if not Ses.sessions:
                    util.msg('all sessions closed, exiting')
                    os._exit(0)

        # otherwise not found
        else:
            self.send_response(404)  # not found