From e0a046cd5353cdeab2bee7bab37d8c7da8289153 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Mon, 15 May 2006 12:27:36 -0400 Subject: [PATCH] Split the model classes in different files --- configure.ac | 1 + sugar/p2p/Makefile.am | 1 - sugar/p2p/{Model.py => model/LocalModel.py} | 38 ++------------------- sugar/p2p/model/Makefile.am | 6 ++++ sugar/p2p/model/RemoteModel.py | 17 +++++++++ sugar/p2p/model/Store.py | 22 ++++++++++++ 6 files changed, 48 insertions(+), 37 deletions(-) rename sugar/p2p/{Model.py => model/LocalModel.py} (59%) create mode 100644 sugar/p2p/model/Makefile.am create mode 100644 sugar/p2p/model/RemoteModel.py create mode 100644 sugar/p2p/model/Store.py diff --git a/configure.ac b/configure.ac index 0828bda5..e31440d0 100644 --- a/configure.ac +++ b/configure.ac @@ -22,5 +22,6 @@ sugar/__installed__.py sugar/browser/Makefile sugar/chat/Makefile sugar/p2p/Makefile +sugar/p2p/model/Makefile sugar/shell/Makefile ]) diff --git a/sugar/p2p/Makefile.am b/sugar/p2p/Makefile.am index 334e7b6a..be343601 100644 --- a/sugar/p2p/Makefile.am +++ b/sugar/p2p/Makefile.am @@ -3,7 +3,6 @@ sugar_PYTHON = \ __init__.py \ Buddy.py \ Group.py \ - Model.py \ Service.py \ StreamReader.py \ StreamWriter.py \ diff --git a/sugar/p2p/Model.py b/sugar/p2p/model/LocalModel.py similarity index 59% rename from sugar/p2p/Model.py rename to sugar/p2p/model/LocalModel.py index 0148c742..b268a5dc 100644 --- a/sugar/p2p/Model.py +++ b/sugar/p2p/model/LocalModel.py @@ -1,24 +1,10 @@ -MODEL_SERVICE_TYPE = "_olpc_model._tcp" -MODEL_SERVICE_PORT = 6300 - import socket import xmlrpclib from sugar.p2p.Service import Service -import network -class RemoteModel: - def __init__(self, service): - self._service = service - - addr = "http://%s:%d" % (service.get_address(), service.get_port()) - self._client = xmlrpclib.ServerProxy(addr) - - def get_value(self, key): - return self._client.get_value(key) - - def set_value(self, key, value): - self._client.set_value(key, value) +MODEL_SERVICE_TYPE = "_olpc_model._tcp" +MODEL_SERVICE_PORT = 6300 class ModelRequestHandler(object): def __init__(self, model): @@ -64,23 +50,3 @@ class LocalModel: port = port + 1 tries = tries - 1 service.set_port(port) - -class Store: - def __init__(self, group): - self._group = group - self._local_models = {} - - def create_model(self, model_id): - model = LocalModel(self._group, model_id) - self._local_models[model_id] = model - return model - - def get_model(self, model_id): - if self._local_models.has_key(model_id): - return self._local_models(model_id) - else: - service = self._group.get_service(model_id, MODEL_SERVICE_TYPE) - if service: - return RemoteModel(service) - else: - return None diff --git a/sugar/p2p/model/Makefile.am b/sugar/p2p/model/Makefile.am new file mode 100644 index 00000000..c828a086 --- /dev/null +++ b/sugar/p2p/model/Makefile.am @@ -0,0 +1,6 @@ +sugardir = $(pythondir)/sugar/p2p/model +sugar_PYTHON = \ + __init__.py \ + LocalModel.py \ + RemoteModel.py \ + Store.py diff --git a/sugar/p2p/model/RemoteModel.py b/sugar/p2p/model/RemoteModel.py new file mode 100644 index 00000000..4492fe9b --- /dev/null +++ b/sugar/p2p/model/RemoteModel.py @@ -0,0 +1,17 @@ +import xmlrpclib + +from sugar.p2p.Service import Service +import network + +class RemoteModel: + def __init__(self, service): + self._service = service + + addr = "http://%s:%d" % (service.get_address(), service.get_port()) + self._client = xmlrpclib.ServerProxy(addr) + + def get_value(self, key): + return self._client.get_value(key) + + def set_value(self, key, value): + self._client.set_value(key, value) diff --git a/sugar/p2p/model/Store.py b/sugar/p2p/model/Store.py new file mode 100644 index 00000000..ae86dc1b --- /dev/null +++ b/sugar/p2p/model/Store.py @@ -0,0 +1,22 @@ +from sugar.p2p.model.RemoteModel import RemoteModel +from sugar.p2p.model.LocalModel import LocalModel + +class Store: + def __init__(self, group): + self._group = group + self._local_models = {} + + def create_model(self, model_id): + model = LocalModel(self._group, model_id) + self._local_models[model_id] = model + return model + + def get_model(self, model_id): + if self._local_models.has_key(model_id): + return self._local_models(model_id) + else: + service = self._group.get_service(model_id, MODEL_SERVICE_TYPE) + if service: + return RemoteModel(service) + else: + return None