From af940b2fa71e1bd54eb86c739b570fb08b4c8307 Mon Sep 17 00:00:00 2001 From: Ariel Calzada Date: Tue, 24 Jan 2012 15:18:44 +0000 Subject: Update i18n mechanism using i18n.py --- diff --git a/activity/activity.info b/activity/activity.info index 667bd15..5c1b742 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,6 +1,6 @@ [Activity] name = ClassroomKit -activity_version = 3 +activity_version = 1 bundle_id = org.laptop.ClassroomKit exec = sugar-activity classroomkit.ClassroomKitActivity icon = classroomkit diff --git a/broadcast.py b/broadcast.py index ad84293..cc2771a 100644 --- a/broadcast.py +++ b/broadcast.py @@ -1,8 +1,8 @@ -from gettext import gettext as _ import gtk import pango from utilities import Utilities +import i18n class BroadcastProcess(): """Broadcast process component @@ -46,10 +46,6 @@ class BroadcastUI(): _greenColor = '#00E500' _redColor = '#FF0000' - # I18N - _START = _('Start') - _STOP = _('Stop') - # UI elements _box = None _button = None @@ -122,11 +118,11 @@ class BroadcastUI(): if not state: self.setButtonBG(self._greenColor) - self.setButtonLabel(self._START) + self.setButtonLabel(i18n.START) self.setLabelTXT("") else: self.setButtonBG(self._redColor) - self.setButtonLabel(self._STOP) + self.setButtonLabel(i18n.STOP) self.setLabelTXT(self._process.getProcessInfo()) class Broadcast(): diff --git a/classroomkit.py b/classroomkit.py index fe9e40b..ac201dd 100644 --- a/classroomkit.py +++ b/classroomkit.py @@ -11,7 +11,6 @@ # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import logging -from gettext import gettext as _ import gtk from sugar.activity import activity diff --git a/i18n.py b/i18n.py new file mode 100644 index 0000000..b438938 --- /dev/null +++ b/i18n.py @@ -0,0 +1,22 @@ +# 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, + +# 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 _ + +# UI Buttons +START = _('Start') +STOP = _('Stop') + +# Process +IPS = _('IPs') +PROCESSID = _('Process ID') +HOSTNAME = _('Hostname') diff --git a/utilities.py b/utilities.py new file mode 100644 index 0000000..1953a3d --- /dev/null +++ b/utilities.py @@ -0,0 +1,130 @@ +import subprocess +import os +import socket +import commands +import i18n + +class Utilities(): + """Utilities + """ + + def __init__(self): + """Constructor + """ + pass + + def checkProgramStatus(self, programName): + """ + Check if 'programName' is running + Returns: [ A, [ B ] ] + A: True | False if the program is running + B: list of PID + """ + result = [] + + ps = subprocess.Popen(["pidof",programName],stdout=subprocess.PIPE) + pid = ps.communicate()[0].strip().split(" ") + ps.stdout.close() + pids = [] + + for p in pid: + p = p.strip() + + if p != "": + pids.append(p) + + if len(pids) > 0: + return [True, pids] + + return [False, []] + + def getHostname(self): + """Get server name + """ + return socket.gethostname() + + def getNetworkInterfaces(self): + """Get server network interfaces names + """ + f = open('/proc/net/dev', 'r') + lines = f.readlines() + f.close() + lines.pop(0) + lines.pop(0) + + interfaces = [] + for line in lines: + interface = line.strip().split(" ")[0].split(":")[0].strip() + interfaces.append(interface) + + return interfaces + + def getNetworkIPs(self, interfaces): + """Get server IPs per interface + """ + pattern = "inet addr:" + cmdName = "/sbin/ifconfig" + ips = {} + + for interface in interfaces: + cmd = cmdName + " " + interface + output = commands.getoutput(cmd) + inet = output.find(pattern) + + if inet >= 0: + start = inet + len(pattern) + end = output.find(" ", start) + + ip = output[start:end] + ips[interface] = ip + else: + ips[interface] = "" + + return ips + + def getNetworkInfo(self): + """Get server network map {IFACE:IP} + """ + info = "" + + interfaces = self.getNetworkInterfaces() + ips = self.getNetworkIPs(interfaces) + + for interface, ip in ips.iteritems(): + if info != "": + info += "\n " + + info += interface + ": " + ip + + return info + + def endProgram(self, programName): + status = self.checkProgramStatus(programName) + + if status [ 0 ] == True: + pids = status[1] + for pid in pids: + os.system("kill -9 " + pid) + + def startProgram(self, programName, args=[]): + cmd = [programName] + + if len(args) > 0: + for arg in args: + cmd.append(arg) + + subprocess.call(cmd, shell=False) + + def getNetworkProcessInfo(self,programName): + status = self.checkProgramStatus(programName) + pid = "" + if status [ 0 ]: + pid = ",".join(status[1]) + + txt = i18n.PROCESSID + " = " + pid + txt += "\n" + txt += i18n.HOSTNAME + " = " + self.getHostname() + txt += "\n" + txt += i18n.IPS + " = " + self.getNetworkInfo() + + return txt -- cgit v0.9.1