def __init__(self, import_name, configuration = None): self.make_config(configuration) conf = self.config service_url = self.config['SERVICE_ROOT'] + ':' + self.config['SERVICE_PORT'] if self.config['READ_ONLY'] : self.server = ReadOnlyServer(service_url) else: self.server = Server(serviceRoot=service_url) self.load_metadata() self.make_containers()
def main(): """Executed when we are launched""" doc=LoadMetadata() container=InMemoryEntityContainer(doc.root.DataServices['MemCacheSchema.MemCache']) server=Server(serviceRoot=SERVICE_ROOT) server.SetModel(doc) # The server is now ready to serve forever global cacheApp cacheApp=server t=threading.Thread(target=runCacheServer) t.setDaemon(True) t.start() logging.info("MemCache starting HTTP server on %s"%SERVICE_ROOT) CleanupForever(doc.root.DataServices['MemCacheSchema.MemCache.KeyValuePairs'])
def main(): """Executed when we are launched""" doc = load_metadata() InMemoryEntityContainer(doc.root.DataServices['MemCacheSchema.MemCache']) server = Server(serviceRoot=SERVICE_ROOT) server.set_model(doc) # The server is now ready to serve forever global cache_app cache_app = server t = threading.Thread(target=run_cache_server) t.setDaemon(True) t.start() logging.info("MemCache starting HTTP server on %s" % SERVICE_ROOT) cleanup_forever( doc.root.DataServices['MemCacheSchema.MemCache.KeyValuePairs'])
def setUp(self): # noqa global regressionServerApp DataServiceRegressionTests.setUp(self) self.container = InMemoryEntityContainer( self.ds['RegressionModel.RegressionContainer']) regressionServerApp = Server("http://localhost:%i/" % HTTP_PORT) regressionServerApp.SetModel(self.ds.get_document()) t = threading.Thread(target=run_regression_server) t.setDaemon(True) t.start() logging.info("OData Client/Server combined tests starting HTTP " "server on localhost, port %i" % HTTP_PORT) # yield time to allow the server to start up time.sleep(2) self.svcDS = self.ds self.client = client.Client("http://localhost:%i/" % HTTP_PORT) self.ds = self.client.model.DataServices
from pyslet.odata2.server import Server server = Server("http://localhost:8081/")
class OdataServer(object) : #: Default configuration parameters. default_config = ImmutableDict({ 'DEBUG': False, 'SERVER_NAME': 'ODATA SERVER', 'APPLICATION_ROOT': None, 'READ_ONLY' : True, 'SERVICE_ROOT' : 'http://localhost', 'SERVICE_PORT' : '8080', 'CORS' : True, 'METADATA' : 'metadata.xml' }) functions = None def __init__(self, import_name, configuration = None): self.make_config(configuration) conf = self.config service_url = self.config['SERVICE_ROOT'] + ':' + self.config['SERVICE_PORT'] if self.config['READ_ONLY'] : self.server = ReadOnlyServer(service_url) else: self.server = Server(serviceRoot=service_url) self.load_metadata() self.make_containers() def __call__(self, environ, start_response): if self.config['CORS'] : return CORS(self.server).__call__(environ, start_response) else : return self.server.__call__(environ, start_response) def make_config(self, configuration): self.config = Config(None, self.default_config) if (configuration) : self.config.from_object(configuration) def load_metadata(self) : """Loads the metadata file from the current directory.""" doc = edmx.Document() with open(self.config['SERVER_ROOT'] + '/' + self.config['SERVER_NAME'] + '/' + self.config['METADATA'], 'rb') as f: doc.Read(f) if doc : self.metadata = doc self.server.SetModel(doc) else: pass #raise error def add_function_import(self, rule, endpoint=None, view_func=None, **options): # This seems terribly hacky but I can't think of another way... funcImport = self.server.model.DataServices[rule] if funcImport : funcImport.bind(view_func, **options) def function_import(self, rule, **options): def decorator(f): endpoint = options.pop('endpoint', None) self.add_function_import(rule, endpoint, f, **options) return f return decorator def make_containers(self) : for schema in self.metadata.root.DataServices.Schema : self.make_container(schema) def make_container(self, schema) : for entity_container in schema.EntityContainer : entity_name = schema.Name + '.' + entity_container.Name if (self.config["DATASOURCES"][entity_name]) : ctype = self.config["DATASOURCES"][entity_name]['dbapi'] if (ctype == 'psycopg2') : container = PgSQLEntityContainer( pgsql_options = self.config["DATASOURCES"][entity_name]['config'], container=self.metadata.root.DataServices[entity_name] )
parser.add_argument('-model', type=str, help='-model model\'s path') parser.add_argument('-iterations', type=int, help='-iteration number of epoches') parser.add_argument('-finetune', type=str, help='-finetune base-model path') parser.add_argument('-net', type=str, help='-RNN or CNN') args = parser.parse_args() doc = load_metadata() container = InMemoryEntityContainer( doc.root.DataServices['MemCacheSchema.MemCache']) mem_cache = doc.root.DataServices['MemCacheSchema.MemCache.KeyValuePairs'] server = Server(serviceRoot=SERVICE_ROOT) server.set_model(doc) # The server is now ready to serve forever global cache_app cache_app = server t = threading.Thread(target=run_cache_server) t.setDaemon(True) t.start() logging.info("MemCache starting HTTP server on %s" % SERVICE_ROOT) print(args) m1 = 0 m2 = 0 global net_type net_type = args.net