Skip to content

Commit

Permalink
Add option for cli install folder definition
Browse files Browse the repository at this point in the history
  • Loading branch information
aelmiger committed Oct 24, 2023
1 parent dac839b commit 34d925a
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
12 changes: 10 additions & 2 deletions syclops/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
nargs="*",
)

parser.add_argument(
"-if",
"--install_folder",
help="Path to install folder",
default=None,
)


def _run_subprocess(args, cwd=None, env=None, execution_info="Command"):
process_result = subprocess.run(args, cwd=cwd, env=env)
Expand Down Expand Up @@ -309,13 +316,14 @@ def _ensure_catalog_exists(install_folder: Path):


def main():
install_folder = get_or_create_install_folder()
args = parser.parse_args()

install_folder = get_or_create_install_folder(args.install_folder)
install_blender(BLENDER_VERSION, install_folder)
_ensure_catalog_exists(install_folder)
console = Console()
console.print(f"Syclops folder: {install_folder}", style="bold green")

args = parser.parse_args()

if len(sys.argv) == 1:
parser.print_help()
Expand Down
38 changes: 25 additions & 13 deletions syclops/utility/setup_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,25 +95,37 @@ def install_blender(version: str, install_dir: Path) -> None:
# Clean up
dest_file.unlink()

def get_or_create_install_folder() -> Path:
def get_or_create_install_folder(install_folder_path: Path) -> Path:
"""
Get the install folder from the config file, or ask the user for a folder.
Args:
install_folder_path (Path): The path to the install folder, if it exists.
Returns:
Path: The path to the install folder.
"""
config = _load_config()
install_folder_key = "install_folder"

# If 'install_folder' is not in the config, ask the user and save it
if "install_folder" not in config:
install_folder = _ask_directory().resolve()
config["install_folder"] = str(install_folder)
def determine_folder():
if install_folder_path is not None:
return install_folder_path.resolve()
return _ask_directory().resolve()

# If 'install_folder' is not in the config or the saved folder doesn't exist
if install_folder_key not in config or not Path(config[install_folder_key]).exists():
install_folder = determine_folder()
config[install_folder_key] = str(install_folder)
_write_config(config)
else:
install_folder = Path(config["install_folder"]).resolve()
if not install_folder.exists():
install_folder = _ask_directory().resolve()
config["install_folder"] = str(install_folder)
_write_config(config)

if not install_folder.exists():
install_folder.mkdir(parents=True, exist_ok=True)
install_folder = Path(config[install_folder_key]).resolve()

# Ensure the folder exists
install_folder.mkdir(parents=True, exist_ok=True)
return install_folder


def _load_config() -> dict:
config_file = _get_or_create_config_file_path()
if config_file.exists():
Expand Down

0 comments on commit 34d925a

Please sign in to comment.