def convert(infiles, args, logger, killer): """Takes input files for conversion. Returns the number of failed, completed and copied files, and the time taken to convert. """ options = [] if args["options"] is not None: options.extend(args["options"]) converter = Converter(options, args["threads"]) start_time = time.time() num_files = len(infiles) size_files = fileops.total_size(infiles) update_progress = True while converter.num_converted() < num_files: # Check current processes if converter.check_processes() > 0: print("Logging errors...") converter.log_errors(logger) # update_progress = True if converter.can_add_process() and len(infiles) > 0: inf = infiles.pop() outf = fileops.convert_path(inf, args["indir"], args["outdir"]) outf = os.path.splitext(outf)[0] + (os.extsep + args["outext"]) converter.add_convert_process(inf, outf, pretend=args["pretend"]) update_progress = True # Update the progress if update_progress: time_left = time_remaining( converter.size_conv, size_files - converter.size_conv, time.time() - start_time, ) display_progress(converter.num_converted(), num_files, time_left) update_progress = False # Sleep only if really waiting elif not args["pretend"]: time.sleep(0.05) if killer.kill_now: converter.kill_all() print("Exiting...") exit(1) return converter.failed, converter.completed, time.time() - start_time