예제 #1
0
파일: core.py 프로젝트: andrewfang/smap
 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()
예제 #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()
예제 #3
0
파일: client.py 프로젝트: 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()
예제 #4
0
파일: core.py 프로젝트: tarunsmalviya/smap
 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()
예제 #5
0
파일: client.py 프로젝트: 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
예제 #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