Last active
October 4, 2020 22:09
-
-
Save ppisarczyk/949c02f01dfa0857b48e83ca9984c6ce to your computer and use it in GitHub Desktop.
Process Files with Progress Bar
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def printProgressBar(iteration, total, prefix='', suffix='', | |
decimals=1, length=100, fill='█'): | |
""" | |
Call in a loop to create terminal progress bar | |
@params: | |
iteration - Required : current iteration (Int) | |
total - Required : total iterations (Int) | |
prefix - Optional : prefix string (Str) | |
suffix - Optional : suffix string (Str) | |
decimals - Optional : positive number of decimals in percent complete (Int) | |
length - Optional : character length of bar (Int) | |
fill - Optional : bar fill character (Str) | |
(https://stackoverflow.com/questions/3173320/text-progress-bar-in-the-console) | |
""" | |
percent = ("{0:."+str(decimals)+"f}").format(100*(iteration/float(total))) | |
filledLength = int(length * iteration // total) | |
bar = fill * filledLength + '-' * (length - filledLength) | |
print('\r%s |%s| %s%% %s' % (prefix, bar, percent, suffix), end='\r') | |
# Print New Line on Complete | |
if iteration == total: | |
print() | |
def processFiles(files, destination): | |
""" | |
Process files from list of paths. | |
*files* is a `list` of file paths as `string` | |
*destination* is a `string` of the destination to save the files. | |
""" | |
from fontTools.ttLib import woff2 | |
from fontTools.ttx import makeOutputFileName | |
if not os.path.exists(destination): | |
os.mkdir(destination) | |
print("🏗 Processing Files") | |
printProgressBar(0, len(files), prefix=' ', suffix='Complete', length=50) | |
for i, file in enumerate(files): | |
if os.path.exists(file): | |
print f"Processing File: {file}\n" | |
printProgressBar(i + 1, len(files), prefix=' ', | |
suffix='Complete', length=50) | |
if __name__ == "__main__": | |
import argparse | |
description = "Python Util" | |
parser = argparse.ArgumentParser(description=description) | |
group = parser.add_mutually_exclusive_group() | |
parser.add_argument("directory", help="Directory of files to work on") | |
group.add_argument("-a", "--arg1", action="store_true", | |
help="arg1 help") | |
group.add_argument("-b", "--arg2", action="store_true", | |
help="arg2 help") | |
args = parser.parse_args() | |
if args.arg1: | |
out = os.path.join(args.directory, "NEWDIR") | |
/* files = getFiles(args.directory, 'subfolder') */ | |
files = getFiles(args.directory) | |
print(files) | |
if len(files) != 0: | |
processFiles(files, out) | |
else: | |
print("No Files") | |
if args.arg2: | |
function2(args.directory) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment