Browse Source

move deletion of subscriptions to program

Helmut Pozimski 6 years ago
parent
commit
51b71302d4
2 changed files with 28 additions and 23 deletions
  1. 26 5
      lib_stov/program.py
  2. 2 18
      stov

+ 26 - 5
lib_stov/program.py

@@ -100,18 +100,18 @@ def add_subscription(conf, database, channel="", search="", playlist=""):
                 _(" successfully added"))
 
 
-def list_subscriptions(conf, db):
+def list_subscriptions(conf, database):
     """
     Prints a list of subscriptions from the database.
 
     :param conf: configuration object
     :type conf: lib_stov.configuration.Conf
-    :param db: database object
-    :type db: lib_stov.database.Db
+    :param database: database object
+    :type database: lib_stov.database.Db
     """
-    subscriptions_list = db.get_subscriptions(conf)
+    subscriptions_list = database.get_subscriptions(conf)
     sub_state = None
-    if len(subscriptions_list) != 0:
+    if subscriptions_list:
         LOGGER.info(_("ID Title"))
         for sub in subscriptions_list:
             if not sub.disabled:
@@ -122,3 +122,24 @@ def list_subscriptions(conf, db):
                         " (%s)" % sub_state)
     else:
         LOGGER.info(_("No subscriptions added yet, add one!"))
+
+
+def delete_subscription(database, sub_id):
+    """
+    Deletes a specified subscription from the database
+
+    :param database: database object
+    :type database: lib_stov.database.Db
+    :param sub_id: ID of the subscription to be deleted
+    :type sub_id: int
+    """
+    try:
+        database.delete_subscription(sub_id)
+    except stov_exceptions.SubscriptionNotFoundException as error:
+        LOGGER.error(error)
+        sys.exit(1)
+    except stov_exceptions.DBWriteAccessFailedException as error:
+        LOGGER.error(error)
+        sys.exit(1)
+    else:
+        LOGGER.info(_("Subscription deleted successfully!"))

+ 2 - 18
stov

@@ -61,24 +61,8 @@ if ARGUMENTS.add:
                              ARGUMENTS.playlist)
 elif ARGUMENTS.list:
     program.list_subscriptions(CONF, DB)
-elif ARGUMENTS.deleteid is not None:
-    try:
-        DELETE_ID = int(ARGUMENTS.deleteid)
-    except ValueError:
-        LOGGER.error(_("Invalid option, please use the ID of the subscription "
-                       "you want to delete as parameter for the remove "
-                       "option."))
-    else:
-        try:
-            DB.delete_subscription(DELETE_ID)
-        except stov_exceptions.SubscriptionNotFoundException as error:
-            LOGGER.error(error)
-            sys.exit(1)
-        except stov_exceptions.DBWriteAccessFailedException as error:
-            LOGGER.error(error)
-            sys.exit(1)
-        else:
-            LOGGER.info(_("Subscription deleted successfully!"))
+elif ARGUMENTS.deleteid:
+    program.delete_subscription(DB, ARGUMENTS.deleteid)
 elif ARGUMENTS.update is True:
     SUBSCRIPTIONS_LIST = DB.get_subscriptions(CONF)
     for element in SUBSCRIPTIONS_LIST: