Skip to content

Commit

Permalink
Add webaccount/webservice extension support
Browse files Browse the repository at this point in the history
This is another patch in a series of patches for interacting with
online accounts from Sugar.  The relevant feature request is [1].

This patch introduces two new sections in sugar extensions:

(1) webservice is stub for installing webservices; each web service is
installed in a subdirectory of this directory.

(2) cpsection/webaccount is a new control panel section for managing
web service accounts. Account management services are loaded into
individual subdirectories of cpsection/webaccount/services.

A new helper method was also added to
jarabe/webservice/accountsmanager and the unit test as updated accordingly.

Note that this same directory structure can be set up in
env.get_profile_path()/extensions for web services installed by the
end user.

[1] http://wiki.sugarlabs.org/go/Features/Web_services

A first pass at a unit test for the new webaccount cpsection is also
included. For naming consistency, this test was called test_webaccount
while the exsiting test_webaccount was renamed to the more appropriate
test_webservice.
  • Loading branch information
walterbender committed Jun 20, 2013
1 parent da547a6 commit 664b914
Show file tree
Hide file tree
Showing 25 changed files with 374 additions and 5 deletions.
3 changes: 3 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ extensions/cpsection/network/Makefile
extensions/cpsection/power/Makefile
extensions/cpsection/updater/backends/Makefile
extensions/cpsection/updater/Makefile
extensions/cpsection/webaccount/services/Makefile
extensions/cpsection/webaccount/Makefile
extensions/deviceicon/Makefile
extensions/globalkey/Makefile
extensions/webservice/Makefile
extensions/Makefile
Makefile
po/Makefile.in
Expand Down
3 changes: 2 additions & 1 deletion data/icons/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ sugar_DATA = \
module-modemconfiguration.svg \
module-network.svg \
module-power.svg \
module-updater.svg
module-updater.svg \
module-webaccount.svg

EXTRA_DIST = $(sugar_DATA)
15 changes: 15 additions & 0 deletions data/icons/module-webaccount.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion extensions/Makefile.am
Original file line number Diff line number Diff line change
@@ -1 +1 @@
SUBDIRS = cpsection deviceicon globalkey
SUBDIRS = cpsection deviceicon globalkey webservice
2 changes: 1 addition & 1 deletion extensions/cpsection/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SUBDIRS = aboutme aboutcomputer background datetime frame keyboard language \
modemconfiguration network power updater
modemconfiguration network power updater webaccount

sugardir = $(pkgdatadir)/extensions/cpsection
sugar_PYTHON = __init__.py
2 changes: 2 additions & 0 deletions extensions/cpsection/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
8 changes: 8 additions & 0 deletions extensions/cpsection/webaccount/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
SUBDIRS = services
sugardir = $(pkgdatadir)/extensions/cpsection/webaccount

sugar_PYTHON = \
__init__.py \
model.py \
view.py \
web_service.py
24 changes: 24 additions & 0 deletions extensions/cpsection/webaccount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2013, Walter Bender
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

from gettext import gettext as _
from pkgutil import extend_path

__path__ = extend_path(__path__, __name__)

CLASS = 'WebServicesConfig'
ICON = 'module-webaccount'
TITLE = _('Configure your Web Services')
Empty file.
6 changes: 6 additions & 0 deletions extensions/cpsection/webaccount/services/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SUBDIRS =

sugardir = $(pkgdatadir)/extensions/cpsection/webaccount/services

sugar_PYTHON = \
__init__.py
2 changes: 2 additions & 0 deletions extensions/cpsection/webaccount/services/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
82 changes: 82 additions & 0 deletions extensions/cpsection/webaccount/view.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright (C) 2013, Walter Bender - Raul Gutierrez Segales
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

import glib
from gettext import gettext as _

from gi.repository import Gtk

from jarabe.webservice.accountsmanager import get_webaccount_services
from jarabe.controlpanel.sectionview import SectionView

from sugar3.graphics.icon import CanvasIcon
from sugar3.graphics import style


class WebServicesConfig(SectionView):
def __init__(self, model, alerts):
SectionView.__init__(self)

self._model = model
self.restart_alerts = alerts

services = get_webaccount_services()
if len(services) == 0:
label = Gtk.Label()
label.set_markup(
'<span size="x-large" weight="bold">' +
glib.markup_escape_text(
_('No web services are installed.\n'
'Please visit %s for more details.' %
'http://wiki.sugarlabs.org/go/WebServices')) +
'</span>')
label.show()
self.add(label)
return

vbox = Gtk.VBox()
hbox = Gtk.HBox(style.DEFAULT_SPACING)

self._service_config_box = Gtk.VBox()

for service in services:
icon = CanvasIcon(icon_name=service.get_icon_name())
icon.connect('button_press_event',
service.config_service_cb,
self._service_config_box)
icon.show()
hbox.pack_start(icon, False, False, 0)

hbox.show()
vbox.pack_start(hbox, False, False, 0)

scrolled = Gtk.ScrolledWindow()
vbox.pack_start(scrolled, True, True, 0)

self.add(vbox)
scrolled.set_policy(Gtk.PolicyType.NEVER, Gtk.PolicyType.AUTOMATIC)
scrolled.show()

workspace = Gtk.VBox()
scrolled.add_with_viewport(workspace)
workspace.show()

workspace.add(self._service_config_box)
workspace.show_all()
vbox.show()

def undo(self):
pass
23 changes: 23 additions & 0 deletions extensions/cpsection/webaccount/web_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) 2013, Walter Bender - Raul Gutierrez Segales
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


class WebService():
def get_icon_name(self):
raise "Not implemented"

def config_service_cb(self, widget, event, container):
raise "Not implemented"
5 changes: 5 additions & 0 deletions extensions/webservice/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
SUBDIRS =

sugardir = $(pkgdatadir)/extensions/webservice
sugar_PYTHON = \
__init__.py
2 changes: 2 additions & 0 deletions extensions/webservice/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
2 changes: 2 additions & 0 deletions po/POTFILES.in
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ extensions/cpsection/power/model.py
extensions/cpsection/power/view.py
extensions/cpsection/updater/__init__.py
extensions/cpsection/updater/view.py
extensions/cpsection/webaccount/__init__.py
extensions/cpsection/webaccount/view.py
extensions/deviceicon/battery.py
extensions/deviceicon/frame.py
extensions/deviceicon/network.py
Expand Down
31 changes: 30 additions & 1 deletion src/jarabe/webservice/accountsmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def _get_webservice_paths():
return paths


def get_webaccount_paths():
def _get_webaccount_paths():
paths = []
for path in [os.path.join(_user_extensions_path, 'cpsection',
'webaccount'),
Expand Down Expand Up @@ -218,3 +218,32 @@ def get_active_accounts():

def has_configured_accounts():
return len(get_configured_accounts()) > 0


def get_webaccount_services():
_ensure_module_repository()

service_paths = []
for path in _get_webaccount_paths():
service_paths.append(os.path.join(path, 'services'))

services = []
for service_path in service_paths:
if not os.path.exists(service_path):
continue

folders = os.listdir(service_path)
for folder in folders:
if not os.path.isdir(os.path.join(service_path, folder)):
continue

if not os.path.exists(os.path.join(
service_path, folder, 'service.py')):
continue

module = _load_module(os.path.join(service_path, folder),
'service')
if hasattr(module, 'get_service'):
services.append(module.get_service())

return services
2 changes: 2 additions & 0 deletions tests/extensions/cpsection/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
2 changes: 2 additions & 0 deletions tests/extensions/cpsection/webaccount/services/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
45 changes: 45 additions & 0 deletions tests/extensions/cpsection/webaccount/services/mock/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Copyright (C) 2013, Walter Bender - Raul Gutierrez Segales
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

from gi.repository import Gtk

from jarabe.webservice import accountsmanager

from cpsection.webaccount.web_service import WebService

_SERVICE_NAME = 'mock'


class WebService(WebService):

def __init__(self):
self._account = accountsmanager.get_account(_SERVICE_NAME)

def get_icon_name(self):
return _SERVICE_NAME

def config_service_cb(self, widget, event, container):
label = Gtk.Label(_SERVICE_NAME)

for c in container.get_children():
container.remove(c)

container.add(label)
container.show_all()


def get_service():
return WebService()
23 changes: 23 additions & 0 deletions tests/extensions/cpsection/webaccount/web_service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright (C) 2013, Walter Bender - Raul Gutierrez Segales
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA


class WebService():
def get_icon_name(self):
raise "Not implemented"

def config_service_cb(self, widget, event, container):
raise "Not implemented"
32 changes: 32 additions & 0 deletions tests/test_webaccount.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Copyright (C) 2012, Daniel Narvaez
# Copyright (C) 2013, Walter Bender
#
# 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 2 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, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA

from sugar3.test import unittest
from sugar3.test import uitree

ACCOUNT_NAME = 'mock'


class TestWebAccount(unittest.UITestCase):

def test_webaccount(self):
with self.run_view("webaccount"):
root = uitree.get_root()

for name in [ACCOUNT_NAME]:
node = root.find_child(name=name, role_name='label')
self.assertIsNotNone(node)
Loading

0 comments on commit 664b914

Please sign in to comment.