|
| 1 | +import sys |
| 2 | +import os |
| 3 | +import subprocess |
| 4 | +from jinja2 import Environment, select_autoescape, FileSystemLoader |
| 5 | + |
| 6 | + |
| 7 | +def usage(): |
| 8 | + print("Web installer build script") |
| 9 | + print("build.py <installer version> <tag version>") |
| 10 | + print( |
| 11 | + "The installer verison is the version number used within the conda constructor script" |
| 12 | + ) |
| 13 | + print("The tag verison is the version of cadquery that will be pulled from github") |
| 14 | + |
| 15 | + |
| 16 | +def write_file(destpath, contents): |
| 17 | + with open(destpath, "w") as destfile: |
| 18 | + destfile.write(contents) |
| 19 | + |
| 20 | + |
| 21 | +def run_cmd(cmdarray, workingdir, captureout=False): |
| 22 | + stdout = stderr = None |
| 23 | + if captureout: |
| 24 | + stdout = stderr = subprocess.PIPE |
| 25 | + proc = subprocess.Popen( |
| 26 | + cmdarray, cwd=workingdir, stdout=stdout, stderr=stderr, universal_newlines=True |
| 27 | + ) |
| 28 | + proc_out, proc_err = proc.communicate() |
| 29 | + if proc.returncode != 0: |
| 30 | + raise RuntimeError("Failure to run command") |
| 31 | + return stdout, stderr |
| 32 | + |
| 33 | + |
| 34 | +def generate_templates(installer_version, tag_version): |
| 35 | + print("Generating Scripts") |
| 36 | + env = Environment(loader=FileSystemLoader("."), autoescape=select_autoescape()) |
| 37 | + |
| 38 | + template = env.get_template("construct.yaml.jinja2") |
| 39 | + output = template.render(installer_version=installer_version) |
| 40 | + write_file("construct.yaml", output) |
| 41 | + |
| 42 | + template = env.get_template("post-install.bat.jinja2") |
| 43 | + output = template.render(tag_version=tag_version) |
| 44 | + write_file("post-install.bat", output) |
| 45 | + |
| 46 | + template = env.get_template("post-install.sh.jinja2") |
| 47 | + output = template.render(tag_version=tag_version) |
| 48 | + write_file("post-install.sh", output) |
| 49 | + |
| 50 | + |
| 51 | +def run_constructor(): |
| 52 | + print("Running constructor") |
| 53 | + scriptdir = os.path.dirname(os.path.realpath(__file__)) |
| 54 | + builddir = os.path.join(scriptdir, "build") |
| 55 | + if not os.path.exists(builddir): |
| 56 | + os.makedirs(builddir) |
| 57 | + run_cmd(["constructor", scriptdir], builddir) |
| 58 | + |
| 59 | + |
| 60 | +def main(): |
| 61 | + if len(sys.argv) < 2: |
| 62 | + usage() |
| 63 | + return |
| 64 | + installer_version = sys.argv[1] |
| 65 | + tag_version = sys.argv[2] |
| 66 | + generate_templates(installer_version, tag_version) |
| 67 | + run_constructor() |
| 68 | + |
| 69 | + |
| 70 | +main() |
0 commit comments