Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAleksey Lim <alsroot@sugarlabs.org>2012-06-04 01:10:59 (GMT)
committer Aleksey Lim <alsroot@sugarlabs.org>2012-06-04 01:10:59 (GMT)
commit72ffb031c25c8506f9f0f897086377a8a797ed03 (patch)
tree04d7af2b70c481a5658e6d1e9dfaa47ab302b349
parenteb8a5d16101df0b9348033a6a43e1b7526f4bbdb (diff)
Move local Context props to sugar_network_server; move webui related props to sugar_nework_webui
-rw-r--r--local_document/context.py41
-rw-r--r--local_document/env.py8
-rw-r--r--local_document/mounts.py13
-rwxr-xr-xsugar-network-service25
-rw-r--r--sugar_network/__init__.py4
-rw-r--r--tests/__init__.py2
-rwxr-xr-xtests/units/activities.py2
-rwxr-xr-xtests/units/client.py2
-rwxr-xr-xtests/units/injector.py2
-rwxr-xr-xtests/units/mounts.py2
10 files changed, 29 insertions, 72 deletions
diff --git a/local_document/context.py b/local_document/context.py
deleted file mode 100644
index a1a456f..0000000
--- a/local_document/context.py
+++ /dev/null
@@ -1,41 +0,0 @@
-# Copyright (C) 2012 Aleksey Lim
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-import active_document as ad
-from sugar_network_server.resources.context import Context as _Context
-
-
-class Context(_Context):
-
- LOCAL_PROPS = {
- 'keep': False,
- 'keep_impl': 0,
- 'position': (-1, -1),
- }
-
- @ad.active_property(prefix='LK', typecast=bool,
- default=LOCAL_PROPS['keep'])
- def keep(self, value):
- return value
-
- @ad.active_property(prefix='LI', typecast=[0, 1, 2],
- default=LOCAL_PROPS['keep_impl'])
- def keep_impl(self, value):
- return value
-
- @ad.active_property(ad.StoredProperty, typecast=[int],
- default=LOCAL_PROPS['position'])
- def position(self, value):
- return value
diff --git a/local_document/env.py b/local_document/env.py
index 4a6cc13..e241929 100644
--- a/local_document/env.py
+++ b/local_document/env.py
@@ -49,14 +49,6 @@ server_mode = optparse.Option(
default=False, type_cast=optparse.Option.bool_cast,
action='store_true', name='server-mode')
-webui = optparse.Option(
- _('start web application to serve Sugar Network content'),
- default=True, type_cast=optparse.Option.bool_cast, action='store_true')
-
-webui_port = optparse.Option(
- _('address to listen for Web clients'),
- default=5000, type_cast=int, name='webui-port')
-
delayed_start = optparse.Option(
_('immediate start only database and the rest on getting ' \
'notification from IPC client'),
diff --git a/local_document/mounts.py b/local_document/mounts.py
index 2d58c5d..fab4191 100644
--- a/local_document/mounts.py
+++ b/local_document/mounts.py
@@ -25,13 +25,18 @@ import zerosugar
import sweets_recipe
import active_document as ad
from local_document import activities, sugar, http, env, zeroconf
-from local_document.context import Context
from active_toolkit import sockets, util, coroutine, enforce
# TODO Incremental timeout
_RECONNECTION_TIMEOUT = 3
+_LOCAL_PROPS = {
+ 'keep': False,
+ 'keep_impl': 0,
+ 'position': (-1, -1),
+ }
+
_logger = logging.getLogger('local_document.mounts')
@@ -202,7 +207,7 @@ class _LocalMount(ad.ProxyCommands, _Mount):
props = event.pop('props')
found_commons = False
- for prop in Context.LOCAL_PROPS.keys():
+ for prop in _LOCAL_PROPS.keys():
if prop not in props:
continue
if prop == 'keep_impl':
@@ -289,13 +294,13 @@ class _RemoteMount(ad.CommandsProcessor, _Mount):
if command == ('GET', None):
if 'reply' in request:
reply = request.get('reply', [])[:]
- for prop, default in Context.LOCAL_PROPS.items():
+ for prop, default in _LOCAL_PROPS.items():
if prop in reply:
patch[prop] = default
reply.remove(prop)
request['reply'] = reply
elif command in (('POST', None), ('PUT', None)):
- for prop in Context.LOCAL_PROPS.keys():
+ for prop in _LOCAL_PROPS.keys():
if prop in request.content:
patch[prop] = request.content.pop(prop)
if not request.content:
diff --git a/sugar-network-service b/sugar-network-service
index 50ecc2f..9c3d0d5 100755
--- a/sugar-network-service
+++ b/sugar-network-service
@@ -22,9 +22,10 @@ from gettext import gettext as _
import active_document as ad
import restful_document as rd
import sugar_network_server as server
+import sugar_network_webui as webui
+
from local_document import application, sugar, env, bus, activities
from local_document.mounts import Mounts
-from local_document.context import Context
from sugar_network import bus as client
from active_toolkit import optparse, coroutine, enforce
@@ -169,26 +170,22 @@ class Application(application.Daemon):
self._monitor = coroutine.spawn(activities.monitor, self._home_volume,
self._activity_directories)
- if env.webui.value:
- from sugar_network_webui import app
-
- logging.info(_('Start Web server on %s port'),
- env.webui_port.value)
-
- self._web_server = coroutine.WSGIServer(
- ('127.0.0.1', env.webui_port.value), app)
+ if webui.webui.value:
+ # Point client API to `self._mounts` directly passing over IPC
+ client.Request.connection = self._mounts
+ host = (webui.webui_host.value, webui.webui_port.value)
+ logging.info(_('Start Web server on %s:%s port'), *host)
+ self._web_server = coroutine.WSGIServer(host, webui.get_app())
coroutine.spawn(self._web_server.serve_forever)
def _mount(self, server_mode):
if server_mode:
- documents = [Context] + server.documents()
+ documents = server.documents()
else:
- documents = [Context] + server.documents(['report'])
+ documents = server.documents(['context', 'report'])
self._home_volume = ad.SingleVolume(self._db_path, documents)
server.volume.update(self._home_volume)
self._mounts = Mounts(self._home_volume)
- # Point client API to `self._mounts` directly passing over IPC
- client.Request.connection = self._mounts
def _populate_index(self):
for cls in self._home_volume.values():
@@ -200,10 +197,12 @@ class Application(application.Daemon):
application.debug.value = sugar.logger_level()
rd.only_sync_notification.value = False
ad.index_lazy_open.value = True
+webui.webui.value = True
# It seems to be that most of users (on XO at least) don't have recent SSH
server.trust_users.value = True
optparse.Option.seek('main', [application.debug, application.foreground])
+optparse.Option.seek('webui', webui)
optparse.Option.seek('sugar-network', env)
optparse.Option.seek('sugar-network-server',
[server.port, server.subscribe_port])
diff --git a/sugar_network/__init__.py b/sugar_network/__init__.py
index fd49afd..09e95c2 100644
--- a/sugar_network/__init__.py
+++ b/sugar_network/__init__.py
@@ -19,4 +19,6 @@ from local_document import sugar, application
from sugar_network.client import Client, checkins
-from local_document.env import api_url, server_mode, webui_port
+from local_document.env import api_url, server_mode
+
+from sugar_network_webui import webui_port
diff --git a/tests/__init__.py b/tests/__init__.py
index d74610c..39a492f 100644
--- a/tests/__init__.py
+++ b/tests/__init__.py
@@ -13,6 +13,7 @@ import restful_document as rd
from active_toolkit import coroutine
from sugar_network_server import env as server_env
from sugar_network_server.resources.user import User
+from sugar_network_server.resources.context import Context
from restful_document.router import Router
from restful_document.subscribe_socket import SubscribeSocket
from local_document import env, sugar
@@ -20,7 +21,6 @@ from local_document.bus import Server
from sugar_network import client
from sugar_network.bus import Request
from local_document.mounts import Mounts
-from local_document.context import Context
root = abspath(dirname(__file__))
tmproot = join(root, '.tmp')
diff --git a/tests/units/activities.py b/tests/units/activities.py
index ada2bcf..57e0fb4 100755
--- a/tests/units/activities.py
+++ b/tests/units/activities.py
@@ -10,11 +10,11 @@ from __init__ import tests
import active_document as ad
from sugar_network_server.resources.user import User
+from sugar_network_server.resources.context import Context
from sugar_network_server import env as server_env
from active_toolkit import coroutine
from local_document.mounts import Mounts
from local_document import activities, sugar
-from local_document.context import Context
class ActivitiesTest(tests.Test):
diff --git a/tests/units/client.py b/tests/units/client.py
index 687be6b..acb65c4 100755
--- a/tests/units/client.py
+++ b/tests/units/client.py
@@ -10,11 +10,11 @@ import active_document as ad
from active_toolkit import coroutine
from sugar_network_server.resources.user import User
+from sugar_network_server.resources.context import Context
from sugar_network.client import Client
from sugar_network.bus import Request
from local_document.bus import Server
from local_document import mounts
-from local_document.context import Context
class ClientTest(tests.Test):
diff --git a/tests/units/injector.py b/tests/units/injector.py
index f36e3b2..bd59744 100755
--- a/tests/units/injector.py
+++ b/tests/units/injector.py
@@ -14,9 +14,9 @@ import zerosugar
from active_toolkit import coroutine
from sugar_network.client import Client
from sugar_network_server.resources.user import User
+from sugar_network_server.resources.context import Context
from sugar_network_server.resources.implementation import Implementation
from local_document import activities
-from local_document.context import Context
class InjectorTest(tests.Test):
diff --git a/tests/units/mounts.py b/tests/units/mounts.py
index ec5aa60..1533493 100755
--- a/tests/units/mounts.py
+++ b/tests/units/mounts.py
@@ -22,7 +22,7 @@ from local_document.mounts import Mounts
from local_document.bus import Server
from local_document import env, mounts, sugar, http, activities
from sugar_network_server.resources.user import User
-from local_document.context import Context
+from sugar_network_server.resources.context import Context
class MountsTest(tests.Test):