def __handle_archive(task: Task, curdir: str, recv_file: str): before = set(os.listdir(curdir)) if '.zip' in task.get_filename(): with zipfile.ZipFile(recv_file, mode='r') as zip_arc: arc_type = 'zip' zip_arc.extractall(path=curdir) else: with tarfile.open(name=recv_file, mode='r:*') as tar: arc_type = 'tar' tar.extractall(path=curdir) after = set(os.listdir(curdir)) if after - (after ^ before) == set(): # No changes in the directory raise RuntimeError('No extraction for {} archive'.format(arc_type)) # There is no need for the archive to stay any longer os.remove(recv_file)
def __init_templ_dct(self, templ_dct, task: Task): """ Function to initialize template dictionary with methods of the related Task object :param task: related task :return: nothing """ templ_dct['__procnum__'] = task.get_procnum() templ_dct['__walltime__'] = task.get_walltime() templ_dct['__memory__'] = task.get_memory() templ_dct['__filename__'] = task.get_filename() templ_dct['__descname__'] = task.get_passport_name() templ_dct['__jobid__'] = task.get_jobid() templ_dct['__name__'] = task.get_name() templ_dct['__user__'] = task.get_user() templ_dct['__taskdir__'] = task.get_dir_name_for_task(self.workdir) templ_dct['__binname__'] = task.get_bin_name() templ_dct['__logname__'] = task.get_log_name() templ_dct['__workdir__'] = self.__get_workdir()