Example #1
0
class AptThread(threading.Thread, EventsObject):
    def __init__(self, task_id, task_type, **params):
        EventsObject.__init__(self)
        threading.Thread.__init__(self, None, self._run, None, (task_type, ),
                                  params)

        self.task_id = task_id

        self.ended = threading.Event()
        self.success = threading.Event()
        self.status_changed = threading.Event()

        self.error = ThreadedVar(None)
        self.status = ThreadedVar(None)
        self.task_type = task_type
        self.params = params

    def _run(self, task_type, **params):
        logging.debug("Starting %s thread with params %s" %
                      (task_type, params))

        try:
            if task_type == "install":
                acquire_progress_monitor = AptAcquireProgressMonitor(self)
                install_progress_monitor = AptInstallProgressMonitor(self)
                cache = apt.Cache()
                cache[params["package_name"]].mark_install()
                cache.commit(acquire_progress_monitor,
                             install_progress_monitor)
            elif task_type == "remove":
                acquire_progress_monitor = AptAcquireProgressMonitor(self)
                install_progress_monitor = AptInstallProgressMonitor(self)
                cache = apt.Cache()
                cache[params["package_name"]].mark_delete()
                cache.commit(acquire_progress_monitor,
                             install_progress_monitor)
            elif task_type == "update_cache":
                cache = apt.Cache()
                cache.update()
            elif task_type == "wait":
                # Debugging task
                time.sleep(params["delay"])
            else:
                print "Don't know what to do for task type : " + task_type
            self.success.set()
        except:
            error = sys.exc_info()[1]
            stack = traceback.format_exc()
            logging.error("Error during %s task with params %s : %s" %
                          (task_type, params, str(error)))
            self.error.set_value(stack)
            print stack

        logging.debug("End of %s thread with params %s" % (task_type, params))

        self.ended.set()
class AptThread(threading.Thread, EventsObject):
    def __init__(self, task_id, task_type, **params):
        EventsObject.__init__(self)
        threading.Thread.__init__(self, None, self._run, None, (task_type,), params)
        
        self.task_id = task_id
        
        self.ended = threading.Event()
        self.success = threading.Event()
        self.status_changed = threading.Event()
        
        self.error = ThreadedVar(None)
        self.status = ThreadedVar(None)
        self.task_type = task_type
        self.params = params
    
    def _run(self, task_type, **params):
        logging.debug("Starting %s thread with params %s" % (task_type, params))
        
        try:
            if task_type == "install":
                acquire_progress_monitor = AptAcquireProgressMonitor(self)
                install_progress_monitor = AptInstallProgressMonitor(self)
                cache = apt.Cache()
                cache[params["package_name"]].mark_install()
                cache.commit(acquire_progress_monitor, install_progress_monitor)
            elif task_type == "remove":
                acquire_progress_monitor = AptAcquireProgressMonitor(self)
                install_progress_monitor = AptInstallProgressMonitor(self)
                cache = apt.Cache()
                cache[params["package_name"]].mark_delete()
                cache.commit(acquire_progress_monitor, install_progress_monitor)
            elif task_type == "upgrade":
                acquire_progress_monitor = AptAcquireProgressMonitor(self)
                install_progress_monitor = AptInstallProgressMonitor(self)
                cache = apt.Cache()
                cache[params["package_name"]].mark_delete()
                cache[params["package_name"]].mark_install()
                cache.commit(acquire_progress_monitor, install_progress_monitor)
            elif task_type == "update_cache":
                cache = apt.Cache()
                cache.update()
            elif task_type == "wait":
                # Debugging task
                time.sleep(params["delay"])
            else:
                print "Don't know what to do for task type : " + task_type
            self.success.set()
        except:
            error = sys.exc_info()[1]
            logging.error("Error during %s task with params %s : %s" % (task_type, params, str(error)))
            self.error.set_value(error)
        
        logging.debug("End of %s thread with params %s" % (task_type, params))
        
        self.ended.set()
Example #3
0
    def __init__(self, task_id, task_type, **params):
        EventsObject.__init__(self)
        threading.Thread.__init__(self, None, self._run, None, (task_type, ),
                                  params)

        self.task_id = task_id

        self.ended = threading.Event()
        self.success = threading.Event()
        self.status_changed = threading.Event()

        self.error = ThreadedVar(None)
        self.status = ThreadedVar(None)
        self.task_type = task_type
        self.params = params
Example #4
0
 def __init__(self, task_id, task_type, **params):
     EventsObject.__init__(self)
     threading.Thread.__init__(self, None, self._run, None, (task_type,), params)
     
     self.task_id = task_id
     
     self.ended = threading.Event()
     self.success = threading.Event()
     self.status_changed = threading.Event()
     
     self.error = ThreadedVar(None)
     self.status = ThreadedVar(None)
     self.task_type = task_type
     self.params = params