From 0508e559b8a33ecc49eca22b54041792fdeb4122 Mon Sep 17 00:00:00 2001 From: Saifeddine ALOUI Date: Thu, 25 May 2023 22:07:26 +0200 Subject: [PATCH] Added a tool to install all personalities --- installations/download_all_personalities.bat | 16 ++++++ installations/download_all_personalities.py | 55 ++++++++++++++++++++ installations/download_all_personalities.sh | 16 ++++++ 3 files changed, 87 insertions(+) create mode 100644 installations/download_all_personalities.bat create mode 100644 installations/download_all_personalities.py create mode 100644 installations/download_all_personalities.sh diff --git a/installations/download_all_personalities.bat b/installations/download_all_personalities.bat new file mode 100644 index 00000000..db912f98 --- /dev/null +++ b/installations/download_all_personalities.bat @@ -0,0 +1,16 @@ +@echo off + +rem Set the environment name +set environment_name=env + +rem Activate the virtual environment +call %environment_name%\Scripts\activate.bat + +rem Change to the installations subfolder + +rem Run the Python script +python installations/download_all_personalities.py + +rem Deactivate the virtual environment +echo deactivating +call %environment_name%\Scripts\deactivate.bat diff --git a/installations/download_all_personalities.py b/installations/download_all_personalities.py new file mode 100644 index 00000000..624d2e15 --- /dev/null +++ b/installations/download_all_personalities.py @@ -0,0 +1,55 @@ +import os +import shutil +from pathlib import Path + +def copy_files(source_path, destination_path): + for item in os.listdir(source_path): + source_item = source_path / item + destination_item = destination_path / item + + if source_item.is_file(): + # Remove destination file if it already exists + if destination_item.exists(): + destination_item.unlink() + + # Copy file from source to destination + shutil.copy2(str(source_item), str(destination_item)) + + elif source_item.is_dir(): + # Create destination directory if it does not exist + destination_item.mkdir(parents=True, exist_ok=True) + + # Recursively copy files in subdirectories + copy_files(source_item, destination_item) + +import subprocess + +def clone_and_copy_repository(repo_url): + tmp_folder = Path("tmp/git_clone") + personalities_folder = Path("personalities") + subfolder_name = "personalities_zoo" + + # Clone the repository to a temporary folder + subprocess.run(["git", "clone", repo_url, str(tmp_folder)]) + + # Check if the repository was cloned successfully + if not tmp_folder.exists(): + print("Failed to clone the repository.") + return + + # Construct the source and destination paths for copying the subfolder + subfolder_path = tmp_folder / subfolder_name + destination_path = Path.cwd() / personalities_folder + + # Copy files and folders recursively + print(f"copying") + copy_files(subfolder_path, destination_path) + + # Remove the temporary folder + shutil.rmtree(str(tmp_folder)) + + print("Repository clone and copy completed successfully.") + +# Example usage +repo_url = "https://github.com/ParisNeo/PyAIPersonality.git" +clone_and_copy_repository(repo_url) diff --git a/installations/download_all_personalities.sh b/installations/download_all_personalities.sh new file mode 100644 index 00000000..f2e12cfe --- /dev/null +++ b/installations/download_all_personalities.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Set the environment name +environment_name="env" + +# Activate the virtual environment +source "$environment_name/Scripts/activate" + +# Change to the installations subfolder + +# Run the Python script +python installations/download_all_personalities.py + +# Deactivate the virtual environment +echo "deactivating" +deactivate