From 5abcb4e8dd58b28c2b973c3eff4e125abe2d63f5 Mon Sep 17 00:00:00 2001 From: Simon McVittie Date: Tue, 30 Oct 2007 16:10:02 +0000 Subject: [PATCH 1/5] Encode nickname in UTF-8 when writing it out to .sugar/*/config (#4518) --- NEWS | 1 + lib/sugar/profile.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 35554212..a1e802e1 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,4 @@ +* #4518: Encode nickname in UTF-8 when writing it out to .sugar/*/config (smcv) * #4503: Do some standard Tubes boilerplate in sugar.presence, so activities don't have to (smcv) * #4428 Revert to the trial-3 frame behavior (marco) diff --git a/lib/sugar/profile.py b/lib/sugar/profile.py index 10a2b6cc..c150fb16 100644 --- a/lib/sugar/profile.py +++ b/lib/sugar/profile.py @@ -87,7 +87,7 @@ class Profile(object): parsed = cp.read([self._config_path]) if self.nick_name: - _set_key(cp, 'Buddy', 'NickName', self.nick_name) + _set_key(cp, 'Buddy', 'NickName', self.nick_name.encode('utf8')) if self.color: _set_key(cp, 'Buddy', 'Color', self.color.to_string()) if self.backup1: From 4ee3e65bc56d575c5bfc83d92e95cf3482ec8dd4 Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Wed, 31 Oct 2007 09:59:35 +0100 Subject: [PATCH 2/5] sugar-control: Use NM for radio on/off, check for superuser --- NEWS | 2 + shell/controlpanel/control.py | 104 ++++++++++++++++++++-------------- 2 files changed, 65 insertions(+), 41 deletions(-) diff --git a/NEWS b/NEWS index b4d9c05a..c0d6553f 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,5 @@ +* sugar-control: Use NM for radio on/off, check for superuser (erikos) + Snapshot b72f00e30b * #4517 Do not require a TakeScreenshot method on the dbus service (marco) diff --git a/shell/controlpanel/control.py b/shell/controlpanel/control.py index 89870514..28922b80 100644 --- a/shell/controlpanel/control.py +++ b/shell/controlpanel/control.py @@ -27,10 +27,15 @@ import os import string import shutil from gettext import gettext as _ +import dbus from sugar import profile from sugar.graphics.xocolor import XoColor +NM_SERVICE_NAME = 'org.freedesktop.NetworkManager' +NM_SERVICE_PATH = '/org/freedesktop/NetworkManager' +NM_SERVICE_IFACE = 'org.freedesktop.NetworkManager' +NM_ASLEEP = 1 _COLORS = {'red': {'dark':'#b20008', 'medium':'#e6000a', 'light':'#ffadce'}, 'orange': {'dark':'#9a5200', 'medium':'#c97e00', 'light':'#ffc169'}, @@ -184,25 +189,16 @@ _LANGUAGES = { 'Zulu/South_Africa': ('zu_ZA.UTF-8', 'latarcyrheb-sun16') } -_timezones = [] def _initialize(): - _timezones = _read_zonetab() + timezones = _read_zonetab() + j=0 - for timezone in _timezones: + for timezone in timezones: set_timezone.__doc__ += timezone+', ' j+=1 if j%3 == 0: set_timezone.__doc__ += '\n' - - if not os.access(_TIMEZONE_CONFIG, os.R_OK): - #Theres no /etc/sysconfig/clock file, so make one - fd = open(_TIMEZONE_CONFIG, 'w') - f.write(' The ZONE parameter is only evaluated by sugarcontrol.\n') - f.write('The timezone of the system' + - ' is defined by the contents of /etc/localtime.\n') - f.write('ZONE="America/NEW_York"\n') - f.close() keys = _LANGUAGES.keys() keys.sort() @@ -282,30 +278,50 @@ def set_nick(nick): pro.nick_name = nick pro.save() -def get_radio(state): - return '' +def get_radio(): + bus = dbus.SystemBus() + proxy = bus.get_object(NM_SERVICE_NAME, NM_SERVICE_PATH) + nm = dbus.Interface(proxy, NM_SERVICE_IFACE) + state = nm.state() + if state: + if state == NM_ASLEEP: + return _('Asleep') + else: + return _('Awake') + return _('State is unknown.') -def print_radio(self): +def print_radio(): print get_radio() def set_radio(state): """Turn Radio off state : 'on/off' """ + + # TODO: NM 0.6.x does not return a reply yet + # so we ignore it for the moment + if state == 'on': - cmd = '/sbin/iwconfig eth0 txpower on' - handle = os.popen(cmd, 'r') - print string.join(handle.readlines()) - handle.close() + dbus.SystemBus().call_async(NM_SERVICE_NAME, NM_SERVICE_PATH, + NM_SERVICE_IFACE, 'wake', '', (), + None, None) elif state == 'off': - cmd = '/sbin/iwconfig eth0 txpower off' - handle = os.popen(cmd, 'r') - print string.join(handle.readlines()) - handle.close() + dbus.SystemBus().call_async(NM_SERVICE_NAME, NM_SERVICE_PATH, + NM_SERVICE_IFACE, 'sleep', '', (), + None, None) else: print (_("Error in specified radio argument use on/off.")) - + +def _check_for_superuser(): + if os.getuid(): + print _("Permission denied. You need to be root to run this method.") + return False + return True + def get_timezone(): + if not os.access(_TIMEZONE_CONFIG, os.R_OK): + # this is what the default is for the /etc/localtime + return "America/New_York" fd = open(_TIMEZONE_CONFIG, "r") lines = fd.readlines() fd.close() @@ -331,12 +347,30 @@ def print_timezone(): print (_("Error in reading timezone")) else: print timezone - + +def _read_zonetab(fn='/usr/share/zoneinfo/zone.tab'): + fd = open (fn, 'r') + lines = fd.readlines() + fd.close() + timezones = [] + for line in lines: + if line.startswith('#'): + continue + line = line.split() + if len(line) > 1: + timezones.append(line[2]) + timezones.sort() + return timezones + def set_timezone(timezone): """Set the system timezone timezone : """ - if timezone in _timezones: + if not _check_for_superuser(): + return + + timezones = _read_zonetab() + if timezone in timezones: fromfile = os.path.join("/usr/share/zoneinfo/", timezone) try: shutil.copyfile(fromfile, "/etc/localtime") @@ -358,20 +392,6 @@ def set_timezone(timezone): fd.close() else: print (_("Error timezone does not exist.")) - -def _read_zonetab(fn='/usr/share/zoneinfo/zone.tab'): - fd = open (fn, 'r') - lines = fd.readlines() - fd.close() - timezones = [] - for line in lines: - if line.startswith('#'): - continue - line = line.split() - if len(line) > 1: - timezones.append(line[2]) - timezones.sort() - return timezones def _writeI18N(lang, sysfont): path = '/etc/sysconfig/i18n' @@ -418,11 +438,13 @@ def set_language(language): """Set the system language. languages : """ + if not _check_for_superuser(): + return if language in _LANGUAGES: _writeI18N(_LANGUAGES[language][0], _LANGUAGES[language][1]) else: print (_("Sorry I do not speak \'%s\'.")%language) - # inilialize the docstrings for the timezone and language _initialize() + From 38b87ad7cd1f7620c5c8f615bfc18b693c46053e Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Wed, 31 Oct 2007 10:36:38 +0100 Subject: [PATCH 3/5] sugar-control: add env import --- bin/sugar-control-panel | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bin/sugar-control-panel b/bin/sugar-control-panel index d978fed7..489cf72f 100755 --- a/bin/sugar-control-panel +++ b/bin/sugar-control-panel @@ -20,6 +20,8 @@ import sys import getopt +from sugar import env + sys.path.insert(0, env.get_shell_path()) import control From 14ffdc1d03f93e76ae0f7e483c006ce76f61dd23 Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Wed, 31 Oct 2007 11:32:54 +0100 Subject: [PATCH 4/5] sugar-control: fixed some imports, cleaned some strings --- bin/sugar-control-panel | 2 +- shell/controlpanel/Makefile.am | 4 +++- shell/controlpanel/control.py | 20 ++++++++++---------- 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/bin/sugar-control-panel b/bin/sugar-control-panel index 489cf72f..367372d8 100755 --- a/bin/sugar-control-panel +++ b/bin/sugar-control-panel @@ -24,7 +24,7 @@ from sugar import env sys.path.insert(0, env.get_shell_path()) -import control +from controlpanel import control def cmd_help(): print 'Usage: sugar-control [ option ] key [ args ... ] \n\ diff --git a/shell/controlpanel/Makefile.am b/shell/controlpanel/Makefile.am index 353aeec0..b7721707 100644 --- a/shell/controlpanel/Makefile.am +++ b/shell/controlpanel/Makefile.am @@ -1,2 +1,4 @@ sugardir = $(pkgdatadir)/shell/controlpanel -sugar_PYTHON = control.py +sugar_PYTHON = \ + __init__.py \ + control.py diff --git a/shell/controlpanel/control.py b/shell/controlpanel/control.py index 28922b80..02ddfe38 100644 --- a/shell/controlpanel/control.py +++ b/shell/controlpanel/control.py @@ -218,7 +218,7 @@ def print_jabber(): def set_jabber(server): """Set the jabber server - server : 'olpc.collabora.co.uk' + server : e.g. 'olpc.collabora.co.uk' """ pro = profile.get_profile() pro.jabber_server = server @@ -239,11 +239,11 @@ def print_color(): print 'fill: color=%s hue=%s'%(color, hue) def set_color(stroke, fill, modstroke='medium', modfill='medium'): - """Set the system color. - fill : 'red, orange, yellow, blue, purple' - stroke : 'red, orange, yellow, blue, purple' - modstroke : 'dark, medium, light' - modfill : ''dark, medium, light' + """Set the system color by setting a fill and stroke color. + fill : [red, orange, yellow, blue, purple] + stroke : [red, orange, yellow, blue, purple] + hue stroke : [dark, medium, light] (optional) + hue fill : [dark, medium, light] (optional) """ if modstroke not in _MODIFIERS or modfill not in _MODIFIERS: @@ -272,7 +272,7 @@ def print_nick(): def set_nick(nick): """Set the nickname. - nick : 'erikos' + nick : e.g. 'walter' """ pro = profile.get_profile() pro.nick_name = nick @@ -285,16 +285,16 @@ def get_radio(): state = nm.state() if state: if state == NM_ASLEEP: - return _('Asleep') + return _('off') else: - return _('Awake') + return _('on') return _('State is unknown.') def print_radio(): print get_radio() def set_radio(state): - """Turn Radio off + """Turn Radio 'on' or 'off' state : 'on/off' """ From dbbdf7383f2c94da2135fe0855d00945eab60115 Mon Sep 17 00:00:00 2001 From: Simon Schampijer Date: Wed, 31 Oct 2007 11:33:45 +0100 Subject: [PATCH 5/5] sugar-control: add the init file --- shell/controlpanel/__init__.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 shell/controlpanel/__init__.py diff --git a/shell/controlpanel/__init__.py b/shell/controlpanel/__init__.py new file mode 100644 index 00000000..a9dd95ad --- /dev/null +++ b/shell/controlpanel/__init__.py @@ -0,0 +1,16 @@ +# Copyright (C) 2006-2007, Red Hat, Inc. +# +# 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 +