From: Jordan Augé Date: Fri, 22 Nov 2013 10:37:49 +0000 (+0100) Subject: Merge branch 'master' of ssh://git.onelab.eu/git/myslice X-Git-Tag: myslice-0.3-0~113 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=d1197c134b70bda643a752bdaf891190cb5a15e7;hp=-c;p=unfold.git Merge branch 'master' of ssh://git.onelab.eu/git/myslice --- d1197c134b70bda643a752bdaf891190cb5a15e7 diff --combined manifold/manifoldapi.py index 46229f17,cd14efe7..1b97505d --- a/manifold/manifoldapi.py +++ b/manifold/manifoldapi.py @@@ -1,5 -1,5 +1,5 @@@ # Manifold API Python interface - import xmlrpclib + import copy, xmlrpclib from myslice.config import Config @@@ -32,6 -32,12 +32,12 @@@ class ManifoldAPI def __repr__ (self): return "ManifoldAPI[%s]"%self.url + def _print_value (self, value): + print "+++",'value', + if isinstance (value,list): print "[%d]"%len(value), + elif isinstance (value,dict): print "{%d}"%len(value), + print mytruncate (value,80) + # a one-liner to give a hint of what the return value looks like def _print_result (self, result): if not result: print "[no/empty result]" @@@ -41,7 -47,8 +47,8 @@@ print "result is a dict with %d keys : %s"%(len(result),result.keys()) for (k,v) in result.iteritems(): if v is None: continue - print '+++',k,':',mytruncate (v,60) + if k=='value': self._print_value(v) + else: print '+++',k,':',mytruncate (v,30) else: print "[dont know how to display result] %s"%result # xxx temporary code for scaffolding a ManifolResult on top of an API that does not expose error info @@@ -63,15 -70,17 +70,19 @@@ try: if debug: print "====> ManifoldAPI.%s"%repr(),"url",self.url - print "=> auth",self.auth + # No password in the logs + logAuth = copy.copy(self.auth) + if 'AuthString' in logAuth: + logAuth['AuthString']="XXX" + print "=> auth",logAuth print "=> args",args,"kwds",kwds annotations = { 'authentication': self.auth } args += (annotations,) result=getattr(self.server, methodName)(*args, **kwds) + print "%s%r" %(methodName, args) + if debug: print '<= result=', self._print_result(result) diff --combined manifold/metadata.py index 40a88ff6,90a09eab..08fdf61d --- a/manifold/metadata.py +++ b/manifold/metadata.py @@@ -4,8 -4,6 +4,8 @@@ import os.pat from manifold.manifoldresult import ManifoldResult from manifold.manifoldapi import ManifoldAPI +from django.contrib import messages + debug=False debug=True @@@ -19,7 -17,7 +19,7 @@@ class MetaData self.auth=auth self.hash_by_object={} - def fetch (self): + def fetch (self, request): offline_filename="%s/../offline-metadata.json"%os.path.dirname(__file__) if work_offline: try: @@@ -29,24 -27,29 +29,29 @@@ except: print "metadata.work_offline: failed to decode %s"%offline_filename manifold_api = ManifoldAPI(self.auth) - fields = ['table', 'column.name', 'column.qualifier', 'column.type', 'column.is_array', 'column.description', 'column.default', 'key', 'capability'] + fields = ['table', 'column.name', 'column.qualifier', 'column.type', + 'column.is_array', 'column.description', 'column.default', 'key', 'capability'] #fields = ['table', 'column.column', # 'column.description','column.header', 'column.title', # 'column.unit', 'column.info_type', # 'column.resource_type', 'column.value_type', # 'column.allowed_values', 'column.platforms.platform', # 'column.platforms.platform_url'] - result = manifold_api.forward({ - 'action': 'get', - 'object': 'local:object', # proposed to replace metadata:table - 'fields': fields - }) + request={ 'action': 'get', + 'object': 'local:object', # proposed to replace metadata:table + 'fields': fields , + } + result = manifold_api.forward(request) + # xxx need a way to export error messages to the UI if result['code'] == 1: # warning - messages.warning(request, result['description']) + # messages.warning(request, result['description']) + print ("METADATA WARNING -",request,result['description']) elif result['code'] == 2: - messages.error(request, result['description']) + # messages.error(request, result['description']) + print ("METADATA ERROR -",request,result['description']) # XXX FAIL HERE XXX + return rows = result.ok_value() # API errors will be handled by the outer logic diff --combined unfold/page.py index 944b2380,7f071c0b..a6ca83cd --- a/unfold/page.py +++ b/unfold/page.py @@@ -33,8 -33,7 +33,7 @@@ class Page # queue of queries with maybe a domid, see enqueue_query self._queue=[] # global prelude object - # self.prelude=Prelude(css_files=['css/plugin.css','css/onelab_marko.css',]) - self.prelude=Prelude() + self.prelude=Prelude(css_files=['css/plugin.css','css/onelab_marko.css',]) # record known plugins hashed on their domid def record_plugin (self, plugin): @@@ -81,7 -80,7 +80,7 @@@ result={'query_uuid':a} if b: result['domid']=b return result - env['query_publish_dom_tuples'] = [ query_publish_dom_tuple (a,b) for (a,b) in self._queue ] + env['query_exec_tuples'] = [ query_publish_dom_tuple (a,b) for (a,b) in self._queue ] javascript = render_to_string ("page-queries.js",env) self.add_js_chunks (javascript) # self.reset_queue() @@@ -89,29 -88,6 +88,6 @@@ self.expose_js_manifold_config() - # DEPRECATED # # needs to be called explicitly and only when metadata is actually required - # DEPRECATED # # in particular user needs to be logged - # DEPRECATED # def get_metadata (self): - # DEPRECATED # # look in session's cache - we don't want to retrieve this for every request - # DEPRECATED # session=self.request.session - # DEPRECATED # if 'manifold' not in session: - # DEPRECATED # print "Page.expose_js_metadata: no 'manifold' in session... - cannot retrieve metadata - skipping" - # DEPRECATED # return - # DEPRECATED # manifold=session['manifold'] - # DEPRECATED # # if cached, use it - # DEPRECATED # if 'metadata' in manifold and isinstance(manifold['metadata'],MetaData): - # DEPRECATED # if debug: print "Page.get_metadata: return cached value" - # DEPRECATED # return manifold['metadata'] - # DEPRECATED # # otherwise retrieve it - # DEPRECATED # manifold_api_session_auth = session['manifold']['auth'] - # DEPRECATED # print "get_metadata(), manifold_api_session_auth =", session['manifold']['auth'] - # DEPRECATED # metadata=MetaData (manifold_api_session_auth) - # DEPRECATED # metadata.fetch() - # DEPRECATED # # store it for next time - # DEPRECATED # manifold['metadata']=metadata - # DEPRECATED # if debug: print "Page.get_metadata: return new value" - # DEPRECATED # return metadata - # needs to be called explicitly and only when metadata is actually required # in particular user needs to be logged def get_metadata (self): @@@ -130,19 -106,20 +106,20 @@@ metadata_auth = {'AuthMethod':'anonymous'} metadata=MetaData (metadata_auth) - metadata.fetch() + metadata.fetch(self.request) # store it for next time manifold['metadata']=metadata if debug: print "Page.get_metadata: return new value" return metadata def expose_js_metadata (self): - # export in this js global... - self.add_js_chunks("var MANIFOLD_METADATA =" + self.get_metadata().to_json() + ";") + # expose global MANIFOLD_METADATA as a js variable + # xxx this is fetched synchroneously.. + self.add_js_init_chunks("var MANIFOLD_METADATA =" + self.get_metadata().to_json() + ";") def expose_js_manifold_config (self): config=Config() - self.add_js_chunks(config.manifold_js_export()) + self.add_js_init_chunks(config.manifold_js_export()) #################### requirements/prelude management # just forward to self.prelude - see decorator above @@@ -151,6 -128,8 +128,8 @@@ @to_prelude def add_css_files (self):pass @to_prelude + def add_js_init_chunks (self):pass + @to_prelude def add_js_chunks (self):pass @to_prelude def add_css_chunks (self):pass