Commit 5460e7eb authored by Daalen, Tim van's avatar Daalen, Tim van
Browse files

initial commit

parent 4eb8db23
from genericpath import isfile
from subprocess import Popen, run, PIPE, STDOUT
from glob import glob
from os import getcwd, mkdir, path, remove, sep
from platform import system
Simple pipeline to create pyinstaller executables.
# Run command in shell, stdout is printed to the screen
def run_cmd(cmd):
ps = run(cmd, stderr=STDOUT, shell=True, text=True)
# Print anny errors
if ps.stderr != None:
raise Exception("ui file conversion error")
def ui_to_py(ui_folder):
# python -m PyQt5.uic.pyuic -x main.ui -o
for ui_file in glob(ui_folder + '*'):
filename, ext = path.splitext(ui_file)
print(f"Converting {filename} to .py")
run_cmd(f"""python -m PyQt5.uic.pyuic -x {ui_file} -o {filename +".py"}""")
def remove_pyui_files(ui_folder):
pyuifiles = glob(ui_folder + '*.py')
if len(pyuifiles) > 0:
for file in pyuifiles:
print(f"Removing {file}")
if __name__ == "__main__":
# Convert .ui files to .py files
ui_folder = f"{getcwd()}{sep}gui{sep}ui-files{sep}"
venv = f"{getcwd()}{sep}venv"
# for sending multiple commands in one line
if system()[0].upper() == "W": # windows
cmd_sep = "&&"
else: # Linux
cmd_sep = ";"
# Step 1, convert .ui files to .py files
# remove py files if they already exist, recompiling is the best way to ensure they are up to date
# Step 2: pyinstallers includes all dependencies in the environment, so we use a venv
# Step 2a, ensure the folder for the venv exists
if (not path.exists(venv)) or (not path.isdir(venv)):
# Step 2b, create the venv if needed
venv_activate = venv + f"{sep}Scripts{sep}activate.bat"
if (not path.exists(venv_activate)) or (not path.isfile(venv_activate)):
run_cmd(f"python -m venv {venv}")
run_cmd(f"{venv_activate} {cmd_sep} pip install -r requirements.txt")
# Step 3, activate venv and tun pyinstaller
run_cmd(f"{venv_activate} {cmd_sep} pyinstaller -F --clean {getcwd()}{sep}")
confirmation = input("Do you want to cleanup the build environment (Y/N): ")
if confirmation[0].upper() == 'Y':
remove(getcwd() + sep + "build")
#remove(getcwd() + "dist")
remove(getcwd() + "irods-iBridgesGui.spec")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment