Commits

Jesper Nøhr  committed bac456f Merge
  • Participants
  • Parent commits 8d71fb1, d37baec

Comments (0)

Files changed (3)

File puck/client.py

+#!/usr/bin/python
+import os, sys, simplejson, socket
+from twisted.internet import reactor
+
+class PuckProxy(object):
+    pass
+    
+class JSONCall(object):
+    def __init__(self, module='', id_=None, args=( ), kwargs={ }):
+        self.module = module
+        self.id = id_
+        self.args = args
+        self.kwargs = kwargs
+    
+    def to_json(self):
+        kwd = { 
+            'method': self.module, 
+            'id': self.id,
+            'args': self.args,
+        }
+
+        return simplejson.dumps(kwd)
+
+class PuckClient(object):
+    def __init__(self, module, host, port, *args, **kwargs):
+        for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
+            af, socktype, proto, canonname, sa = res
+            self.sock = socket.socket(af, socktype, proto)
+
+            try:
+                self.sock.connect(sa)
+            except socket.error, msg:
+                self.sock = None
+            
+        if self.sock is not None:
+            print "got a socket:", self.sock
+            self.__call(module, *args, **kwargs)
+        else:
+            print "failed to connect, can't do anything"
+    
+    def __call(self, module, *args, **kwargs):
+        packet = JSONCall(module=module, id_=None, args=args, kwargs=kwargs)
+        self.sock.sendall(packet.to_json())
+        f = self.sock.makefile('rb')
+        return f.readline()
+    
+    def __getattr__(self, attr):
+        print "searching for blarch"

File tests/example-fs/client.py

 #!/usr/bin/python
-import os, sys, simplejson, socket
+import os, sys
 sys.path.append('../../')
-from twisted.internet import reactor
-from puck.client import PuckClientFactory
 
-class StupidClient(object):
-    def __init__(self, host, port):
-        for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
-            af, socktype, proto, canonname, sa = res
-            self.sock = socket.socket(af, socktype, proto)
+from puck.client import PuckClient
 
-            try:
-                self.sock.connect(sa)
-            except socket.error, msg:
-                print "ex %s", repr(msg)
-                self.sock = None
-            
-            if self.sock is not None:
-                print "got a socket:", self.sock
-                
-            
-if __name__ == '__main__':
-    s = StupidClient('localhost', 8080)
+if __name__ == "__main__":
+    c = PuckClient("hg.repository", 'localhost', 8080)
+    print c
+    

File tests/example-fs/twistd.pid

-32267