1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# 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 logging
import os
from gi.repository import Gtk
from gettext import gettext as _
from jarabe import config
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 = self._get_services()
if len(services) == 0:
label = Gtk.Label(_('No web services are installed.\n\
Please visit http://wiki.sugarlabs.org/WebServices for more details.'))
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
def _get_services(self):
services = []
service_paths = [os.path.join(config.ext_path,
'cpsection',
'webservices',
'services'),
os.path.join(os.path.expanduser('~'),
'.sugar',
'extensions',
'cpsection',
'webservices',
'services')]
for service_path in service_paths:
if os.path.exists(service_path):
folders = os.listdir(service_path)
for f in folders:
if not os.path.isdir(os.path.join(service_path, f)):
continue
if not os.path.exists(os.path.join(service_path, f,
'service.py')):
continue
try:
logging.exception('Found webservice %s' % (f))
mod_name = \
'cpsection.webservices.services.%s.service' % (f)
mod = __import__(mod_name,
globals(),
locals(),
['service'])
if hasattr(mod, 'get_service'):
services.append(mod.get_service())
except Exception as e:
logging.exception(
'Exception while loading extension %s: %s' %
(f, str(e)))
return services
|