1. Ali Afshar
  2. landslide-main

Commits

Ali Afshar  committed b11714c

Initial Import

  • Participants
  • Parent commits 67babe4
  • Branches default

Comments (0)

Files changed (6)

File build.bu

View file
+
+pb:
+    @pb_clean
+    protoc --proto_path=proto --python_out=landslide proto/landslide.proto
+
+pb_clean:
+    rm landslide/landslide_pb2.py
+

File landslide/actions.py

Empty file added.

File landslide/controller.py

View file
+# -*- coding: utf-8 -*-
+"""
+    landslide.controller
+    ~~~~~~~~~~~~~~~~~~~~
+
+    The main application entry point
+
+    :copyright: 2010 by The Landslide Project
+    :license: GPL 2 or later (see README/COPYING/LICENSE)
+"""
+
+class LandslideNode(object):
+    """The Node
+    """
+
+

File landslide/exchange.py

View file
+# -*- coding: utf-8 -*-
+"""
+    landslide.exchange
+    ~~~~~~~~~~~~~~~~~~
+
+    Message passing to and from the report node
+
+    :copyright: 2010 by The Landslide Project
+    :license: GPL 2 or later (see README/COPYING/LICENSE)
+"""
+
+import threading
+
+from amqplib import client_0_8 as amqp
+
+
+class Credentials(object):
+    """A credentials instance to access the message queue
+    """
+    userid = 'guest'
+    password = 'guest'
+
+
+class Connection(object):
+    """Represent a connection to the exchange server
+    """
+    def __init__(self, host='localhost', credentials=Credentials()):
+        self.host = host
+        self.credentials = credentials
+        self.conn = amqp.Connection(
+            host="%s:5672" % host,
+            userid=credentials.userid,
+            password=credentials.password,
+            virtual_host="/", insist=False
+        )
+        self.chan = self.new_channel()
+
+    def new_channel(self):
+        chan = self.conn.channel()
+        chan.queue_declare(queue='main', durable=True,
+                           exclusive=False, auto_delete=False)
+        chan.exchange_declare(exchange='fan',
+                           type='fanout', durable=True,
+                           auto_delete=False)
+        chan.queue_bind('main', 'fan')
+        chan.basic_consume('main', callback=self._on_msg_received)
+        return chan
+
+    def main(self):
+        t = threading.Thread(target=self._wait_for_channel)
+        t.start()
+        return t
+
+    def _wait_for_channel(self):
+        while self.chan.callbacks:
+            self.chan.wait()
+
+    def send_message(self, msg):
+        """Send a message
+        """
+        return self.chan.basic_publish(msg, 'fan')
+
+    def send(self, msg_body, content_type, headers=None):
+        """Send a message
+        """
+        msg = amqp.Message(msg_body, content_type=content_type,
+                           application_headers=headers or {})
+        return self.send_message(msg)
+
+    def receive(self, message):
+        """Receive a message
+        """
+
+    def _on_msg_received(self, msg):
+        for key, val in msg.properties.items():
+            print '%s: %s' % (key, str(val))
+        for key, val in msg.delivery_info.items():
+            print '> %s: %s' % (key, str(val))
+
+        print ''
+        print msg.body
+        print '-------'
+        msg.channel.basic_ack(msg.delivery_tag)
+
+        #
+        # Cancel this callback
+        #
+        if msg.body == 'quit':
+            msg.channel.basic_cancel(msg.consumer_tag)
+
+
+if __name__ == '__main__':
+    c = Connection()
+    c.main()
+    print c.send('hello', 'text/plain')
+    print c.send('quit', 'text/plain')
+    #c.main()
+

File landslide/reporters.py

View file
+# -*- coding: utf-8 -*-
+"""
+    landslide.reporters
+    ~~~~~~~~~~~~~~~~~~~
+
+    Report happenings going on
+
+    :copyright: 2010 by The Landslide Project
+    :license: GPL 2 or later (see README/COPYING/LICENSE)
+"""

File proto/landslide.proto

View file
+
+package landslide;
+
+message Command {
+    required int32 timestamp = 1;
+}
+