Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python 3 cleanups #824

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions mythplugins/mytharchive/mythburn/scripts/mythburn.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

# python 3 doesn't have a unicode type
try:
Expand Down Expand Up @@ -115,7 +113,7 @@
except:
# Some hardcoded values for ioctl calls,
# not available on python > 3.5, see include/linux/cdrom.h
class CDROM(object):
class CDROM:
CDS_NO_INFO = 0
CDS_NO_DISC = 1
CDS_TRAY_OPEN = 2
Expand Down Expand Up @@ -257,7 +255,7 @@ def simple_fix_rtl(str):
#############################################################
# class to hold a font definition

class FontDef(object):
class FontDef:
def __init__(self, name=None, fontFile=None, size=19, color="white", effect="normal", shadowColor="black", shadowSize=1):
self.name = name
self.fontFile = fontFile
Expand Down Expand Up @@ -308,10 +306,7 @@ def drawText(self, text, color=None):
def write(text, progress=True):
"""Simple place to channel all text output through"""

if sys.version_info == 2:
sys.stdout.write((text + "\n").encode("utf-8", "replace"))
else:
sys.stdout.write(text + "\n")
sys.stdout.write(text + "\n")
sys.stdout.flush()

if progress == True and progresslog != "":
Expand Down Expand Up @@ -2026,7 +2021,7 @@ def extractVideoFrame(source, destination, seconds):
return (long(0),long(0))
else:
return myimage.size
except IOError:
except OSError:
return (long(0),long(0))

#############################################################
Expand Down Expand Up @@ -2146,7 +2141,7 @@ def encodeNuvToMPEG2(chanid, starttime, mediafile, destvideofile, folder, profil
"""Encodes a nuv video source file to MPEG2 video and AC3 audio, using mythtranscode & mythffmpeg"""

# make sure mythtranscode hasn't left some stale fifos hanging around
if ((doesFileExist(os.path.join(folder, "audout")) or doesFileExist(os.path.join(folder, "vidout")))):
if (doesFileExist(os.path.join(folder, "audout")) or doesFileExist(os.path.join(folder, "vidout"))):
fatalError("Something is wrong! Found one or more stale fifo's from mythtranscode\n"
"Delete the fifos in '%s' and start again" % folder)

Expand Down
49 changes: 20 additions & 29 deletions mythplugins/mythgame/mythgame/scripts/giantbomb.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
# ----------------------
# Name: giantbomb.py
# Python Script
Expand Down Expand Up @@ -129,29 +128,21 @@
import re


IS_PY2 = sys.version_info[0] == 2

try:
if IS_PY2:
from StringIO import StringIO
else:
from io import StringIO
from io import StringIO
from lxml import etree
except Exception as e:
sys.stderr.write(u'\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
sys.stderr.write('\n! Error - Importing the "lxml" and "StringIO" python libraries failed on error(%s)\n' % e)
sys.exit(1)


if IS_PY2:
stdio_type = file
else:
import io
stdio_type = io.TextIOWrapper
unicode = str
unichr = chr
import io
stdio_type = io.TextIOWrapper
unicode = str
unichr = chr


class OutStreamEncoder(object):
class OutStreamEncoder:
"""Wraps a stream with an encoder
"""
def __init__(self, outstream, encoding=None):
Expand Down Expand Up @@ -187,7 +178,7 @@ def __getattr__(self, attr):
version+=str(digit)+'.'
version = version[:-1]
if version < '2.7.2':
sys.stderr.write(u'''
sys.stderr.write('''
! Error - The installed version of the "lxml" python library "libxml" version is too old.
At least "libxml" version 2.7.2 must be installed. Your version is (%s).
''' % version)
Expand Down Expand Up @@ -218,22 +209,22 @@ def main():
# api.giantbomb.com api key provided for Mythtv
apikey = "b5883a902a8ed88b15ce21d07787c94fd6ad9f33"

parser = OptionParser(usage=u"%prog usage: giantbomb -hdluvMD [parameters]\n <game name or gameid number>\n\nFor details on using giantbomb from the command execute './giantbomb.py -u'. For details on the meaning of the XML element tags see the wiki page at:\nhttps://www.mythtv.org/wiki/MythTV_Universal_Metadata_Format")
parser = OptionParser(usage="%prog usage: giantbomb -hdluvMD [parameters]\n <game name or gameid number>\n\nFor details on using giantbomb from the command execute './giantbomb.py -u'. For details on the meaning of the XML element tags see the wiki page at:\nhttps://www.mythtv.org/wiki/MythTV_Universal_Metadata_Format")

parser.add_option( "-d", "--debug", action="store_true", default=False, dest="debug",
help=u"Show debugging info")
help="Show debugging info")
parser.add_option( "-u", "--usage", action="store_true", default=False, dest="usage",
help=u"Display examples for executing the giantbomb script")
help="Display examples for executing the giantbomb script")
parser.add_option( "-v", "--version", action="store_true", default=False, dest="version",
help=u"Display version and author")
parser.add_option( "-l", "--language", metavar="LANGUAGE", default=u'en', dest="language",
help=u"Select data that matches the specified language. At this time giantbomb.com only supports 'en' English.")
parser.add_option( "-a", "--area", metavar="AREA", default=u"gb", dest="area",
help=u"Select data that matches the specified country. This option is currently not used.")
help="Display version and author")
parser.add_option( "-l", "--language", metavar="LANGUAGE", default='en', dest="language",
help="Select data that matches the specified language. At this time giantbomb.com only supports 'en' English.")
parser.add_option( "-a", "--area", metavar="AREA", default="gb", dest="area",
help="Select data that matches the specified country. This option is currently not used.")
parser.add_option( "-M", "--gamelist", action="store_true", default=False, dest="gamelist",
help=u"Get matching Movie list")
help="Get matching Movie list")
parser.add_option( "-D", "--gamedata", action="store_true", default=False, dest="gamedata",
help=u"Get Movie metadata including graphic URLs")
help="Get Movie metadata including graphic URLs")

opts, args = parser.parse_args()

Expand All @@ -249,7 +240,7 @@ def main():

# Process version command line requests
if opts.version:
version = etree.XML(u'<grabber></grabber>')
version = etree.XML('<grabber></grabber>')
etree.SubElement(version, "name").text = __title__
etree.SubElement(version, "author").text = __author__
etree.SubElement(version, "thumbnail").text = 'giantbomb.png'
Expand All @@ -269,7 +260,7 @@ def main():
sys.stderr.write("! Error: There must be one value for any option. Your options are (%s)\n" % (args))
sys.exit(1)

if args[0] == u'':
if args[0] == '':
sys.stderr.write("! Error: There must be a non-empty argument, yours is empty.\n")
sys.exit(1)

Expand Down
Loading