def config(self, user, uuid=None, max_uuids=50): conf_filename = os.path.join(self.cache_dir, (uuid or user) + ".yaml") if self._requires_reconf(conf_filename): with FileLock(conf_filename + ".lck"): if self._requires_reconf(conf_filename): log.debug("(re)configure %s for %s", (uuid or "all"), user) if uuid: params = tile_params(user, uuid, self.cartodb_domain) if params is None: return conf = mapproxy_config([params], user=user) else: layers = [] for uuid in user_uuids(user, max_uuids=max_uuids, cartodb_domain=self.cartodb_domain): try: params = tile_params(user, uuid, self.cartodb_domain) if params: layers.append(params) else: log.warn("found no layer for %s %s", user, uuid) except RequestError as ex: log.warn("faild to query tiler for %s %s: %s", user, uuid, ex) if not layers: return conf = mapproxy_config(layers, user=user) write_mapproxy_config(conf, conf_filename) return conf_filename
def config(self, user, uuid=None, max_uuids=50): conf_filename = os.path.join(self.cache_dir, (uuid or user) + '.yaml') if self._requires_reconf(conf_filename): with FileLock(conf_filename + '.lck'): if self._requires_reconf(conf_filename): log.debug('(re)configure %s for %s', (uuid or "all"), user) if uuid: params = tile_params(user, uuid, self.cartodb_domain) if params is None: return conf = mapproxy_config([params], user=user) else: layers = [] try: for uuid in user_uuids(user, max_uuids=max_uuids, cartodb_domain=self.cartodb_domain): try: params = tile_params(user, uuid, self.cartodb_domain) if params: layers.append(params) else: log.warn("found no layer for %s %s", user, uuid) except RequestError as ex: log.warn("faild to query tiler for %s %s: %s", user, uuid, ex) except RequestError as ex: log.warn("failed to get user uuids for user %s: %s", user, ex) if not layers: return conf = mapproxy_config(layers, user=user) write_mapproxy_config(conf, conf_filename) return conf_filename
def test_tile_params(): viz_url = 'http://osm2.cartodb.com/api/v2/viz/fda70aae-a7a5-11e4-96f0-0e0c41326911/viz.json' httpretty.register_uri('GET', viz_url, body=open( os.path.join(os.path.dirname(__file__), 'test-vis.json')).read()) # tiler_url def tiler_req(request, uri, headers): eq_(request.headers['Content-type'], 'application/json') return (200, headers, open( os.path.join(os.path.dirname(__file__), 'test-tiler-resp.json')).read()) httpretty.register_uri('POST', 'http://osm2.cartodb.com:80/api/v1/map', body=tiler_req) params = tile_params('osm2', 'fda70aae-a7a5-11e4-96f0-0e0c41326911') eq_( params['url'], 'http://0.ashbu.cartocdn.com/osm2/api/v1/map/235546e1476036314c850900596b4415:1422529684709.27/' ) eq_(params['bounds'], [ -71.2369179725647, 42.66377193433536, -71.2114691734314, 42.67511582354274 ]) eq_(params['title'], 'spencer')
def test_tile_params(): viz_url = 'http://osm2.cartodb.com/api/v2/viz/fda70aae-a7a5-11e4-96f0-0e0c41326911/viz.json' httpretty.register_uri('GET', viz_url, body=open(os.path.join(os.path.dirname(__file__), 'test-vis.json')).read()) # tiler_url def tiler_req(request, uri, headers): eq_(request.headers['Content-type'], 'application/json') return (200, headers, open(os.path.join(os.path.dirname(__file__), 'test-tiler-resp.json')).read()) httpretty.register_uri('POST', 'http://osm2.cartodb.com:80/api/v1/map', body=tiler_req) params = tile_params('osm2', 'fda70aae-a7a5-11e4-96f0-0e0c41326911') eq_(params['url'], 'http://0.ashbu.cartocdn.com/osm2/api/v1/map/235546e1476036314c850900596b4415:1422529684709.27/') eq_(params['bounds'], [-71.2369179725647, 42.66377193433536, -71.2114691734314, 42.67511582354274]) eq_(params['title'], 'spencer')