def all_pois(self): poiList = [] lists = os.listdir(self.poiDataPath) for folder in lists: path = self.poiDataPath + folder with io.open('%s/meta.json' % path) as metafile: meta = json.loads(metafile.read()) if not meta['deleted']: container = POIContainer(meta['name']) container.id = folder container.content = [] if os.path.exists('%s/poi.ov2' % path): with io.open('%s/poi.ov2' % path, 'rb') as stream: container.content = ov2.get_pois_from_stream(stream) poiList.append(container) return poiList
def get_container(self, uid, evenDelete = False): path = '%s/%s/' % ( self.poiDataPath, uid ) if os.path.exists(path): with io.open('%s/meta.json' % path) as metafile: meta = json.loads(metafile.read()) if not meta['deleted'] or evenDelete: container = POIContainer(meta['name']) container.id = uid container.content = [] if os.path.exists('%s/poi.ov2' % path): with io.open('%s/poi.ov2' % path, 'rb') as stream: container.content = ov2.get_pois_from_stream(stream) return container else: return None raise Exception('Malformed meta.json file at [%s]' % uid) raise Exception('Unknown UID')
def create_container(self, name = "Nuevo mapa", pois = [], poi_bin_string = None): uid = uuid4().hex container = POIContainer(name) container.id = uid path = '%s/%s/' % ( self.poiDataPath, uid ) os.mkdir(path) ts = int(time()) with io.open('%s/meta.json' % path, 'w') as metafile: metafile.write(unicode(json.dumps({ 'name': name, 'created_at': ts, 'updated_at': ts, 'deleted': False }))) if len(pois) > 0: with io.open('%s/poi.ov2' % path, 'wb') as stream: ov2.save_pois_to_stream(stream, pois) if poi_bin_string: with io.open('%s/poi.ov2' % path, 'wb') as stream: stream.write(poi_bin_string) with io.open('%s/poi.ov2' % path, 'rb') as stream: container.content = ov2.get_pois_from_stream(stream) return container