from st2actions.runners.pythonrunner import Action
import st2common.config as config
from st2common.persistence import action


class UnregisterPackAction(Action):

    def run(self, packs=None):
        self._setup()
        for pack in packs:
            self.logger.debug('Removing pack %s.', pack)
            self._unregister_rules(pack)
            self._unregister_triggers(pack)
            self._unregister_trigger_types(pack)
            self._unregister_actions(pack)
            self.logger.info('Removed pack %s.', pack)

    def _setup(self):
        try:
            config.parse_args()
        except:
            pass

    def _unregister_rules(self, pack):
        pass

    def _unregister_triggers(self, pack):
        pass

    def _unregister_trigger_types(self, pack):
        pass

    def _unregister_actions(self, pack):
        action_dbs = action.Action.get_all(pack=pack)
        for action_db in action_dbs:
            try:
                action.Action.delete(action_db)
            except:
                self.logger.exception('Failed to remove action %s.', action_db)

@@ -1,16 +1,120 @@
+from oslo.config import cfg%0A%0Aimport st2common.config as config%0Afrom st2common.models.db import db_setup%0A
 from st2actions.
@@ -152,42 +152,8 @@
 ion%0A
-import st2common.config as config%0A
 from
@@ -620,16 +620,42 @@
 (self):%0A
+        # 1. Parse config%0A
         
@@ -717,32 +717,409 @@
           pass%0A%0A
+        # 2. Setup db connection%0A        username = cfg.CONF.database.username if hasattr(cfg.CONF.database, 'username') else None%0A        password = cfg.CONF.database.password if hasattr(cfg.CONF.database, 'password') else None%0A        db_setup(cfg.CONF.database.db_name, cfg.CONF.database.host, cfg.CONF.database.port,%0A                 username=username, password=password)%0A%0A
     def _unregis

Fix packs.unload action.