libinstaller/lib/ui.py

61 lines
1.9 KiB
Python

import sys
import time
def progressbar(it, prefix="", size=60, out=sys.stdout):
count = len(it)
def show(j):
x = int(size*j/count)
print("{}[{}{}] {}/{}".format(prefix, u""*x, "."*(size-x), j, count), end='\r', file=out, flush=True)
show(0)
for i, item in enumerate(it):
yield item
show(i+1)
print("", flush=True, file=out)
def bordered(text):
lines = text.splitlines()
width = max(len(s) for s in lines)
res = ['' + '' * width + '']
for s in lines:
res.append('' + (s + ' ' * width)[:width] + '')
res.append('' + '' * width + '')
return '\n'.join(res)
def underlined(text):
lines = text.splitlines()
width = max(len(s) for s in lines)
res = []
for s in lines:
res.append(s)
res.append('' * width)
return '\n'.join(res)
def print_welcome(script_version, compiler, compiler_version, mpi, mpi_version, build_threads, disable_shared_libs, instDir, installs):
if not disable_shared_libs:
shared_str = "Yes"
else:
shared_str = "No"
out = underlined("Patricks Simple Library Installer " + script_version)
out = out + "\n" + "Compiler: " + compiler.upper() + ", Version: " + compiler_version
out = out + "\n" + "MPI: " + mpi.upper() + ", Version: " + mpi_version
out = out + "\n" + "Number of threads to use: " + build_threads
out = out + "\n" + "Building of shared libraries: " + shared_str
out = out + "\n" + "Install Directory: "+instDir
out = out + "\n"
out = out + "\n" + "The following Libraries will be installed:"
for lib in installs:
out = out + "\n" + lib['name'] + " v." + lib['version']
print(bordered(out) + "\n")
# short sleep to enable user to abprt if selected options are wrong
for i in progressbar(range(5), "Waiting 5s to start build: ", 10):
time.sleep(1)
print("\n")