Skip to content

Commit

Permalink
adopted to PY3
Browse files Browse the repository at this point in the history
Now it works with 2.7 and 3.x
  • Loading branch information
lareq committed Jan 5, 2022
1 parent 322eab1 commit 45437e0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
14 changes: 7 additions & 7 deletions plugin/OscamStatusSetup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# version.
#===============================================================================

from __init__ import _
from .__init__ import _
from Screens.Screen import Screen
from Screens.MessageBox import MessageBox

Expand Down Expand Up @@ -64,7 +64,7 @@


def _parse_line(line):
for key, rx in oscam_regex.items():
for key, rx in list(oscam_regex.items()):
match = rx.search(line)
if match:
return key, match
Expand Down Expand Up @@ -209,7 +209,7 @@ def readCFG():
except:
pass
if cfg:
print "[OscamStatus] reading config file..."
print("[OscamStatus] reading config file...")
d = cfg.read()
cfg.close()
for line in d.splitlines():
Expand All @@ -225,7 +225,7 @@ def readCFG():
if tmp.serverName != 'Autodetected':
oscamServers.append(tmp)
if len(oscamServers) == 0:
print "[OscamStatus] no config file found"
print("[OscamStatus] no config file found")
tmp = oscamServer()
if parse_oscam_version_file('/tmp/.oscam/oscam.version', tmp):
if hasattr(tmp, 'ConfigDir'):
Expand All @@ -237,7 +237,7 @@ def readCFG():
def writeCFG(oscamServers):
cfg = file(CFG, "w")
savedconfig = 0
print "[OscamStatus] writing datfile..."
print("[OscamStatus] writing datfile...")
for line in oscamServers:
if line.serverName != 'Autodetected':
cfg.write(line.username + ' ')
Expand Down Expand Up @@ -385,7 +385,7 @@ def keyDelete(self):
self.index = -1
if self.index > -1:
if self.index == config.plugins.OscamStatus.lastServer.value:
print "[OscamStatus] you can not delete the active entry..."
print("[OscamStatus] you can not delete the active entry...")
return
message = _("Do you really want to delete this entry?")
msg = self.session.openWithCallback(self.Confirmed, MessageBox, message)
Expand Down Expand Up @@ -465,7 +465,7 @@ def __init__(self, session, entry, index):
self.serverIPConfigEntry = NoSave(ConfigIP(default=serverIP, auto_jump=True))
else:
self.serverIPConfigEntry = NoSave(ConfigText(default=entry.serverIP, fixed_size=False, visible_width=20))
self.serverIPConfigEntry.setUseableChars(u'1234567890aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ.-_')
self.serverIPConfigEntry.setUseableChars('1234567890aAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyYzZ.-_')
self.portConfigEntry = NoSave(ConfigInteger(default=serverPort, limits=(0, 65536)))
self.usernameConfigEntry = NoSave(ConfigText(default=entry.username, fixed_size=False, visible_width=20))
self.passwordConfigEntry = NoSave(ConfigPassword(default=entry.password, fixed_size=False))
Expand Down
2 changes: 1 addition & 1 deletion plugin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def localeInit():
def _(txt):
t = gettext.dgettext("OscamStatus", txt)
if t == txt:
print "[OscamStatus] fallback to default translation for", txt
print("[OscamStatus] fallback to default translation for", txt)
t = gettext.gettext(txt)
return t

Expand Down
44 changes: 23 additions & 21 deletions plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#===============================================================================
# OscamStatus Plugin by puhvogel 2011-2018
# modified by Pr2
# adopted to py3 by lareq
#
# This 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, or (at your option) any later
# version.
#===============================================================================

from __init__ import _
from .__init__ import _
from Plugins.Plugin import PluginDescriptor

from Screens.Screen import Screen
Expand Down Expand Up @@ -39,7 +40,7 @@

from threading import Thread, Lock
import xml.dom.minidom
import urllib2
import urllib.request, urllib.error, urllib.parse
import ssl
try:
_create_unverified_https_context = ssl._create_unverified_context
Expand All @@ -49,14 +50,15 @@
else:
# Handle target environment that doesn't support HTTPS verification
ssl._create_default_https_context = _create_unverified_https_context
from urllib import unquote_plus
from urllib2 import Request, urlopen, URLError, HTTPError
from urllib.parse import unquote_plus
from urllib.request import Request, urlopen
from urllib.error import URLError, HTTPError

from os import path, listdir
import re


from OscamStatusSetup import oscamServer, readCFG, OscamServerEntriesListConfigScreen, \
from .OscamStatusSetup import oscamServer, readCFG, OscamServerEntriesListConfigScreen, \
globalsConfigScreen, LASTSERVER, XOFFSET, EXTMENU, USEECM,\
dlg_xh, USEPICONS

Expand Down Expand Up @@ -87,7 +89,7 @@ def getPicon(channelname):
# Converts past seconds into days, hours, minutes and seconds ...
def elapsedTime(s, fmt, hasDays=False):
try:
secs = long(s)
secs = int(s)
if hasDays:
days, secs = divmod(secs, 86400)
hours, secs = divmod(secs, 3600)
Expand Down Expand Up @@ -158,22 +160,22 @@ def run(self):
self.__running = True
self.__cancel = False

PasswdMgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
PasswdMgr = urllib.request.HTTPPasswordMgrWithDefaultRealm()
PasswdMgr.add_password(None, self.url, self.username, self.password)

handler = urllib2.HTTPDigestAuthHandler(PasswdMgr)
opener = urllib2.build_opener(urllib2.HTTPHandler, handler)
handler = urllib.request.HTTPDigestAuthHandler(PasswdMgr)
opener = urllib.request.build_opener(urllib.request.HTTPHandler, handler)

urllib2.install_opener(opener)
request = urllib2.Request(self.url)
urllib.request.install_opener(opener)
request = urllib.request.Request(self.url)

self.__messages.push((THREAD_WORKING, "Download Thread is running"))
mp.send(0)

try:
page = urllib2.urlopen(request, timeout=5).read()
page = urllib.request.urlopen(request, timeout=5).read()

except urllib2.URLError, err:
except urllib.error.URLError as err:
error = "Error: "
if hasattr(err, "code"):
error += str(err.code)
Expand Down Expand Up @@ -476,7 +478,7 @@ class ClientDataScreen(Screen):

def __init__(self, session, type, oServer, data):
self.skin = ClientDataScreen.part1 + ClientDataScreen.ecmhistory + ClientDataScreen.part2
print self.skin
print(self.skin)
self.session = session
self.type = type
self.oServer = oServer
Expand Down Expand Up @@ -620,7 +622,7 @@ def __init__(self, session, part, oServer, timerOn=True):
def downloadXML(self):
self.setTitle(_("loading..."))
self.download = True
print "[OscamStatus] loading", self.url
print("[OscamStatus] loading", self.url)
self.getIndex()
# Message Queue initialisation...
getPage2.MessagePump.recv_msg.get().append(self.gotThreadMsg)
Expand All @@ -630,7 +632,7 @@ def downloadXML(self):
except RuntimeError:
self.download = False
getPage2.MessagePump.recv_msg.get().remove(self.gotThreadMsg)
print "[OscamStatus] Thread already running..."
print("[OscamStatus] Thread already running...")

def sendNewPart(self, part):
self.timer.stop()
Expand Down Expand Up @@ -658,21 +660,21 @@ def gotThreadMsg(self, msg):
errStr = str(msg[1])
if self.timerOn:
self.timer.stop()
print "[OscamStatus]", errStr
print("[OscamStatus]", errStr)
info = self.session.open(MessageBox, errStr, MessageBox.TYPE_ERROR)
info.setTitle(_("Oscam Status"))
self.close(1)

elif msg[0] == THREAD_FINISHED:
getPage2.MessagePump.recv_msg.get().remove(self.gotThreadMsg)
self.download = False
print "[OscamStatus] Download finished"
print("[OscamStatus] Download finished")

self.data = msg[1]
self.download = False
# if no xml comes back something is not right ..
if not "<?xml version=\"1.0\"" in self.data:
print "[OscamStatus] Oscam Download Error: no xml"
if not ("<?xml version=\"1.0\"").encode() in self.data :
print("[OscamStatus] Oscam Download Error: no xml")
info = self.session.open(MessageBox, _("no xml"), MessageBox.TYPE_ERROR)
info.setTitle(_("Oscam Download Error"))
self.close(1)
Expand All @@ -689,7 +691,7 @@ def gotThreadMsg(self, msg):
if self.timerOn:
self.timer.stop()
errmsg = str(node[0].firstChild.nodeValue.strip())
print "[OscamStatus] Oscam XML Error:", errmsg
print("[OscamStatus] Oscam XML Error:", errmsg)
info = self.session.open(MessageBox, _(errmsg), MessageBox.TYPE_ERROR)
info.setTitle(_("Oscam XML Error"))
self.close(1)
Expand Down
4 changes: 2 additions & 2 deletions setup_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ def run(self):
if f.endswith('.po'):
src = os.path.join(lc, f)
dest = os.path.join(lc, f[:-2] + 'mo')
print "Language compile %s -> %s" % (src, dest)
print("Language compile %s -> %s" % (src, dest))
if os.system("msgfmt '%s' -o '%s'" % (src, dest)) != 0:
raise Exception, "Failed to compile: " + src
raise Exception("Failed to compile: " + src)


class build(_build):
Expand Down

0 comments on commit 45437e0

Please sign in to comment.