From 45ebb89fc7833ccbd1f44d522517eed2895629e5 Mon Sep 17 00:00:00 2001 From: gribse Date: Tue, 5 Nov 2024 13:10:30 +0100 Subject: [PATCH] change version in filename --- GestionVersion2.3.py => GestionVersion2.4.py | 75 ++++++++++++++------ 1 file changed, 53 insertions(+), 22 deletions(-) rename GestionVersion2.3.py => GestionVersion2.4.py (75%) diff --git a/GestionVersion2.3.py b/GestionVersion2.4.py similarity index 75% rename from GestionVersion2.3.py rename to GestionVersion2.4.py index b1198cf..06fac89 100644 --- a/GestionVersion2.3.py +++ b/GestionVersion2.4.py @@ -2,19 +2,19 @@ # - Make an AVP folder in the current directory whe creating a new project # - Make a BPE folder in the current directory whe creating a new project - - import os import datetime +import requests -#If colorama is not installed, notify the user +# If colorama is not installed, notify the user try: from colorama import init, Fore, Style except ImportError: print("Please install the colorama module using 'pip install colorama' to enable colored text.") Fore = Style = lambda x: x -debug_mode = True +debug_mode = False +software_version = "2.4" # Initialize colorama init() @@ -22,20 +22,25 @@ init() # Function to pause if debug mode is enabled def pause_debug(message="No message provided."): if debug_mode: - input(Fore.YELLOW + "[DEBUG] " + message + " - Enter to continue.\n" + Style.RESET_ALL) + input(Fore.YELLOW + "[DEBUG] " + message + " - Enter to continue.\n" + Style.RESET_ALL) + +# Function to check the latest version from Gitea +def check_latest_version(): + gitea_api_url = "https://gitea.achilletoupin.com/api/v1/repos/gribse/gestionProjets/releases/latest" + try: + response = requests.get(gitea_api_url) + response.raise_for_status() + latest_release = response.json() + latest_version = latest_release['tag_name'] + pause_debug(Fore.GREEN + "Latest version: " + latest_version + Style.RESET_ALL) + return latest_version + except requests.RequestException as e: + print(Fore.RED + "Error checking latest version: " + str(e) + Style.RESET_ALL) + return None -current_directory = os.path.dirname(os.path.abspath(__file__)) # Get the current directory -os.chdir(current_directory) -pause_debug(f"Current directory: {current_directory}") - -avp_directory = os.path.join(current_directory, "AVP") # Set the source directory to the 'Projets' directory -pause_debug(f"AVP directory: {avp_directory}") - def createNewProject(): - - # Prompt the user for the project name project_name = input("Enter the project name:\n") pause_debug(f"Project name entered: {project_name}") @@ -58,14 +63,14 @@ def createNewProject(): # Find the folder with the largest number after the year and month if not folders: - new_number = 1 + projet_number_in_month = 1 else: latest_number = max(int(f.split()[2]) for f in folders) - new_number = latest_number + 1 - pause_debug(f"New folder number determined: {new_number}") + projet_number_in_month = latest_number + 1 + pause_debug(f"New folder number determined: {projet_number_in_month}") # Create the new folder name - new_folder_name = f"{current_year} {current_month} {new_number} {project_name}" + new_folder_name = f"{current_year} {current_month} {projet_number_in_month} {project_name}" pause_debug(f"New folder name: {new_folder_name}") # Create the new folder @@ -89,6 +94,13 @@ def createNewProject(): os.makedirs(avp_folder_path, exist_ok=True) os.makedirs(bpe_folder_path, exist_ok=True) pause_debug(f"AVP and BPE folders created in {new_folder_name}") + + # Create the first AVP folder + createNewAVP() + + # Create a placeholder file to indicate the default file name + placeholder_filename = f"{current_year}{current_month}{projet_number_in_month}AVP01-{project_name}" + placeholder_file_path = os.path.join(new_folder_path, "README.txt") def createNewAVP(): # Creating AVP folders @@ -102,10 +114,10 @@ def createNewAVP(): else: pause_debug("Finding the latest folder") latest_number = max(int(f[3:]) for f in folders) - new_number = latest_number + 1 - new_number = str(new_number).zfill(2) - new_folder_name = f"AVP{str(new_number).zfill(2)}" - pause_debug(f"New folder number determined: {new_number}") + projet_number_in_month = latest_number + 1 + projet_number_in_month = str(projet_number_in_month).zfill(2) + new_folder_name = f"AVP{str(projet_number_in_month).zfill(2)}" + pause_debug(f"New folder number determined: {projet_number_in_month}") input(f"\nWould you like to create {new_folder_name}? Press any key to continue or CTRL+C to exit...") pause_debug(f"User confirmed creation of new folder: {new_folder_name}") @@ -170,8 +182,27 @@ def displayHelp(): print("You can press 'Q' to quit the program.") def main(): + # Display the welcome message displayWelcomeMessage() + # Check if the current version is equal to the latest version + latest_version = check_latest_version() + if latest_version: + if software_version == latest_version: + print(Fore.GREEN + f"You are using the latest version: {software_version}" + Style.RESET_ALL) + elif software_version > latest_version: + print(Fore.YELLOW + f"You are using a newer version: {software_version}. The latest version is: {latest_version}" + Style.RESET_ALL) + else: + print(Fore.RED + f"A new version is available: {latest_version}. You are using version: {software_version}" + Style.RESET_ALL) + else: + print(Fore.RED + "Could not check the latest version." + Style.RESET_ALL) + + # Get the various directories + current_directory = os.path.dirname(os.path.abspath(__file__)) # Get the current directory + pause_debug(f"Current directory: {current_directory}") + avp_directory = os.path.join(current_directory, "AVP") # Set the source directory to the 'Projets' directory + pause_debug(f"AVP directory: {avp_directory}") + # Check if the current directory is a parent directory named "Projets", and if so, ask the user if they want to initiate a new project if os.path.basename(os.path.dirname(avp_directory)) == "Projets": pause_debug("Checked parent directory. It is named 'Projets'.")