Browse Source

move main functionality to main module

Helmut Pozimski 6 years ago
parent
commit
705df10050
2 changed files with 71 additions and 52 deletions
  1. 67 0
      lib_stov/main.py
  2. 4 52
      stov

+ 67 - 0
lib_stov/main.py

@@ -0,0 +1,67 @@
+#   This file is part of stov, written by Helmut Pozimski 2012-2017.
+#
+#   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.
+#
+#   stov is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with stov.  If not, see <http://www.gnu.org/licenses/>.
+
+
+# -*- coding: utf8 -*-
+
+""" Contains the main function of stov to start the application.
+"""
+import logging
+
+from lib_stov import helpers
+from lib_stov import program
+
+
+def main():
+    """
+    Main function
+    """
+    helpers.initialize_gettext()
+    helpers.setup_sighandler()
+    parser = helpers.parse_arguments()
+    arguments = parser.parse_args()
+    helpers.create_lock()
+    conf = helpers.setup_configuration(arguments)
+    logger = logging.getLogger("stov")
+    database = helpers.setup_database(conf)
+    helpers.find_youtubedl(conf)
+    if arguments.add:
+        program.add_subscription(conf, database, arguments.channel,
+                                 arguments.searchparameter,
+                                 arguments.playlist)
+    elif arguments.list:
+        program.list_subscriptions(conf, database)
+    elif arguments.deleteid:
+        program.delete_subscription(database, arguments.deleteid)
+    elif arguments.update:
+        program.update_subscriptions(database, conf)
+    elif arguments.download:
+        program.download_notify(database, conf)
+    elif arguments.subscriptionid:
+        program.list_videos(database, conf, arguments.subscriptionid)
+    elif arguments.catchup:
+        program.catchup(database, arguments.catchup)
+    elif arguments.cleanup:
+        program.clean_database(database, conf)
+    elif arguments.enableid:
+        program.change_subscription_state(database, arguments.enableid, True)
+    elif arguments.disableid:
+        program.change_subscription_state(database, arguments.disableid, False)
+    elif arguments.license:
+        program.print_license()
+    elif arguments.version:
+        logger.info("1.0wip")
+    else:
+        parser.print_help()
+    helpers.remove_lock()

+ 4 - 52
stov

@@ -21,57 +21,9 @@
 #   Foundation, Inc., 51 Franklin Street, Fifth Floor,
 #   Boston, MA 02110-1301, USA.
 
-"""This is the main script of stov, it can be directly called and glues
-everything together, performing all the actions a user wants.
-"""
+""" Executes the main function of stov """
 
-import logging
+from lib_stov.main import main
 
-from lib_stov import helpers
-from lib_stov import program
-
-
-helpers.initialize_gettext()
-helpers.setup_sighandler()
-PARSER = helpers.parse_arguments()
-ARGUMENTS = PARSER.parse_args()
-helpers.create_lock()
-CONF = helpers.setup_configuration(ARGUMENTS)
-LOGGER = logging.getLogger("stov")
-DB = helpers.setup_database(CONF)
-helpers.find_youtubedl(CONF)
-
-
-"""Check which ARGUMENTS are given on the command line and
-run the corresponding code
-
-"""
-if ARGUMENTS.add:
-    program.add_subscription(CONF, DB, ARGUMENTS.channel,
-                             ARGUMENTS.searchparameter,
-                             ARGUMENTS.playlist)
-elif ARGUMENTS.list:
-    program.list_subscriptions(CONF, DB)
-elif ARGUMENTS.deleteid:
-    program.delete_subscription(DB, ARGUMENTS.deleteid)
-elif ARGUMENTS.update:
-    program.update_subscriptions(DB, CONF)
-elif ARGUMENTS.download:
-    program.download_notify(DB, CONF)
-elif ARGUMENTS.subscriptionid:
-    program.list_videos(DB, CONF, ARGUMENTS.subscriptionid)
-elif ARGUMENTS.catchup:
-    program.catchup(DB, ARGUMENTS.catchup)
-elif ARGUMENTS.cleanup:
-    program.clean_database(DB, CONF)
-elif ARGUMENTS.enableid:
-    program.change_subscription_state(DB, ARGUMENTS.enableid, True)
-elif ARGUMENTS.disableid:
-    program.change_subscription_state(DB, ARGUMENTS.disableid, False)
-elif ARGUMENTS.license:
-    program.print_license()
-elif ARGUMENTS.version:
-    LOGGER.info("1.0wip")
-else:
-    PARSER.print_help()
-helpers.remove_lock()
+if __name__ == "__main__":
+    main()