Example #1
0
def main():
    context = zmq.Context()
    socket = context.socket(zmq.SUB)
    socket.connect(CHANNEL)
    socket.setsockopt(zmq.SUBSCRIBE, "")
    zmq_stream = zmqstream.ZMQStream(socket)

    data_store = AsyncDataStore(zmq_stream.on_recv)
    viewer = GViewer(DisplayerContext(data_store, Displayer()),
                     config=Config(auto_scroll=True),
                     event_loop=urwid.TornadoEventLoop(ioloop.IOLoop.instance()))
    viewer.start()
Example #2
0
 def __init__(self, data):
     data_store = self.create_data_store(data)
     self.child_context = ChildDisplayer().context
     self.viewer = GViewer(
         DisplayerContext(data_store, self, actions=Actions(
             [("m", "notify a message", self.notify),
              ("L", "log view", self.log),
              ("M", "mark a message", self.mark)])),
         other_contexts=[self.child_context],
         palette=[("nodeid", "light cyan", "black")])
Example #3
0
class Displayer(BaseDisplayer):
    def __init__(self, data):
        data_store = StaticDataStore(data)
        self.viewer = GViewer(DisplayerContext(data_store, self))

    def summary(self, message):
        return message["summary"]

    def get_views(self):
        return [("Detail A", self.detail_a),
                ("Detail B", self.detail_b),
                ("Detail C", self.detail_c)]

    def detail_a(self, message):
        return View([Group("Detail", [Text(message["a"])])])

    def detail_b(self, message):
        return View([Group("Detail", [Text(message["b"])])])

    def detail_c(self, message):
        raise ValueError("error")

    def run(self):
        self.viewer.start()
Example #4
0
class Displayer(BaseDisplayer):
    def __init__(self, data):
        data_store = StaticDataStore(data)
        self.viewer = GViewer(DisplayerContext(data_store, self))

    def summary(self, message):
        return message["summary"]

    def get_views(self):
        return [("View A", self.detail_a),
                ("View B", self.detail_b),
                ("View C", self.detail_c)]

    def detail_a(self, message):
        return View([Group("AAA", [Text(m) for m in message["a"]])])

    def detail_b(self, message):
        return View([Group("BBB", [Text(m) for m in message["b"]])])

    def detail_c(self, message):
        return View([Group("CCC", [Text(m) for m in message["c"]])])

    def run(self):
        self.viewer.start()
Example #5
0
class Displayer(BaseDisplayer):
    def __init__(self):
        store = StaticDataStore(_get_list())
        context = DisplayerContext(store, self)
        self.viewer = GViewer(context)

    def get_views(self):
        return [("", self.highlight)]

    def highlight(self, message):
        with open(message, "r") as f:
            file_content = f.read()

        if message.endswith(".py"):
            pygmentize_list = pygmentize(file_content, get_lexer_by_name("python"))
        else:
            pygmentize_list = pygmentize(file_content, get_lexer_by_name("json"))

        widgets = map(lambda l: Text(l), pygmentize_list)

        return View([Group("", widgets)])

    def start(self):
        self.viewer.start()
Example #6
0
class PanamaDisplayer(BaseDisplayer):
    def __init__(self, data):
        data_store = self.create_data_store(data)
        self.child_context = ChildDisplayer().context
        self.viewer = GViewer(
            DisplayerContext(data_store, self, actions=Actions(
                [("m", "notify a message", self.notify),
                 ("L", "log view", self.log),
                 ("M", "mark a message", self.mark)])),
            other_contexts=[self.child_context],
            palette=[("nodeid", "light cyan", "black")])

    def create_data_store(self, data):
        return StaticDataStore(data)

    def summary(self, message):
        return [
            "  ",
            ("nodeid", message["node_id"]),
            " ",
            message["name"]]

    def get_views(self):
        return [("Detail", self.detail)]

    def detail(self, message):
        detail_groups = []
        summary_group_content = \
            [Prop(k, v) for k, v in message.items() if isinstance(v, str)]

        detail_groups.append(PropsGroup("Summary", summary_group_content))

        for shareholder in message.get("officers").get("shareholder of"):
            props = [
                Prop(k, shareholder[k]) for k in [
                    "name", "icij_id", "valid_until", "country_codes",
                    "countries", "node_id", "sourceID"]
            ]
            for index, address in enumerate(shareholder["registered_address"]):
                props.extend(
                    [Prop("address[{0}].{1}".format(index, k), v) for k, v in address.items()])

            detail_groups.append(PropsGroup(
                shareholder.get("name"), props))

        return View(detail_groups, actions=Actions([
            ("E", "export", self.export),
            ("m", "notify", self.notify)]))

    def notify(self, controller, messag, widget, *args, **kwargs):
        controller.notify("yayaya")

    def export(self, controller, message, widget, *args, **kwargs):
        with open("panama-export.json", "w") as w:
            w.write(json.dumps(message))
        controller.notify("export to file panama-export.json")

    def log(self, controller, message, widget, *args, **kwargs):
        controller.open_view_by_context(self.child_context)

    def mark(self, controller, message, widget, *args, **kwargs):
        widget.set_title([
            "V ", ("nodeid", message["node_id"]),
            " ", message["name"]])

    def run(self):
        self.viewer.start()
Example #7
0
 def __init__(self, data):
     data_store = StaticDataStore(data)
     self.viewer = GViewer(DisplayerContext(data_store, self))
Example #8
0
 def __init__(self):
     store = StaticDataStore(_get_list())
     context = DisplayerContext(store, self)
     self.viewer = GViewer(context)