Browse Source

Took some small steps in the direction of python 3 compatibility, install.py not yet done, not all functionality tested yet

Helmut Pozimski 11 years ago
parent
commit
d15a3918a5
6 changed files with 37 additions and 27 deletions
  1. 4 2
      configuration.py
  2. 14 20
      outputhelper.py
  3. 6 2
      stov.py
  4. 7 1
      subscription.py
  5. 3 1
      youtube.py
  6. 3 1
      youtubeAPI.py

+ 4 - 2
configuration.py

@@ -15,6 +15,8 @@
 
 # -*- coding: utf8 -*-
 
+from __future__ import unicode_literals
+
 import os
 import gettext
 import sys
@@ -86,7 +88,7 @@ class conf(object):
 			printf(_("Opening configuration file"),
 				outputlevel="verbose", level=self.outputlevel, descriptor="stderr")
 			self.configfile = open(str(os.environ['HOME']) + "/.stov/stov.config", "w")
-		except IOError, os.error:
+		except IOError:
 			printf(_("Configuration could not be written, please"
 					" check that the configuration directory exists and is writable"),
 				outputlevel="default", level=self.outputlevel, descriptor="stderr")
@@ -140,7 +142,7 @@ class conf(object):
 			printf(_("Creating hidden directory in home for configuration and "
 				"database"),
 				outputlevel="verbose", level=self.outputlevel, descriptor="stderr")
-			os.mkdir(str(os.environ['HOME']) + "/.stov", 0750)
+			os.mkdir(str(os.environ['HOME']) + "/.stov", 0o750)
 		except os.error:
 			printf(_("Configuration directory could not be created, "
 				"please check that your home directory exists and is writable"),

+ 14 - 20
outputhelper.py

@@ -16,6 +16,8 @@
 
 # -*- coding: utf8 -*-
 
+from __future__ import unicode_literals, print_function
+
 import sys
 
 """
@@ -27,35 +29,27 @@ using print to generate the output"""
 def printf(string, outputlevel, descriptor="stdout", level="default"):
 	if descriptor == "stdout":
 		if level == "default" and outputlevel == "default":
-			if isinstance(string, unicode):
-				print string.encode("utf8")
-			elif string is str:
-				print string
+			if sys.version_info >= (3,0):
+				print(string)
 			else:
-				print str(string)
+				print(string.encode("utf8"))
 		elif level == "verbose":
-			if isinstance(string, unicode):
-				print string.encode("utf8")
-			elif string is str:
-				print string
+			if sys.version_info >= (3,0):
+				print(string)
 			else:
-				print str(string)
+				print(string.encode("utf8"))
 		elif level == "quiet":
 			pass
 	elif descriptor == "stderr":
 		if level == "default" and outputlevel == "default":
-			if isinstance(string, unicode):
-				print >> sys.stderr, string.encode("utf8")
-			elif string is str:
-				print >> sys.stderr, string
+			if sys.version_info >= (3,0):
+				print (string, file=sys.stderr)
 			else:
-				print str(string)
+				print(string.encode("utf8"), file=sys.stderr)
 		elif level == "verbose":
-			if isinstance(string, unicode):
-				print >> sys.stderr, string.encode("utf8")
-			elif string is str:
-				print >> sys.stderr, string
+			if sys.version_info >= (3,0):
+				print (string, file=sys.stderr)
 			else:
-				print >> sys.stderr, str(string)
+				print(string.encode("utf8"), file=sys.stderr)
 		elif level == "quiet":
 			pass

+ 6 - 2
stov.py

@@ -21,6 +21,7 @@
 #	Foundation, Inc., 51 Franklin Street, Fifth Floor,
 #	Boston, MA 02110-1301, USA.
 
+from __future__ import unicode_literals
 import sys
 import gettext
 import os
@@ -52,7 +53,10 @@ except IOError:
 				"won't be available"), outputlevel="default",
 		descriptor="stderr")
 else:
-	trans.install(unicode=True)
+	if sys.version_info >= (3,0):
+		trans.install()
+	else:
+		trans.install(unicode=True)
 
 """Overwrite the default OptionParser class so error messages
 can be localized
@@ -382,7 +386,7 @@ FROM subscriptions")
 		videosdownloaded = len(mailcontent)
 		videosfailed = videosfailed + element.FailedVideos
 	if videosdownloaded > 0 and conf.values["notify"] == "yes":
-		MailText = u""
+		MailText = ""
 		msg = MIMEMultipart()
 		if videosdownloaded == 1:
 			msg["Subject"] = _("Downloaded %i new video") % videosdownloaded

+ 7 - 1
subscription.py

@@ -16,11 +16,17 @@
 
 # -*- coding: utf8 -*-
 
+from __future__ import unicode_literals
+
 import sys
 import gettext
-import urllib2
 import sqlite3
 
+if sys.version_info >= (3,):
+	import urllib.request as urllib2
+else:
+	import urllib2
+
 import youtubeAPI
 import youtube
 

+ 3 - 1
youtube.py

@@ -16,6 +16,8 @@
 
 # -*- coding: utf8 -*-
 
+from __future__ import unicode_literals
+
 import os
 import sys
 import gettext
@@ -43,7 +45,7 @@ class video(object):
 			try:
 				printf(_("Creating directory %s") % self.__targetdir,
 					outputlevel="verbose", level=self.__conf.outputlevel, descriptor="stderr")
-				os.makedirs(self.__targetdir, 0750)
+				os.makedirs(self.__targetdir, 0o750)
 			except os.error:
 				printf(_("Download directory does not exist \
 and can't be created. Please check your configuration and try again"),

+ 3 - 1
youtubeAPI.py

@@ -16,6 +16,8 @@
 
 # -*- coding: utf8 -*-
 
+from __future__ import unicode_literals
+
 from xml.dom.minidom import parseString
 
 
@@ -49,7 +51,7 @@ class Parser(object):
 
 class YtChannel(object):
 	def __init__(self):
-		self.title = u""
+		self.title = ""
 		self.videos = []