def execute_library_task_gui(self,
                              videoid,
                              task_type,
                              title,
                              nfo_settings=None,
                              show_prg_dialog=True):
     """
     Execute a library task for a videoid, by showing a GUI progress bar/dialog
     :param videoid: the videoid
     :param task_type: the type of task for the jobs (same used to execute the jobs)
     :param title: title for the progress dialog/background progress bar
     :param nfo_settings: the NFOSettings object containing the user's NFO settings
     :param show_prg_dialog: if True show progress dialog, otherwise, a background progress bar
     """
     list_errors = []
     # Preparation of jobs data for the task
     jobs_data = self.compile_jobs_data(videoid, task_type, nfo_settings)
     # Set a progress bar
     progress_class = ui.ProgressDialog if show_prg_dialog else ui.ProgressBarBG
     with progress_class(show_prg_dialog, title,
                         max_value=len(jobs_data)) as progress_bar:
         # Execute the jobs for the task
         for job_data in jobs_data:
             self._execute_job(task_type, job_data, list_errors)
             progress_bar.perform_step()
             progress_bar.set_message('{} ({}/{})'.format(
                 job_data['title'], progress_bar.value,
                 progress_bar.max_value))
             if progress_bar.is_cancelled():
                 LOG.warn('Library operations interrupted by User')
                 break
             if self.monitor.abortRequested():
                 LOG.warn('Library operations interrupted by Kodi')
                 break
     show_library_task_errors(show_prg_dialog, list_errors)
def execute_tasks(title, tasks, task_handler, **kwargs):
    """
    Run all tasks through task_handler and display a progress dialog in the GUI. Additional kwargs will be
    passed into task_handler on each invocation.
    Returns a list of errors that occured during execution of tasks.
    """
    errors = []
    notify_errors = kwargs.pop('notify_errors', False)
    progress = xbmcgui.DialogProgress()
    progress.create(title)
    for task_num, task in enumerate(tasks):
        task_title = task.get('title', 'Unknown Task')
        progress.update(int(task_num * 100 / len(tasks)), task_title)
        #        xbmc.sleep(25)
        if progress.iscanceled():
            break
        if not task:
            continue
        try:
            task_handler(task, **kwargs)
        except Exception as exc:  # pylint: disable=broad-except
            import traceback
            common.error(traceback.format_exc())
            errors.append({
                'task_title': task_title,
                'error': '{}: {}'.format(type(exc).__name__, exc)
            })
    show_library_task_errors(notify_errors, errors)
    return errors
 def execute_library_task(self,
                          videoid,
                          task_type,
                          nfo_settings=None,
                          notify_errors=False):
     """
     Execute a library task for a videoid
     :param videoid: the videoid
     :param task_type: the type of task for the jobs (same used to execute the jobs)
     :param nfo_settings: the NFOSettings object containing the user's NFO settings
     :param notify_errors: if True a dialog box will be displayed at each error
     """
     list_errors = []
     # Preparation of jobs data for the task
     jobs_data = self.compile_jobs_data(videoid, task_type, nfo_settings)
     if not jobs_data:
         return
     total_jobs = len(jobs_data)
     # Execute the jobs for the task
     for index, job_data in enumerate(jobs_data):
         self._execute_job(task_type, job_data, list_errors)
         yield index, total_jobs, job_data['title']
     show_library_task_errors(notify_errors, list_errors)