Ejemplo n.º 1
0
 def set_metadata(self, metadata):
     metadata = util.build_recursive(metadata)
     if 'Metadata' in metadata:
         metadata = metadata['Metadata']
     self['Metadata'] = util.dict_merge(self.get('Metadata', {}),
                                        metadata)
     self.dirty_children()
Ejemplo n.º 2
0
def parser(data):
    """Parse a response body from the server.  Since this may include
multiple lines, we need to be careful to do this right and merge the
results together."""
    rv = {}
    for line in data.split('\n'):
        if len(line.strip()) == 0:
            continue
        line_obj = json.loads(line)

        if not isinstance(line_obj, list):
            return data
        if len(line_obj) == 0: continue

        for v in line_obj:
            if not 'uuid' in v:
                return line_obj
            # raise SmapException("Invalid sMAP object: " + str(v))
            id = v['uuid']
            if not id in rv:
                rv[id] = v
            else:
                if 'Readings' in v and 'Readings' in rv[id]:
                    rv[id]['Readings'].extend(v['Readings'])
                    del v['Readings']
                rv[id] = util.dict_merge(rv[id], v)
    return rv.values()
Ejemplo n.º 3
0
Archivo: client.py Proyecto: ahaas/smap
def parser(data):
    """Parse a response body from the server.  Since this may include
multiple lines, we need to be careful to do this right and merge the
results together."""
    rv = {}
    for line in data.split('\n'):
        if len(line.strip()) == 0: 
            continue
        line_obj = json.loads(line)

        if not isinstance(line_obj, list): 
            return data
        if len(line_obj) == 0: continue

        for v in line_obj:
            if not 'uuid' in v:
                return line_obj
            # raise SmapException("Invalid sMAP object: " + str(v))
            id = v['uuid']
            if not id in rv:
                rv[id] = v
            else:
                if 'Readings' in v and 'Readings' in rv[id]:
                    rv[id]['Readings'].extend(v['Readings'])
                    del v['Readings']
                rv[id] = util.dict_merge(rv[id], v)
    return rv.values()
Ejemplo n.º 4
0
 def set_metadata(self, metadata):
     metadata = util.build_recursive(metadata)
     if 'Metadata' in metadata:
         metadata = metadata['Metadata']
     self['Metadata'] = util.dict_merge(self.get('Metadata', {}),
                                        metadata)
     self.dirty_children()
Ejemplo n.º 5
0
Archivo: client.py Proyecto: ahaas/smap
 def tags(self, path):
     """ 
     Get all metadata associated with path, including metadata 
     inherited from collections it belongs to
     """
     nodes = path.split('/')
     p = ""
     rv = {}
     for node in nodes:
         p += '/' + node
         fp = urllib2.urlopen(self.base + "/data" + p)
         res = json.loads(fp.read())
         rv = util.dict_merge(rv, res)
     if 'Contents' in rv:
         del rv['Contents']
     return rv
Ejemplo n.º 6
0
 def tags(self, path):
     """ 
     Get all metadata associated with path, including metadata 
     inherited from collections it belongs to
     """
     nodes = path.split('/')
     p = ""
     rv = {}
     for node in nodes:
         p += '/' + node
         fp = urllib2.urlopen(self.base + "/data" + p)
         res = json.loads(fp.read())
         rv = util.dict_merge(rv, res)
     if 'Contents' in rv:
         del rv['Contents']
     return rv