def main(): _opts = _init_env() del _opts _routes = [ (r'/', 'model_service.service_handler'), (r'/web/(.+)', 'serv_web.web_handler'), (r'/admin/(.+)', 'model_service.admin_handler'), (r'/d/([^/]+)', 'model_service.metedata_handler'), (r'/d/([^/]+/\w+/.+)', 'model_service.resource_handler'), (r'/m/([^/]+)', 'model_service.model_handler'), (r'/s/([^/]+)', 'model_service.status_handler'), (r'/o/([^/]+)', 'model_service.output_handler'), (r'/data/([^/]+)/([^/]+)', 'model_service.data_cache_handler'), (r'/data/([^/]+)', 'model_service.data_cache_handler') ] _config = {} _config['webapp2_extras.sessions'] = { 'secret_key': 'something-very-secret' } _app = webapp2.WSGIApplication(routes=_routes, debug=True, config=_config) _app.error_handlers[400] = handle_error _app.error_handlers[404] = handle_error from paste import httpserver import config httpserver.serve(_app, host=config.get_at('general', 'host'), port=config.get_at('general', 'port'))
def task(self, path): import os, config _p, _v = path.split('/', 1) _d_web = config.get_at('general', 'web_path') if os.path.exists(os.path.join(_d_web, _p)): logging.info('loading web path: ' + path) _f = os.path.join(_d_web, path) if not os.path.exists(_f): _f = config.get_at('general', 'nodata_file') return self.output_file(_f) _zips = load_zips() if _p not in _zips.keys(): if os.path.exists(os.path.join(_d_web, _p + '.zip')): _zips = load_zips(True) if _p in _zips: _r = _zips[_p].load(_v) if _r == None: if _v.endswith('.png'): return self.output_file(config.get_at('general', 'nodata_file')) raise Exception('failed to find page %s' % path) else: return self.output_byte(path, _r) raise Exception('no module found %s' % _p)
def main(): _opts = _init_env() del _opts # import serv_web # serv_web._zips = serv_web.load_zips() _routes = [ (r'/', 'serv_web.web'), (r'/map/(.+)', 'serv_web.map') ] _config = {} _config['webapp2_extras.sessions'] = { 'secret_key': 'something-very-secret' } import webapp2 _app = webapp2.WSGIApplication(routes=_routes, debug=True, config=_config) _app.error_handlers[400] = handle_error _app.error_handlers[404] = handle_error from paste import httpserver import config httpserver.serve(_app, host=config.get_at('general', 'host'), port=config.get_at('general', 'port')) print 'done'
def __init__(self): import config import pymongo self.con = pymongo.MongoClient(config.get_at('general', 'db_connect')) self.db = self.con.data_cache self.data_caches = self.db.data_caches self.cache_path = config.get_at('general', 'data_cache_path') self.types = { 'band': data_type_band(), 'foot': data_type_foot() }
def task(self, path): import os, config logging.info('loading web path: ' + path) _f = os.path.join(config.get_at('general', 'web_path'), path) self.output_file(_f)
def task(self, oid, dtype=None): import file_unzip import config print 'request data cache: %s, %s' % (oid, dtype) with file_unzip.file_unzip(config.get_at('general', 'tmp_path')) as _zip: _f = self.mag.load(oid, dtype.lower() if dtype else dtype, _zip) self.output_file(_f)
def insert_band(self, bnd, username, note=''): import file_unzip import config with file_unzip.file_unzip(config.get_at('general', 'tmp_path')) as _zip: _f = _zip.generate_file('', '.tif') bnd.save(_f) return self.insert_file(_f, 'band', 'tif', username, note)
def load_zips(load=False): global _zips if not load: return _zips import os import config import read_zip _root = config.get_at('general', 'web_path') for _f in os.listdir(_root): if _f.endswith('.zip'): _t = _f[:-4] if _t not in _zips: print ' + loading zip', _f, import sys sys.stdout.flush() _zips[_t] = read_zip.zip_file(os.path.join(_root, _f)) print 'done' return _zips
def generate_url(self, oid): import config _url = 'http://%s:%s/data/%s' % (config.get_at('general', 'host'), config.get_at('general', 'port'), str(oid)) return {'type': 'cache', 'url': _url}
import serv_base import model_process import logging import config _models = model_process.geo_models(config.get_at('general', 'mod_path')) class service_handler(serv_base.service_base): def task(self): _ms = {} for _m in _models.models: _mod = _models.models[_m] _met = _models.metadata[_m] _ms[_m] = {'model': _mod.model, 'inputs': _mod.inputs, 'outputs': _mod.outputs, 'pic': len(_met.pic), 'doc': len(_met.doc)} _o = {'model_service': {'provider': 'geodata.cn'}, 'models': _ms} self.output_json(_o) class metedata_handler(serv_base.service_base): def task(self, model_id): logging.info('model id:' + model_id) _ks = _models.models.keys() _ks.sort() _ms = [] for _m in _ks: if model_id == '*' or model_id == _m: