X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=manifold%2Fmetadata.py;h=f7a5968637f27cc43bdc8e0dfbae5bf9af8cc0dc;hb=74a25f8b8d58726e9bda273a2fde04da83d5d913;hp=04f8511f12aa6d08141a656b4faee717a39ef374;hpb=4c7212bd04ddb65511c42aac5bae6fc3044cd846;p=myslice.git diff --git a/manifold/metadata.py b/manifold/metadata.py index 04f8511f..f7a59686 100644 --- a/manifold/metadata.py +++ b/manifold/metadata.py @@ -1,47 +1,45 @@ import json +import os.path from manifold.manifoldresult import ManifoldResult from manifold.manifoldapi import ManifoldAPI +from django.contrib import messages + debug=False debug=True -# turn this on if you want to work offline -work_offline=False -#work_offline=True - class MetaData: def __init__ (self, auth): self.auth=auth self.hash_by_object={} - def fetch (self): - offline_filename="offline-metadata.json" - if work_offline: - try: - with file(offline_metadata) as f: - self.hash_by_object=json.loads(f.read()) - return - except: - print "metadata.work_offline: failed to decode %s"%offline_filename + def fetch (self, request): manifold_api = ManifoldAPI(self.auth) - 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.Get({ - 'object': 'local:object', # proposed to replace metadata:table - 'fields': fields - }) - + 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'] + 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 @@ -49,10 +47,6 @@ class MetaData: # print "Failed to retrieve metadata",rows_result.error() # rows=[] self.hash_by_object = dict ( [ (row['table'], row) for row in rows ] ) - # save for next time we use offline mode - if debug and rows: - with file(offline_filename,'w') as f: - f.write(json.dumps(self.hash_by_object)) def to_json(self): return json.dumps(self.hash_by_object)