Quellcode durchsuchen

Coding style corrections

Helmut Pozimski vor 12 Jahren
Ursprung
Commit
8e85b49820
7 geänderte Dateien mit 62 neuen und 44 gelöschten Zeilen
  1. 13 8
      configuration.py
  2. 2 1
      install.py
  3. 4 3
      outputhelper.py
  4. 11 9
      stov.py
  5. 6 4
      subscription.py
  6. 16 12
      youtube.py
  7. 10 7
      youtubeAPI.py

+ 13 - 8
configuration.py

@@ -23,6 +23,7 @@ import subprocess
 
 from outputhelper import printf
 
+
 class conf(object):
 	def __init__(self):
 		"""Constructor
@@ -54,7 +55,8 @@ class conf(object):
 		self.__explanations = {
 				"database": _("the name of your database file"),
 				"downloaddir": _("the directory where downloaded videos are saved"),
-				"maxvideos": _("the maximum number of videos to retrieve for each subscription"),
+				"maxvideos": _("the maximum number of videos to retrieve for each "
+					"subscription"),
 				"mailhost": _("the host of your mail server"),
 				"mailto": _("the address used for notifications"),
 				"mailfrom": _("the sender address of notification e-mails"),
@@ -65,7 +67,8 @@ class conf(object):
 				"youtube-dl": _("the path to your youtube-dl installation"),
 				"notify": _("if you want to be notified via e-mail about new videos"),
 				"videocodec": _("which video codec you prefer (h264, webm or flv)"),
-				"maxresolution": _("which resolution you prefer (360p, 480p, 720p or 1080p)"),
+				"maxresolution": _("which resolution you prefer (360p, 480p, 720p "
+					"or 1080p)"),
 				}
 		self.dbpath = str(os.environ['HOME']) + "/.stov/" + self.values["database"]
 		self.outputlevel = "default"
@@ -98,7 +101,7 @@ class conf(object):
 		except sqlite3.OperationalError:
 			printf(_("The database could not be created, please "
 				"check that the configuration directory exists and is writable"),
-				outputlevel = "default", level=self.outputlevel, descriptor="stderr")
+				outputlevel="default", level=self.outputlevel, descriptor="stderr")
 		else:
 			self.__dbcursor = self.__database.cursor()
 			printf(_("Creating table subscriptions"),
@@ -131,7 +134,8 @@ class conf(object):
 
 		"""
 		try:
-			printf(_("Creating hidden directory in home for configuration and database"),
+			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)
 		except os.error:
@@ -153,7 +157,7 @@ class conf(object):
 		"""
 		try:
 			printf(_("Opening config file for reading"),
-				outputlevel="verbose", level=self.outputlevel, descriptor="stderr")	
+				outputlevel="verbose", level=self.outputlevel, descriptor="stderr")
 			self.configfile = open(str(os.environ['HOME']) + "/.stov/stov.config", "r")
 		except IOError:
 			printf(_("Configuration could not be "
@@ -227,10 +231,11 @@ class conf(object):
 			except sqlite3.OperationalError:
 				printf(_("The database could not be updated, please "
 					"check that the configuration directory exists and is writable"),
-					outputlevel = "default", level=self.outputlevel, descriptor="stderr")
+					outputlevel="default", level=self.outputlevel, descriptor="stderr")
 			else:
 				self.__dbcursor = self.__database.cursor()
-				self.__dbcursor.execute("ALTER TABLE videos add column failcnt int DEFAULT 0;")
+				self.__dbcursor.execute("ALTER TABLE videos add column failcnt int \
+				DEFAULT 0;")
 				self.__database.commit()
 				self.__database.close()
 				self.ReadConfig()
@@ -288,7 +293,7 @@ class conf(object):
 			descriptor="stdout")
 		for value in self.__explanations:
 			printf(_(self.__explanations[value] + " [" + self.values[value] + "]: "),
-				outputlevel="default", level=self.outputlevel, 
+				outputlevel="default", level=self.outputlevel,
 				descriptor="stdout")
 			self.__user_input = raw_input()
 			if self.__user_input != "":

+ 2 - 1
install.py

@@ -117,7 +117,8 @@ you can write to it."""
 	os.chdir(programpath)
 	if os.access(binpath, os.F_OK & os.W_OK) and installation_success is True:
 		try:
-			os.symlink(os.path.join(programpath, "stov.py"), os.path.join(binpath, "stov"))
+			os.symlink(os.path.join(programpath, "stov.py"),
+				os.path.join(binpath, "stov"))
 		except OSError:
 			print "Symlink in bin-directory already exists"
 		print ("stov has been installed successfully to "

+ 4 - 3
outputhelper.py

@@ -23,6 +23,7 @@ import sys
 A little helper function used to do some additional checks before actually
 using print to generate the output"""
 
+
 def printf(string, outputlevel, descriptor="stdout", level="default"):
 	if descriptor == "stdout":
 		if level == "default" and outputlevel == "default":
@@ -38,7 +39,7 @@ def printf(string, outputlevel, descriptor="stdout", level="default"):
 			elif string is str:
 				print string
 			else:
-				print str(string)	
+				print str(string)
 		elif level == "quiet":
 			pass
 	elif descriptor == "stderr":
@@ -55,6 +56,6 @@ def printf(string, outputlevel, descriptor="stdout", level="default"):
 			elif string is str:
 				print >> sys.stderr, string
 			else:
-				print >> sys.stderr, str(string)	
+				print >> sys.stderr, str(string)
 		elif level == "quiet":
-			pass	
+			pass

+ 11 - 9
stov.py

@@ -142,11 +142,11 @@ loaded as a module
 """
 
 if __name__ != "__main__":
-	print >> sys.stderr, """This file should not be imported as a module 
+	print >> sys.stderr, """This file should not be imported as a module
 				please run it directly from command line"""
 	sys.exit(1)
 
-"""Check which outputlevel is defined and save it to a temporary variable 
+"""Check which outputlevel is defined and save it to a temporary variable
 accordingly. Output generated before this will be printed to stdout regardless
 of the user defined setting
 
@@ -222,7 +222,7 @@ else:
 	conf = configuration.conf()
 	if conf.CheckConfig() is not True:
 		printf(_("Your configuration needs to be updated, performing"
-			" update now."), outputlevel="default", level=outputlevel, 
+			" update now."), outputlevel="default", level=outputlevel,
 			descriptor="stdout")
 		conf.UpdateConfig()
 	if conf.CheckDB() is not True:
@@ -233,7 +233,7 @@ else:
 	conf.ReadConfig()
 
 """Check which outputlevel is defined and update the configuration object
-accordingly. 
+accordingly.
 
 """
 
@@ -293,7 +293,7 @@ if options.add is True:
 	if AddSub is True:
 		NewSubscription.AddSub()
 		NewSubscription.UpdateVideos()
-		printf(_("New subscription ") + NewSubscription.GetTitle()\
+		printf(_("New subscription ") + NewSubscription.GetTitle()
 		+ _(" successfully added"), outputlevel="default", level=conf.outputlevel,
 		descriptor="stdout")
 elif options.list is True:
@@ -440,7 +440,8 @@ FROM subscriptions")
 			printf(_("The following videos have been downloaded:\n"),
 			outputlevel="default", level=conf.outputlevel, descriptor="stdout")
 			for i in mailcontent:
-				printf(i, outputlevel="default", level=conf.outputlevel, descriptor="stdout")
+				printf(i, outputlevel="default", level=conf.outputlevel,
+					descriptor="stdout")
 	else:
 		printf(_("Could not determine how you want to be informed "
 					"about new videos, please check the notify parameter "
@@ -512,7 +513,7 @@ elif options.cleanup is True:
 		title=element[1], type=element[2], name=element[3],
 		search=element[4], directory=element[5], conf=conf))
 	for element in subscriptions_list:
-		element.CheckAndDelete()	
+		element.CheckAndDelete()
 	try:
 		database = sqlite3.connect(conf.dbpath)
 		cursor = database.cursor()
@@ -525,7 +526,7 @@ elif options.cleanup is True:
 		database.close()
 
 elif options.license is True:
-	printf( """
+	printf("""
 	stov 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, version 2 of the License.
@@ -539,7 +540,8 @@ elif options.license is True:
 	along with stov.  If not, see <http://www.gnu.org/licenses/>.
 	""", outputlevel="default", level=conf.outputlevel, descriptor="stdout")
 elif options.version is True:
-	printf("0.3dev", outputlevel="default", level=conf.outputlevel, descriptor="stdout")
+	printf("0.3dev", outputlevel="default", level=conf.outputlevel,
+		descriptor="stdout")
 else:
 	parser.print_help()
 

+ 6 - 4
subscription.py

@@ -26,6 +26,7 @@ import youtube
 
 from outputhelper import printf
 
+
 class sub(object):
 	def __init__(self, type, name, conf, search="", id=0, title="", directory=""):
 		self.__ID = id
@@ -85,7 +86,7 @@ class sub(object):
 				outputlevel="default", level=self.__conf.outputlevel, descriptor="stderr")
 
 		for i in self.__ParsedResponse.videos:
-			printf(_('Checking if video "%s" exists in the database' %i.title),
+			printf(_('Checking if video "%s" exists in the database' % i.title),
 				outputlevel="verbose", level=self.__conf.outputlevel, descriptor="stderr")
 			self.__ytid = i.ytid
 			self.__videoquery = "SELECT id FROM videos WHERE ytid=?"
@@ -117,7 +118,7 @@ class sub(object):
 				"Please check permissions and try again."),
 				outputlevel="default", level=self.__conf.outputlevel, descriptor="stderr")
 
-		printf(_("Getting all videos for subscription %s from database" 
+		printf(_("Getting all videos for subscription %s from database"
 			% self.__title), outputlevel="verbose", level=self.__conf.outputlevel,
 			descriptor="stderr")
 		self.__videoquerybysubscription = "SELECT id, title, description, \
@@ -152,7 +153,7 @@ class sub(object):
 			outputlevel="default", level=self.__conf.outputlevel, descriptor="stdout")
 		for i in self.__videos:
 			if i.downloaded == 0:
-				printf(i.title + _("   (pending)"), outputlevel="default", 
+				printf(i.title + _("   (pending)"), outputlevel="default",
 					level=self.__conf.outputlevel, descriptor="stdout")
 			elif i.downloaded == 1:
 				printf(i.title + _("   (downloaded)"), outputlevel="default",
@@ -192,7 +193,7 @@ class sub(object):
 		self.__cursor.execute(self.__query, self.__data)
 		self.__ID = self.__cursor.fetchone()
 		self.__ID = self.__ID[0]
-		printf(_("Subscription got internal ID %s" %self.__ID),
+		printf(_("Subscription got internal ID %s" % self.__ID),
 			outputlevel="verbose", level=self.__conf.outputlevel, descriptor="stderr")
 		self.__connection.close()
 
@@ -244,6 +245,7 @@ class sub(object):
 				outputlevel="default", level=self.__conf.outputlevel, descriptor="stderr")
 		printf(_("Constructed the following API URL: %s" % self.__APIURL),
 			outputlevel="verbose", level=self.__conf.outputlevel, descriptor="stderr")
+
 	def CheckAndDelete(self):
 		"""Checks if a video still exists in the current API response and deletes
 		it if it doesn't

+ 16 - 12
youtube.py

@@ -24,8 +24,10 @@ import subprocess
 
 from outputhelper import printf
 
+
 class video(object):
-	def __init__(self, title, description, ytid, conf, downloaded, failcount = 0, id=0):
+	def __init__(self, title, description, ytid, conf, downloaded, failcount=0,
+			id=0):
 		self.__ID = id
 		self.title = title
 		self.description = description
@@ -53,16 +55,16 @@ and can't be created. Please check your configuration and try again"),
 				printf(_('Downloading video "%s"' % self.title),
 					outputlevel="verbose", level=self.__conf.outputlevel, descriptor="stderr")
 				if self.__conf.outputlevel == "default":
-					subprocess.check_call(["youtube-dl", "--max-quality=%s" % itag_value, "-t",
-					"http://www.youtube.com/watch?v=%s" % self.ytid],
+					subprocess.check_call(["youtube-dl", "--max-quality=%s"
+					% itag_value, "-t", "http://www.youtube.com/watch?v=%s" % self.ytid],
 					stderr=sys.stderr, stdout=open("/dev/null", "w"))
 				elif self.__conf.outputlevel == "verbose":
-					subprocess.check_call(["youtube-dl", "--max-quality=%s" % itag_value, "-t",
-					"http://www.youtube.com/watch?v=%s" % self.ytid],
+					subprocess.check_call(["youtube-dl", "--max-quality=%s"
+					% itag_value, "-t", "http://www.youtube.com/watch?v=%s" % self.ytid],
 					stderr=sys.stderr, stdout=sys.stdout)
 				elif self.__conf.outputlevel == "quiet":
-					subprocess.check_call(["youtube-dl", "--max-quality=%s" % itag_value, "-t",
-					"http://www.youtube.com/watch?v=%s" % self.ytid],
+					subprocess.check_call(["youtube-dl", "--max-quality=%s"
+					% itag_value, "-t", "http://www.youtube.com/watch?v=%s" % self.ytid],
 					stderr=open("/dev/null", "w"), stdout=open("/dev/null", "w"))
 				try:
 					self.__database = sqlite3.connect(self.__conf.dbpath)
@@ -70,7 +72,8 @@ and can't be created. Please check your configuration and try again"),
 					printf(_("The Video \"%s\" has been "
 								"downloaded but the status could not be updated in the database. "
 								"Please check what went wrong and correct it" % self.title),
-						outputlevel="default", level=self.__conf.outputlevel, descriptor="stderr")
+						outputlevel="default", level=self.__conf.outputlevel,
+							descriptor="stderr")
 				else:
 					self.__cursor = self.__database.cursor()
 					printf(_('Downloaded video "%s", updating database accordingly.'
@@ -92,14 +95,15 @@ and can't be created. Please check your configuration and try again"),
 					printf(_("The Video \"%s\" has failed "
 								"downloading but the status could not be updated in the database. "
 								"Please check what went wrong and correct it" % self.title),
-						outputlevel="default", level=self.__conf.outputlevel, descriptor="stderr")
+						outputlevel="default", level=self.__conf.outputlevel,
+							descriptor="stderr")
 				else:
 					self.__cursor = self.__database.cursor()
 					self.failcnt = int(self.failcnt) + 1
 					if self.failcnt >= int(self.__conf.values["maxfails"]):
 						printf(_("The video \"%s\" has failed downloading too often, marking as"
-							" failed" % self.title), outputlevel="default", level=self.__conf.outputlevel,
-							descriptor="stderr")
+							" failed" % self.title), outputlevel="default",
+							level=self.__conf.outputlevel, descriptor="stderr")
 						self.__statement = "UPDATE videos SET downloaded = -1 WHERE id = ?"
 						self.__cursor.execute(self.__statement, (self.__ID,))
 					self.__statement = "UPDATE videos SET failcnt = ? WHERE id = ?"
@@ -118,7 +122,7 @@ and can't be created. Please check your configuration and try again"),
 			self.__database = sqlite3.connect(self.__conf.dbpath)
 		except sqlite3.OperationalError:
 			printf(_("Could not connect to the database, please check settings and"
-				 "permissions and try again"), outputlevel="default",
+				"permissions and try again"), outputlevel="default",
 				level=self.__conf.outputlevel, descriptor="stderr")
 			return False
 		else:

+ 10 - 7
youtubeAPI.py

@@ -31,25 +31,28 @@ class Parser(object):
 		for title in dom.getElementsByTagName('title'):
 			xmlTag = title.toxml()
 			if i == 0:
-				channel.title = xmlTag.replace('<title>','').replace('</title>','')
-				channel.title = channel.title.replace('&amp;','&').replace('&quot;','"')
+				channel.title = xmlTag.replace('<title>', '').replace('</title>', '')
+				channel.title = channel.title.replace('&amp;', '&').replace('&quot;', '"')
 			else:
-				video_title = xmlTag.replace('<title>','').replace('</title>','')
-				video_title = video_title.replace('&amp;','&').replace('&quot;','"')
+				video_title = xmlTag.replace('<title>', '').replace('</title>', '')
+				video_title = video_title.replace('&amp;', '&').replace('&quot;', '"')
 				xmlTag = dom.getElementsByTagName('media:description')[i-1].toxml()
-				video_description = xmlTag.replace('<media:description type="plain">'
-				,'').replace('</media:description>','')
+				video_description = xmlTag.replace('<media:description type="plain">',
+				'').replace('</media:description>', '')
 				video_id = dom.getElementsByTagName('yt:videoid')[i-1].toxml()
-				video_id = video_id.replace('<yt:videoid>','').replace('</yt:videoid>','')
+				video_id = video_id.replace('<yt:videoid>', '').replace('</yt:videoid>',
+					'')
 				channel.videos.append(YtVideo(video_title, video_description, video_id))
 			i = i + 1
 		return channel
 
+
 class YtChannel(object):
 	def __init__(self):
 		self.title = u""
 		self.videos = []
 
+
 class YtVideo(object):
 	def __init__(self, title, description, ytid):
 		self.title = title