Skip to content

Commit

Permalink
Merge pull request #2 from Saumya-Mishra9129/major
Browse files Browse the repository at this point in the history
GConf to GioSettings and python3 port
  • Loading branch information
quozl committed Apr 24, 2020
2 parents cfdea05 + 6438c3c commit 3246b03
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 72 deletions.
6 changes: 3 additions & 3 deletions activity.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import json
import subprocess
from time import sleep
from ConfigParser import ConfigParser
from configparser import ConfigParser
from gettext import gettext as _

from gi.repository import Gio
Expand Down Expand Up @@ -441,7 +441,7 @@ def _select_file_button_cb(self, widget, i):
fd = open(usb_data_path, 'w')
fd.write(json_data)
fd.close()
except Exception, e:
except Exception as e:
write_failed = True
_logger.error('Could not write to USB %s: %s' %
(usb_data_path, e))
Expand Down Expand Up @@ -614,7 +614,7 @@ def count_completed(data):
fd = open(usb_data_path, 'w')
fd.write(json_data)
fd.close()
except Exception, e:
except Exception as e:
self._fatal_error = True
_logger.error('Fatal error: could not write to %s: %s' %
(usb_data_path, e))
Expand Down
2 changes: 1 addition & 1 deletion activity/activity.info
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[Activity]
name = Sugar Labs Academy
exec = sugar-activity activity.TrainingActivity
exec = sugar-activity3 activity.TrainingActivity
bundle_id = org.sugarlabs.Training
icon = sugar-labs-academy
activity_version = 3.6
Expand Down
8 changes: 4 additions & 4 deletions graphics.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import WebKit
from gi.repository import WebKit2

from sugar3.graphics import style
from sugar3.graphics.icon import Icon
Expand All @@ -28,7 +28,7 @@
'x-large', 'x-large', 'x-large', 'xx-large', 'xx-large',
'xx-large']


ZOOM_ORIGINAL = style.zoom(100*100 / 72) / 100.0
class Graphics(Gtk.Alignment):
''' An aligned grid in a scrolling window '''

Expand Down Expand Up @@ -166,11 +166,11 @@ def add_text_icon_and_button(self, text, icon_name,
return button

def add_uri(self, uri, height=610):
self._web_view = WebKit.WebView()
self._web_view = WebKit2.WebView()
width = Gdk.Screen.width() - style.GRID_CELL_SIZE
height = int(height * Gdk.Screen.height() / 900.)
self._web_view.set_size_request(width, height)
self._web_view.set_full_content_zoom(True)
self._web_view.set_zoom_level(ZOOM_ORIGINAL)
self._web_view.load_uri(uri)
self._attach(self._web_view)
self._web_view.show()
Expand Down
12 changes: 6 additions & 6 deletions reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import json
import logging

from gi.repository import GConf

from gi.repository import Gio
from gi.repository import GObject
from gi.repository import Soup
Expand Down Expand Up @@ -57,15 +57,15 @@ def _extract_tasks(data):

class Reporter(GObject.GObject):

URL = '/desktop/sugar/services/training/url'
API_KEY = '/desktop/sugar/services/training/api_key'
URL = '/training/url'
API_KEY = 'training/api_key'
TYPE = 'application/json'

def __init__(self, activity):
GObject.GObject.__init__(self)
client = GConf.Client.get_default()
self._url = client.get_string(self.URL)
self._api_key = client.get_string(self.API_KEY)
settings = Gio.Settings('org.sugarlabs.services')
self._url = settings.get_string(self.URL)
self._api_key = settings.get_string(self.API_KEY)
self._activity = activity

def report(self, tasks_data_list):
Expand Down
19 changes: 10 additions & 9 deletions soupdesk.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import json

from gi.repository import GConf
from gi.repository import Gio
from gi.repository import Soup


Expand All @@ -21,12 +21,12 @@ class ZendeskError(Exception):

class FieldHelper(object):

IDS = '/desktop/sugar/services/zendesk/fields'
IDS = 'zendesk/fields'

def __init__(self):
# FIXME #3926 GConf get_list is missing
client = GConf.Client.get_default()
raw = client.get(self.IDS)
settings = Gio.Settings('org.sugarlabs.services')
raw = settings.get(self.IDS)
if not raw:
raise ZendeskError('soupdesk is missing fields')
self._ids = [int(e.get_string()) for e in raw.get_list()]
Expand All @@ -40,13 +40,14 @@ def get_field(self, index, value):

class Request(object):

URL = '/desktop/sugar/services/zendesk/url'
TOKEN = '/desktop/sugar/services/zendesk/token'
URL = 'zendesk/url'
TOKEN = 'zendesk/token'

def __init__(self):
client = GConf.Client.get_default()
self._url = client.get_string(self.URL)
self._token = client.get_string(self.TOKEN)
settings = Gio.Settings('org.sugarlabs.services')
self._url = settings.get_string(self.URL)

self._token = settings.get_string(self.TOKEN)
self._data = None

if not self._url or not self._token:
Expand Down
20 changes: 10 additions & 10 deletions taskmaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,7 @@ def read_task_data(self, uid=None):
fd = open(usb_data_path, 'r')
json_data = fd.read()
fd.close()
except Exception, e:
except Exception as e:
# Maybe USB key has been pulled?
_logger.error('Could not read from %s: %s' %
(usb_data_path, e))
Expand All @@ -682,7 +682,7 @@ def read_task_data(self, uid=None):
try:
if len(json_data) > 0:
data = json.loads(json_data)
except ValueError, e:
except ValueError as e:
_logger.error('Cannot read training data: %s' % e)
usb_read_failed = True

Expand All @@ -696,14 +696,14 @@ def read_task_data(self, uid=None):
fd = open(sugar_data_path, 'r')
json_data = fd.read()
fd.close()
except Exception, e:
except Exception as e:
json_data = ''
_logger.error('Could not read from %s: %s' %
(sugar_data_path, e))
if len(json_data) > 0:
try:
data = json.loads(json_data)
except ValueError, e:
except ValueError as e:
_logger.error('Cannot load training data: %s' % e)

if uid is None:
Expand Down Expand Up @@ -737,7 +737,7 @@ def write_task_data(self, uid, uid_data):
fd = open(usb_data_path, 'r')
json_data = fd.read()
fd.close()
except Exception, e:
except Exception as e:
# Maybe USB key has been pulled?
_logger.error('Could not read from %s: %s' %
(usb_data_path, e))
Expand All @@ -746,7 +746,7 @@ def write_task_data(self, uid, uid_data):
if len(json_data) > 0:
try:
data = json.loads(json_data)
except ValueError, e:
except ValueError as e:
_logger.error('Cannot load training data: %s' % e)
usb_read_failed = True

Expand All @@ -757,15 +757,15 @@ def write_task_data(self, uid, uid_data):
fd = open(sugar_data_path, 'r')
json_data = fd.read()
fd.close()
except Exception, e:
except Exception as e:
_logger.error('Could not read from %s: %s' %
(sugar_data_path, e))
json_data = ''
sugar_read_failed = True
if len(json_data) > 0:
try:
data = json.loads(json_data)
except ValueError, e:
except ValueError as e:
_logger.error('Cannot load training data: %s' % e)
sugar_read_failed = True

Expand All @@ -787,7 +787,7 @@ def write_task_data(self, uid, uid_data):
fd = open(usb_data_path, 'w')
fd.write(json_data)
fd.close()
except Exception, e:
except Exception as e:
_logger.error('Could not write to USB %s: %s' %
(usb_data_path, e))
_logger.error('write_task_data: Resync required')
Expand All @@ -802,7 +802,7 @@ def write_task_data(self, uid, uid_data):
if usb_read_failed:
_logger.error('write_task_data: Resync required')
self._resync_required = True
except Exception, e:
except Exception as e:
_logger.error('Could not write to Sugar %s: %s' %
(sugar_data_path, e))

Expand Down
10 changes: 5 additions & 5 deletions tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ def _role_button_callback(self, widget, roll):
for button in self._buttons:
button.set_sensitive(not button == widget)
self._role = 'Other'
for key in _ROLES.keys():
for key in list(_ROLES.keys()):
if _ROLES[key][0] == roll:
self._role = key
_logger.debug(self._role)
Expand Down Expand Up @@ -1239,7 +1239,7 @@ def get_graphics(self):
self._buttons = graphics.add_list_buttons(roles)
for i, button in enumerate(self._buttons):
button.connect('clicked', self._role_button_callback, roles[i])
if self._role in _ROLES.keys() and \
if self._role in list(_ROLES.keys()) and \
_ROLES[self._role][0] == roles[i]:
button.set_sensitive(False)
if self._role == 'Other':
Expand Down Expand Up @@ -1852,7 +1852,7 @@ def test(self, task_data):
# (self._name, len(utils.get_favorites().keys()),
# self._task_master.activity.favorites_count))
# return len(utils.get_favorites().keys()) > task_data['data']
return len(utils.get_favorites().keys()) > \
return len(list(utils.get_favorites().keys())) > \
self._task_master.activity.favorites_count


Expand Down Expand Up @@ -1895,7 +1895,7 @@ def test(self, task_data):
# (self._name, len(utils.get_favorites().keys()),
# self._task_master.activity.favorites_count))
# return len(utils.get_favorites().keys()) < task_data['data']
return len(utils.get_favorites().keys()) < \
return len(list(utils.get_favorites().keys())) < \
self._task_master.activity.favorites_count

class Views7Task(HTMLTask):
Expand Down Expand Up @@ -2697,7 +2697,7 @@ def get_graphics(self):
else:
role = None

for key in _ROLES.keys():
for key in list(_ROLES.keys()):
if key == role:
role = _ROLES[key][0]
self._yes_no_required = _ROLES[key][1]
Expand Down
Loading

0 comments on commit 3246b03

Please sign in to comment.