refresh
This commit is contained in:
45
rbuild.py
45
rbuild.py
@ -7,24 +7,27 @@ import os
|
||||
PATH_TO_OPENSCAD = '/usr/bin/openscad'
|
||||
PATH_TO_OPENSCAD_NIGHTLY = '/snap/bin/openscad-nightly'
|
||||
|
||||
|
||||
# For actual dimensions, please see profiles.scad.
|
||||
class BuildSizeConfig:
|
||||
NANO = 'nano'
|
||||
MINI = 'mini'
|
||||
MICRO = 'micro'
|
||||
|
||||
RACK_BUILD_DIR = './rack/print'
|
||||
RACK_MOUNT_BUILD_DIR = './rack-mount/print'
|
||||
|
||||
BUILD_PARENT_DIR = './stl'
|
||||
FILE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
RACK_BUILD_DIR = os.path.join(FILE_DIR, 'rack/print')
|
||||
RACK_MOUNT_BUILD_DIR = os.path.join(FILE_DIR, 'rack-mount/print')
|
||||
BUILD_PARENT_DIR = os.path.join(FILE_DIR, 'stl')
|
||||
|
||||
RACK_BUILD_TARGET_SUB_DIR = 'rack'
|
||||
RACK_MOUNT_BUILD_TARGET_SUB_DIR = 'rack-mount'
|
||||
|
||||
ASSEMBLY_GIF_DIR = './rack/assembly'
|
||||
ASSEMBLY_GIF_BUILD_DIR = './assembly-guide/gifs'
|
||||
ASSEMBLY_GIF_TEMP_DIR = ASSEMBLY_GIF_BUILD_DIR + '/tmp'
|
||||
BUILD_GIF_FROM_PNG_SCRIPT = './misc/animate.sh'
|
||||
ASSEMBLY_GIF_DIR = os.path.join(FILE_DIR, 'rack/assembly')
|
||||
ASSEMBLY_GIF_BUILD_DIR = os.path.join(FILE_DIR, 'assembly-guide/gifs')
|
||||
ASSEMBLY_GIF_TEMP_DIR = os.path.join(ASSEMBLY_GIF_BUILD_DIR, 'tmp')
|
||||
BUILD_GIF_FROM_PNG_SCRIPT = os.path.join(FILE_DIR, 'misc/animate.sh')
|
||||
|
||||
ASSEMBLY_STEPS = [
|
||||
('slideHexNutsIntoYBar.scad', 24),
|
||||
@ -44,10 +47,11 @@ ASSEMBLY_STEPS = [
|
||||
('attachXYPlates.scad', 16)
|
||||
]
|
||||
|
||||
def main():
|
||||
|
||||
def main():
|
||||
if not assertOpenscadExists():
|
||||
print("Could not find OpenSCAD binary. Please make sure it's configured in rbuild.py. Currently only Darwin and Linux have been tested to work.")
|
||||
print(
|
||||
"Could not find OpenSCAD binary. Please make sure it's configured in rbuild.py. Currently only Darwin and Linux have been tested to work.")
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
prog='rbuild',
|
||||
@ -101,7 +105,6 @@ def main():
|
||||
|
||||
|
||||
def run_build(args):
|
||||
|
||||
build_var = args.b
|
||||
config_var = args.c
|
||||
target_var = args.t
|
||||
@ -111,11 +114,11 @@ def run_build(args):
|
||||
|
||||
if (build_var is not None) == (build_gifs is True):
|
||||
print("Please either provide the build (-b) variable, or the build-gifs option (--build-assembly-gifs)")
|
||||
quit()
|
||||
return
|
||||
|
||||
if build_gifs:
|
||||
build_assembly_gifs(config_var, dz, nightly)
|
||||
quit()
|
||||
return
|
||||
|
||||
if target_var != "":
|
||||
final_target_directory_name = target_var
|
||||
@ -123,7 +126,8 @@ def run_build(args):
|
||||
final_target_directory_name = config_var
|
||||
|
||||
rackBuildDirFull = os.path.join(BUILD_PARENT_DIR, final_target_directory_name, RACK_BUILD_TARGET_SUB_DIR)
|
||||
rackMountBuildDirFull = os.path.join(BUILD_PARENT_DIR, final_target_directory_name, RACK_MOUNT_BUILD_TARGET_SUB_DIR)
|
||||
rackMountBuildDirFull = os.path.join(BUILD_PARENT_DIR, final_target_directory_name,
|
||||
RACK_MOUNT_BUILD_TARGET_SUB_DIR)
|
||||
|
||||
if not os.path.exists(rackBuildDirFull):
|
||||
os.makedirs(rackBuildDirFull)
|
||||
@ -136,7 +140,8 @@ def run_build(args):
|
||||
build_single(RACK_BUILD_DIR, rackBuildDirFull, dir_file, config_var, dz, nightly)
|
||||
|
||||
for dir_file in os.listdir(RACK_MOUNT_BUILD_DIR):
|
||||
build_single(RACK_MOUNT_BUILD_DIR, rackMountBuildDirFull, dir_file, config_var, dz, nightly)
|
||||
build_single(RACK_MOUNT_BUILD_DIR, rackMountBuildDirFull, dir_file, config_var, dz,
|
||||
nightly)
|
||||
return
|
||||
|
||||
filename_rack = find_rack(build_var)
|
||||
@ -152,11 +157,13 @@ def run_build(args):
|
||||
if filename_rack_mount:
|
||||
build_single(RACK_MOUNT_BUILD_DIR, rackMountBuildDirFull, filename_rack, config_var, dz, nightly)
|
||||
|
||||
|
||||
def build_single(build_dir, target_dir, filename, config, dz, nightly):
|
||||
print('Building:', filename, 'from', build_dir, 'to', target_dir)
|
||||
openscad_args = construct_openscad_args(build_dir, target_dir, filename, config, dz)
|
||||
run_openscad(openscad_args, nightly)
|
||||
|
||||
|
||||
def build_assembly_gifs(config, dz, nightly):
|
||||
print('Building assembly-gifs. Source Dir:', ASSEMBLY_GIF_DIR, '| Target:', ASSEMBLY_GIF_BUILD_DIR)
|
||||
|
||||
@ -168,11 +175,10 @@ def build_assembly_gifs(config, dz, nightly):
|
||||
run_openscad(openscad_args, nightly)
|
||||
build_gif_from_png(fileName)
|
||||
|
||||
|
||||
def build_gif_from_png(fileName):
|
||||
script_dir = os.path.dirname(os.path.abspath(__file__))
|
||||
script_path = os.path.join(script_dir, BUILD_GIF_FROM_PNG_SCRIPT)
|
||||
try:
|
||||
subprocess.run(["bash", script_path, fileName], check=True)
|
||||
subprocess.run(["bash", BUILD_GIF_FROM_PNG_SCRIPT, fileName], check=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print(f"Error calling shell script: {e}")
|
||||
|
||||
@ -209,7 +215,6 @@ def construct_openscad_animation_args(build_dir, target_dir, filename, config, d
|
||||
return openscad_args
|
||||
|
||||
|
||||
|
||||
def find_rack(filename):
|
||||
return find_scad_file(RACK_BUILD_DIR, filename)
|
||||
|
||||
@ -236,7 +241,6 @@ def find_scad_file(directory, filename):
|
||||
|
||||
|
||||
def run_openscad(options, nightly):
|
||||
|
||||
if nightly:
|
||||
command = [PATH_TO_OPENSCAD_NIGHTLY, '--enable', 'all']
|
||||
else:
|
||||
@ -250,8 +254,11 @@ def run_openscad(options, nightly):
|
||||
print('OpenSCAD command not found! '
|
||||
'Please make sure that you have the OpenSCAD binary configured in rbuild.py.'
|
||||
'(Currently needs Linux/Mac for this)')
|
||||
|
||||
|
||||
def assertOpenscadExists():
|
||||
return os.path.exists(PATH_TO_OPENSCAD)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user