configure manifold server in myslice/config.py
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 12 Feb 2013 13:53:42 +0000 (14:53 +0100)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Tue, 12 Feb 2013 13:53:42 +0000 (14:53 +0100)
rough ManifoldQuery python class
rename plugin.js into plugin_init.js to make room for the joomla js code

engine/manifold_api.py
engine/manifold_query.py [new file with mode: 0644]
engine/query.py [deleted file]
engine/static/js/plugin_init.js [moved from engine/static/js/plugin.js with 100% similarity]
myslice/config.py [new file with mode: 0644]
templates/layout-myslice.html

index 63487b9..f827b51 100644 (file)
@@ -1,19 +1,16 @@
 # Manifold API Python interface
 import xmlrpclib
-#from util.config import Config
+from myslice.config import Config
 
 class ManifoldAPI:
 
   def __init__(self, auth=None, cainfo=None):
 
-    #config = Config()
+    config = Config()
     self.auth = auth
-    #self.server = config.server
-    #self.port = config.port
-    #self.path = config.path
-    self.server = 'demo.myslice.info'
-    self.port = '7080'
-    self.path = '/'
+    self.server = config.manifold_server
+    self.port = config.manifold_port
+    self.path = config.manifold_path
     self.cainfo = cainfo
     self.errors = []
     self.trace = []
@@ -27,4 +24,4 @@ class ManifoldAPI:
            print methodName, self.auth, self.url
            result=getattr(self.proxy, methodName)(self.auth, *args, **kwds)
            return result
-      return func
\ No newline at end of file
+      return func
diff --git a/engine/manifold_query.py b/engine/manifold_query.py
new file mode 100644 (file)
index 0000000..8a5690f
--- /dev/null
@@ -0,0 +1,48 @@
+import json
+
+# xxx php has uniqid, need to find a module for that
+counter=1
+def uniqid (): global counter; counter += 1; return counter
+
+class ManifoldQuery:
+
+    def __init__ (self, action=None, method=None, timestamp='now',
+                  filters=[], params=[], fields=[],
+                  sort=None, limit=None, offset=None,
+                  ):
+        self.uuid=uniqid()
+        # settable
+        self.action=action
+        self.method=method
+        self.timestamp=timestamp
+        self.filters=filters
+        self.params=params
+        self.fields=fields
+        self.sort=sort
+        self.limit=limit
+        self.offset=offset
+        # internal data
+        self.analyzed_query=None
+        self.subqueries = {}
+
+    def to_json (self):
+        uuid=self.uuid
+        a=self.action
+        m=self.method
+        t=self.timestamp
+        f=json.dumps (self.filters)
+        p=json.dumps (self.params)
+        c=json.dumps (self.fields)
+        # xxx unique can be removed, but for now we pad the js structure
+        unique=0
+
+        # subqueries is a dictionary method:query
+        sq=", ".join ( [ "'%s':%s" % (method, subquery.to_json())
+                      for (method, subquery) in self.subqueries.iteritems()])
+        
+        aq = self.analyzed_query.to_json() if self.analyzed_query else 'null'
+        
+        return "new Query('%(a)s', '%(m)s', '%(t)s', %(f)s, %(p)s, %(c)s, %(unique)s, '%(uuid)s', %(aq)s, {{%(sq)s}})"%locals()
+
+    
+
diff --git a/engine/query.py b/engine/query.py
deleted file mode 100644 (file)
index 9b22cbd..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-# needed imports
-# uniqid
-
-xxx this code is broken and not used 
-
-class Query:
-
-    def __init__ (self):
-        self.action=None
-        self.method=None
-        self.ts=None
-        self.filters=[]
-        self.params=[]
-        self.fields=[]
-        self.unique=False
-        # xxx 
-        self.uuid=uniquid()
-        self.sort=None
-        self.limit=None
-        self.offset=None
-        self.analyzed_query=None
-        self.subqueries = []
-
-    def to_json (self):
-        return "Query.json: todo"
-
diff --git a/myslice/config.py b/myslice/config.py
new file mode 100644 (file)
index 0000000..b882b7d
--- /dev/null
@@ -0,0 +1,6 @@
+class Config:
+
+#    manifold_server = 'demo.myslice.info'
+    manifold_server = 'debian04.pl.sophia.inria.fr'
+    manifold_port = '7080'
+    manifold_path = '/'
index 679e746..d7a1565 100644 (file)
@@ -19,7 +19,7 @@
 
 {# let's add these ones no matter what #}
 {% insert_str prelude "jquery/js/jquery.js" %}
-{% insert_str prelude "js/plugin.js" %}
+{% insert_str prelude "js/plugin_init.js" %}
 {% insert_str prelude "css/myslice.css" %}
 
 <body>