Browse Source

project-wide: update copyright and apply pylint suggestions

Helmut Pozimski 3 years ago
parent
commit
c2b020c18b

+ 30 - 23
lib_stov/configuration.py

@@ -1,4 +1,4 @@
-#   This file is part of stov, written by Helmut Pozimski 2012-2017.
+#   This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #   stov is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@ from lib_stov import stov_exceptions
 LOGGER = logging.getLogger("stov")
 
 
-class Conf(object):
+class Conf:
     """This class is used to create the object which is responsible for all
     configuration operations.
     """
@@ -121,8 +121,8 @@ class Conf(object):
         try:
             configfile = open(str(os.environ['HOME']) +
                               "/.stov/stov.json", "w")
-        except IOError:
-            raise stov_exceptions.ConfigFileWriteErrorException()
+        except IOError as exc:
+            raise stov_exceptions.ConfigFileWriteErrorException() from exc
         else:
             json.dump(self.values, configfile, indent=0)
             configfile.close()
@@ -136,8 +136,8 @@ class Conf(object):
         LOGGER.debug(_("Creating stov configuration directory"))
         try:
             os.mkdir(str(os.environ['HOME']) + "/.stov", 0o750)
-        except os.error:
-            raise stov_exceptions.DirectoryCreationFailedException()
+        except os.error as exc:
+            raise stov_exceptions.DirectoryCreationFailedException() from exc
         else:
             self.write_config()
 
@@ -152,15 +152,15 @@ class Conf(object):
         try:
             configfile = open(str(os.environ['HOME']) +
                               "/.stov/stov.config", "r")
-        except IOError:
-            raise stov_exceptions.ConfigFileReadErrorException()
+        except IOError as exc:
+            raise stov_exceptions.ConfigFileReadErrorException() from exc
         for lines in configfile:
             tmpline = lines.strip()
             tmplist = tmpline.split("=")
             self.values[tmplist[0].lower()] = tmplist[1]
         configfile.close()
-        self.dbpath = str(os.environ['HOME']) + "/.stov/" + \
-                      self.values["database"]
+        self.dbpath = str(os.environ['HOME']) + "/.stov/" \
+                      + self.values["database"]
 
     def read_config(self):
         """Reads the existing json configuration files and loads the values in
@@ -170,8 +170,8 @@ class Conf(object):
         try:
             configfile = open(str(os.environ['HOME']) + "/.stov/stov.json",
                               "r")
-        except IOError:
-            raise stov_exceptions.ConfigFileReadErrorException()
+        except IOError as exc:
+            raise stov_exceptions.ConfigFileReadErrorException() from exc
         else:
             self.values.update(json.load(configfile))
             configfile.close()
@@ -183,8 +183,9 @@ class Conf(object):
         """
         try:
             current_version = int(self.values["config_version"])
-        except ValueError:
-            raise stov_exceptions.InvalidConfigurationVersionException()
+        except ValueError as exc:
+            raise stov_exceptions.InvalidConfigurationVersionException() \
+                from exc
         self.values["config_version"] = "0"
         self.read_config()
         if self.values["config_version"] == "0" \
@@ -203,15 +204,15 @@ class Conf(object):
 
     def check_db(self):
         """Checks the database if it is up-to-date"""
-        currentdbversion = int(self.values["db_version"])
+        current_db_version = int(self.values["db_version"])
         self.values["db_version"] = "0"
         self.read_config()
         if self.values["db_version"] == "0" or \
                 int(self.values["db_version"]) < \
-                int(currentdbversion):
-            self.values["db_version"] = str(currentdbversion)
+                int(current_db_version):
+            self.values["db_version"] = str(current_db_version)
             return False
-        self.values["db_version"] = str(currentdbversion)
+        self.values["db_version"] = str(current_db_version)
         return True
 
     def assist(self):
@@ -239,10 +240,10 @@ class Conf(object):
         try:
             self.read_old_config()
             self.write_config()
-        except stov_exceptions.ConfigFileReadErrorException:
-            raise stov_exceptions.ConfigurationMigrationFailed()
-        except stov_exceptions.ConfigFileWriteErrorException:
-            raise stov_exceptions.ConfigurationMigrationFailed
+        except stov_exceptions.ConfigFileReadErrorException as exc:
+            raise stov_exceptions.ConfigurationMigrationFailed() from exc
+        except stov_exceptions.ConfigFileWriteErrorException as exc:
+            raise stov_exceptions.ConfigurationMigrationFailed from exc
         else:
             os.remove(str(os.environ['HOME']) + "/.stov/stov.config")
 
@@ -272,4 +273,10 @@ class Conf(object):
         return logger
 
     def get_value(self, identifier):
-        return self.values[identifier];
+        """
+        Returns the value for the specified identifier
+
+        :param identifier: the identifier in the value dictionary
+        :return:
+        """
+        return self.values[identifier]

+ 13 - 14
lib_stov/database.py

@@ -1,4 +1,4 @@
-#       This file is part of stov, written by Helmut Pozimski 2012-2017.
+#       This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #       stov is free software: you can redistribute it and/or modify
 #       it under the terms of the GNU General Public License as published by
@@ -27,7 +27,7 @@ from lib_stov import subscription
 LOGGER = logging.getLogger("stov")
 
 
-class Db(object):
+class Db:
     """This class is used to construct the module which will take care of all
     database related operations like opening the database, reading from and
     writing to it.
@@ -44,8 +44,8 @@ class Db(object):
 
         try:
             self.__connection = sqlite3.connect(self.__path)
-        except sqlite3.OperationalError:
-            raise stov_exceptions.DBConnectionFailedException()
+        except sqlite3.OperationalError as exc:
+            raise stov_exceptions.DBConnectionFailedException() from exc
         else:
             self.__cursor = self.__connection.cursor()
 
@@ -186,13 +186,12 @@ class Db(object):
         checkresult = self._execute_statement(checkquery, (sub_id,))
         if not checkresult.fetchall():
             raise stov_exceptions.SubscriptionNotFoundException()
-        else:
-            deletevideos = "DELETE FROM videos WHERE subscription_id=?"
-            self._execute_statement(deletevideos, (sub_id,))
-            deletesubscription = "DELETE FROM subscriptions WHERE id=?"
-            self._execute_statement(deletesubscription, (sub_id,))
+        delete_videos = "DELETE FROM videos WHERE subscription_id=?"
+        self._execute_statement(delete_videos, (sub_id,))
+        delete_subscription = "DELETE FROM subscriptions WHERE id=?"
+        self._execute_statement(delete_subscription, (sub_id,))
 
-    def get_videos(self, subscription_id, conf):
+    def get_videos(self, subscription_id):
         """Gets all videos of a given subscription id from the database and
         returns them
 
@@ -287,7 +286,7 @@ class Db(object):
                            "WHERE subscription_id =?"
         self._execute_statement(update_statement, (video_id,))
 
-    def get_subscriptions(self, conf):
+    def get_subscriptions(self):
         """Retrieves all subscriptions from the database"""
         subscriptions_list = []
         subscriptions_query = """SELECT subscriptions.id, subscriptions.title,
@@ -320,7 +319,7 @@ class Db(object):
         Adds a site with the specified name to the database.
 
         :param name: name of the new site
-        :type site: str
+        :type name: str
         """
         insert_statement = "INSERT INTO sites (title) VALUES (?)"
         self._execute_statement(insert_statement, (name,))
@@ -330,7 +329,7 @@ class Db(object):
         Removes a site with the specified name to the database.
 
         :param name: name of the new site
-        :type site: str
+        :type name: str
         """
         site_id = self.get_site_id(name)
         subscriptions = self._get_subscriptions_by_site_id(site_id)
@@ -347,7 +346,7 @@ class Db(object):
         Get the ID of a specific site
 
         :param name: name of the new site
-        :type site: str
+        :type name: str
         :return: the site ID
         :rtype: int
         """

+ 5 - 6
lib_stov/generic_video.py

@@ -1,5 +1,5 @@
 #
-#   This file is part of stov, written by Helmut Pozimski 2012-2015.
+#   This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #   stov is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -28,7 +28,7 @@ from lib_stov import youtubedl_wrapper
 LOGGER = logging.getLogger("stov")
 
 
-class Video(object):
+class Video:
     """This class stores all the attributes of a single video and is
     also able to download it using youtube-dl.
     """
@@ -47,8 +47,6 @@ class Video(object):
 
         :param directory: directory to download to
         :type directory: str
-        :param video_codec: video codec to download
-        :type video_codec: str
         :param url: url to the video
         :type url: str
         :return: boolean value
@@ -59,8 +57,9 @@ class Video(object):
             try:
                 LOGGER.debug(_("Creating directory %s"), targetdir)
                 os.makedirs(targetdir, 0o750)
-            except os.error:
-                raise stov_exceptions.DirectoryCreationFailedException()
+            except os.error as exc:
+                raise stov_exceptions.DirectoryCreationFailedException() \
+                    from exc
 
         os.chdir(targetdir)
         if self.downloaded == 0:

+ 4 - 4
lib_stov/helpers.py

@@ -1,4 +1,4 @@
-#       This file is part of stov, written by Helmut Pozimski 2012-2017.
+#       This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #       stov is free software: you can redistribute it and/or modify
 #       it under the terms of the GNU General Public License as published by
@@ -173,9 +173,9 @@ def create_lock():
             except os.error:
                 LOGGER.error(_("The old lock file could not be deleted!"))
     try:
-        LOCK_FILE = open("/tmp/stov.lock", "w")
-        LOCK_FILE.write(str(os.getpid()))
-        LOCK_FILE.close()
+        lock_file = open("/tmp/stov.lock", "w")
+        lock_file.write(str(os.getpid()))
+        lock_file.close()
     except IOError:
         LOGGER.error(_("The lock file could not be created, please check "
                        "that /tmp is writable and properly configured, "

+ 1 - 1
lib_stov/main.py

@@ -1,4 +1,4 @@
-#   This file is part of stov, written by Helmut Pozimski 2012-2018.
+#   This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #   stov is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by

+ 2 - 2
lib_stov/program.py

@@ -1,4 +1,4 @@
-#       This file is part of stov, written by Helmut Pozimski 2012-2017.
+#       This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #       stov is free software: you can redistribute it and/or modify
 #       it under the terms of the GNU General Public License as published by
@@ -226,7 +226,7 @@ def download_videos(subscriptions=None):
             except stov_exceptions.DBWriteAccessFailedException as error:
                 LOGGER.error(error)
                 sys.exit(1)
-    return (videos_downloaded, videos_failed, video_titles)
+    return videos_downloaded, videos_failed, video_titles
 
 
 def compose_email(downloaded_videos, video_titles):

+ 1 - 1
lib_stov/stov_exceptions.py

@@ -1,4 +1,4 @@
-#       This file is part of stov, written by Helmut Pozimski 2012-2015.
+#       This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #       stov is free software: you can redistribute it and/or modify
 #       it under the terms of the GNU General Public License as published by

+ 4 - 6
lib_stov/subscription.py

@@ -1,5 +1,5 @@
 #
-#   This file is part of stov, written by Helmut Pozimski 2012-2017.
+#   This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #   stov is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -29,7 +29,7 @@ from lib_stov import zdf_mediathek
 LOGGER = logging.getLogger("stov")
 
 
-class Sub(object):
+class Sub:
     """This class constructs a object that stores all the attributes that define
     a subscription and performs the necessary operations on it.
     """
@@ -90,10 +90,8 @@ class Sub(object):
             if self._search != "" and self._conf.values["check_title"] \
                     == "yes":
                 return self._search in video.title
-            else:
-                return self._search.lower() in video.title.lower()
-        else:
-            return False
+            return self._search.lower() in video.title.lower()
+        return False
 
     def gather_videos(self, video_list):
         """Gathers all videos in the subscription and saves

+ 3 - 1
lib_stov/twitch.py

@@ -1,5 +1,5 @@
 #
-#   This file is part of stov, written by Helmut Pozimski 2012-2017.
+#   This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #   stov is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -37,6 +37,8 @@ class Connector(yt_noapi.Connector):
     def __init__(self, subscription_type, name, search=""):
         """Populates the object with all necessary data."""
         yt_noapi.Connector.__init__(self, subscription_type, name, search)
+        self._url = ""
+        self._title = ""
 
     def _construct_url(self):
         """ Constructs the URL for the subscription to retrieve

+ 1 - 1
lib_stov/youtubedl_wrapper.py

@@ -1,5 +1,5 @@
 #
-#        This file is part of stov, written by Helmut Pozimski 2012-2018.
+#        This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #       stov is free software: you can redistribute it and/or modify
 #       it under the terms of the GNU General Public License as published by

+ 8 - 8
lib_stov/yt_noapi.py

@@ -1,5 +1,5 @@
 #
-#        This file is part of stov, written by Helmut Pozimski 2012-2017.
+#        This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #       stov is free software: you can redistribute it and/or modify
 #       it under the terms of the GNU General Public License as published by
@@ -34,7 +34,7 @@ from lib_stov import youtubedl_wrapper
 LOGGER = logging.getLogger("stov")
 
 
-class YtChannel(object):
+class YtChannel:
     """Stores the relevant attributes of a youtube channel."""
 
     def __init__(self, _type, title, videos=None):
@@ -45,7 +45,7 @@ class YtChannel(object):
         self.videos = videos
 
 
-class YtVideo(object):
+class YtVideo:
     """Stores the relevant attributes of a single youtube video."""
 
     def __init__(self, title, ytid):
@@ -53,7 +53,7 @@ class YtVideo(object):
         self.video_id = ytid
 
 
-class Connector(object):
+class Connector:
     """This class will retrieve all the necessary data from youtube using
     youtube-dl, thus bypassing the API.
     """
@@ -98,8 +98,8 @@ class Connector(object):
                 self._construct_url()
                 try:
                     data = urllib.request.urlopen(self._url)
-                except urllib.error.HTTPError:
-                    raise stov_exceptions.ChannelNotFound()
+                except urllib.error.HTTPError as exc:
+                    raise stov_exceptions.ChannelNotFound() from exc
                 else:
                     self._parse_title(data)
             else:
@@ -144,8 +144,8 @@ class Connector(object):
                     try:
                         video_title = youtubedl_wrapper.get_title(
                             self.construct_video_url(video_id))
-                    except subprocess.CalledProcessError:
-                        raise stov_exceptions.YoutubeDlCallFailed()
+                    except subprocess.CalledProcessError as exc:
+                        raise stov_exceptions.YoutubeDlCallFailed() from exc
                     else:
                         videos_list.append(YtVideo(
                             video_title,

+ 4 - 4
lib_stov/zdf_mediathek.py

@@ -1,5 +1,5 @@
 #
-#   This file is part of stov, written by Helmut Pozimski 2012-2018.
+#   This file is part of stov, written by Helmut Pozimski 2012-2021.
 #
 #   stov is free software: you can redistribute it and/or modify
 #   it under the terms of the GNU General Public License as published by
@@ -31,7 +31,7 @@ from lib_stov import stov_exceptions
 LOGGER = logging.getLogger("stov")
 
 
-class ZDFChannel(object):
+class ZDFChannel:
     """Stores the relevant attributes of a ZDF Mediathek channel"""
 
     def __init__(self, title, videos=None):
@@ -42,7 +42,7 @@ class ZDFChannel(object):
         self.type = "channel"
 
 
-class ZDFVideo(object):
+class ZDFVideo:
     """Stores the relevant attributes of a single video in the ZDF
     Mediathek
     """
@@ -52,7 +52,7 @@ class ZDFVideo(object):
         self.video_id = url
 
 
-class Connector(object):
+class Connector:
     """Connector class performing operations against the API"""
 
     def __init__(self, subscription_type, name, search=""):

+ 1 - 1
stov

@@ -4,7 +4,7 @@
 #   stov - a program to subscribe to channels and users from youtube
 #   and download the videos automatically
 #
-#   written by Helmut Pozimski 2012-2017
+#   written by Helmut Pozimski 2012-2021
 #
 #   This program is free software; you can redistribute it and/or
 #   modify it under the terms of the GNU General Public License