from libs.spk_v.runtime import SPK_runtime, SPKRPkgTask
from libs.spk_v.tkmg import VTask


class RunPkgTask(VTask):
    def __init__(self, action, target, target_args=None):
        self.action = action
        self.target = target
        self.target_args = target_args

        super().__init__()
        super().init()
    def run(self, task_manager, app):
        app.repository.make_cache()
        runtime = SPK_runtime(app.api, SPK_runtime.default_conf())

        t = SPKRPkgTask(runtime, self.action, self.target, self.target_args)
        runtime.tasks.append(t)
        runtime.exec_tasks()
        super().run(task_manager, app)
