From 3b0bb2c75a8988451ba19d187d77b4ca0b538c30 Mon Sep 17 00:00:00 2001 From: Rajdeep Roy Chowdhury Date: Sun, 14 Jun 2026 09:27:31 +0530 Subject: [PATCH 1/4] feat: upload and download scripts templatized Signed-off-by: Rajdeep Roy Chowdhury --- scripts/configure-backup.py | 61 +++++++++++++++++++ .../download.template.bat} | 12 ++-- scripts/templates/download.template.sh | 16 +++++ scripts/templates/upload.template.bat | 7 +++ scripts/templates/upload.template.sh | 16 +++++ scripts/upload.bat | 7 --- 6 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 scripts/configure-backup.py rename scripts/{download.bat => templates/download.template.bat} (71%) create mode 100644 scripts/templates/download.template.sh create mode 100644 scripts/templates/upload.template.bat create mode 100644 scripts/templates/upload.template.sh delete mode 100644 scripts/upload.bat diff --git a/scripts/configure-backup.py b/scripts/configure-backup.py new file mode 100644 index 0000000..b7875f3 --- /dev/null +++ b/scripts/configure-backup.py @@ -0,0 +1,61 @@ +import platform +import re + +year = str(input("Enter financial year in the format like (2026-27): ")) + + +def check_valid_financial_year(year: str): + if not re.fullmatch(r"\d{4}-\d{2}", year): + return False + start_year = year.split("-")[0][2:] + end_year = year.split("-")[1] + print(f"start_year: {start_year}, end_year: {end_year}") + return int(start_year) + 1 == int(end_year) + + +if not check_valid_financial_year(year): + print("Please enter a valid financial year in the format like (2026-27)") + exit(0) + +os_name = platform.system() + + +def replace_in_template(input_file, output_file, placeholder, replacement): + with open(f"templates/{input_file}", "r") as f: + lines = f.readlines() + new_lines = [] + for line in lines: + new_line = line.replace(placeholder, replacement) + new_lines.append(new_line) + with open(output_file, "w") as f: + f.writelines(new_lines) + + +def generate_bash_scripts(): + replace_in_template( + "download.template.sh", "download.sh", "{{PLACEHOLDER_YEAR}}", year + ) + replace_in_template("upload.template.sh", "upload.sh", "{{PLACEHOLDER_YEAR}}", year) + + +def generate_batch_scripts(): + replace_in_template( + "download.template.bat", "download.bat", "{{PLACEHOLDER_YEAR}}", year + ) + replace_in_template( + "upload.template.bat", "upload.bat", "{{PLACEHOLDER_YEAR}}", year + ) + + +if os_name == "Windows": + print("Running on Windows") + generate_batch_scripts() +elif os_name == "Darwin": + print("Running on macOS") + generate_bash_scripts() +elif os_name == "Linux": + print("Running on Linux") + generate_bash_scripts() +else: + print(f"Unknown OS: {os_name}") + exit(1) diff --git a/scripts/download.bat b/scripts/templates/download.template.bat similarity index 71% rename from scripts/download.bat rename to scripts/templates/download.template.bat index 0bab102..bcdd69b 100644 --- a/scripts/download.bat +++ b/scripts/templates/download.template.bat @@ -1,11 +1,11 @@ -@echo off +@echo off echo "Fetching Database from remote" - -cd Satyam-Database-2026-27 + +cd Satyam-Database-{{PLACEHOLDER_YEAR}} git pull origin main - + git reset --hard copy database.db ..\database.db - -pause + +pause diff --git a/scripts/templates/download.template.sh b/scripts/templates/download.template.sh new file mode 100644 index 0000000..d0236a8 --- /dev/null +++ b/scripts/templates/download.template.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +DIR=Satyam-Database-{{PLACEHOLDER_YEAR}} + +if [ ! -d "$DIR" ]; then + echo "$DIR Directory does not exist" + exit 1 +fi + +cd $DIR || exit 1 + +echo "Fetching Database from remote" +git pull origin main + +git reset --hard +cp database.db ../database.db diff --git a/scripts/templates/upload.template.bat b/scripts/templates/upload.template.bat new file mode 100644 index 0000000..cdbb68f --- /dev/null +++ b/scripts/templates/upload.template.bat @@ -0,0 +1,7 @@ +@echo off +copy database.db Satyam-Database-{{PLACEHOLDER_YEAR}}\database.db +cd Satyam-Database-{{PLACEHOLDER_YEAR}} +git add . +git commit -m "Updated database" +git push origin main +pause diff --git a/scripts/templates/upload.template.sh b/scripts/templates/upload.template.sh new file mode 100644 index 0000000..fb66cb9 --- /dev/null +++ b/scripts/templates/upload.template.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash + +DIR=Satyam-Database-{{PLACEHOLDER_YEAR}} + +if [ ! -d "$DIR" ]; then + echo "$DIR Directory does not exist" + exit 1 +fi + +cp database.db $DIR\database.db + +cd $DIR + +git add . +git commit -m "Updated database" +git push origin main diff --git a/scripts/upload.bat b/scripts/upload.bat deleted file mode 100644 index ff9f6e3..0000000 --- a/scripts/upload.bat +++ /dev/null @@ -1,7 +0,0 @@ -@echo off -copy database.db Satyam-Database-2026-27\database.db -cd Satyam-Database-2026-27 -git add . -git commit -m "Updated database" -git push origin main -pause From affaa330d3453e57f51b696f4f0925caf9eec5b5 Mon Sep 17 00:00:00 2001 From: Rajdeep Roy Chowdhury Date: Sun, 14 Jun 2026 10:07:48 +0530 Subject: [PATCH 2/4] feat: init git repo added in configure-backup.py Signed-off-by: Rajdeep Roy Chowdhury --- build.gradle.kts | 2 +- scripts/configure-backup.py | 40 +++++++++++++++++++++++++++++-------- 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index e63c31c..33d8448 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -97,7 +97,7 @@ tasks.named("jar") { enabled = false } val copyScripts by tasks.registering(Copy::class) { from("scripts") { - include("start.sh", "start.bat", "download.bat", "upload.bat") + include("start.sh", "start.bat", "configure-backup.py", "templates/**") } into(layout.buildDirectory.dir("libs")) doLast { diff --git a/scripts/configure-backup.py b/scripts/configure-backup.py index b7875f3..6384764 100644 --- a/scripts/configure-backup.py +++ b/scripts/configure-backup.py @@ -1,5 +1,7 @@ import platform import re +import subprocess +from pathlib import Path year = str(input("Enter financial year in the format like (2026-27): ")) @@ -9,17 +11,9 @@ def check_valid_financial_year(year: str): return False start_year = year.split("-")[0][2:] end_year = year.split("-")[1] - print(f"start_year: {start_year}, end_year: {end_year}") return int(start_year) + 1 == int(end_year) -if not check_valid_financial_year(year): - print("Please enter a valid financial year in the format like (2026-27)") - exit(0) - -os_name = platform.system() - - def replace_in_template(input_file, output_file, placeholder, replacement): with open(f"templates/{input_file}", "r") as f: lines = f.readlines() @@ -47,6 +41,36 @@ def generate_batch_scripts(): ) +def init_github_repository(): + repo_name = f"Satyam-Database-{year}" + if (Path(repo_name) / ".git").is_dir(): + print(f"{repo_name} already exists, so skipping clone") + return + github_username = "drcbabu81" + repo_url = f"git@github.com:{github_username}/{repo_name}.git" + + try: + subprocess.run( + ["git", "clone", repo_url], check=True, capture_output=True, text=True + ) + + if (Path(repo_name) / ".git").is_dir(): + print("Clone successful") + else: + print("Git returned success but .git directory is missing") + + except subprocess.CalledProcessError as e: + print("Clone failed") + print(e.stderr) + + +if not check_valid_financial_year(year): + print("Please enter a valid financial year in the format like (2026-27)") + exit(0) + +os_name = platform.system() +init_github_repository() + if os_name == "Windows": print("Running on Windows") generate_batch_scripts() From 3aa70d476d43bf660296a3457df3994a0b853091 Mon Sep 17 00:00:00 2001 From: Rajdeep Roy Chowdhury Date: Sun, 14 Jun 2026 11:11:34 +0530 Subject: [PATCH 3/4] feat: making unix scripts executable Signed-off-by: Rajdeep Roy Chowdhury --- scripts/configure-backup.py | 190 ++++++++++++++++++++---------------- 1 file changed, 105 insertions(+), 85 deletions(-) diff --git a/scripts/configure-backup.py b/scripts/configure-backup.py index 6384764..f2c7503 100644 --- a/scripts/configure-backup.py +++ b/scripts/configure-backup.py @@ -1,85 +1,105 @@ -import platform -import re -import subprocess -from pathlib import Path - -year = str(input("Enter financial year in the format like (2026-27): ")) - - -def check_valid_financial_year(year: str): - if not re.fullmatch(r"\d{4}-\d{2}", year): - return False - start_year = year.split("-")[0][2:] - end_year = year.split("-")[1] - return int(start_year) + 1 == int(end_year) - - -def replace_in_template(input_file, output_file, placeholder, replacement): - with open(f"templates/{input_file}", "r") as f: - lines = f.readlines() - new_lines = [] - for line in lines: - new_line = line.replace(placeholder, replacement) - new_lines.append(new_line) - with open(output_file, "w") as f: - f.writelines(new_lines) - - -def generate_bash_scripts(): - replace_in_template( - "download.template.sh", "download.sh", "{{PLACEHOLDER_YEAR}}", year - ) - replace_in_template("upload.template.sh", "upload.sh", "{{PLACEHOLDER_YEAR}}", year) - - -def generate_batch_scripts(): - replace_in_template( - "download.template.bat", "download.bat", "{{PLACEHOLDER_YEAR}}", year - ) - replace_in_template( - "upload.template.bat", "upload.bat", "{{PLACEHOLDER_YEAR}}", year - ) - - -def init_github_repository(): - repo_name = f"Satyam-Database-{year}" - if (Path(repo_name) / ".git").is_dir(): - print(f"{repo_name} already exists, so skipping clone") - return - github_username = "drcbabu81" - repo_url = f"git@github.com:{github_username}/{repo_name}.git" - - try: - subprocess.run( - ["git", "clone", repo_url], check=True, capture_output=True, text=True - ) - - if (Path(repo_name) / ".git").is_dir(): - print("Clone successful") - else: - print("Git returned success but .git directory is missing") - - except subprocess.CalledProcessError as e: - print("Clone failed") - print(e.stderr) - - -if not check_valid_financial_year(year): - print("Please enter a valid financial year in the format like (2026-27)") - exit(0) - -os_name = platform.system() -init_github_repository() - -if os_name == "Windows": - print("Running on Windows") - generate_batch_scripts() -elif os_name == "Darwin": - print("Running on macOS") - generate_bash_scripts() -elif os_name == "Linux": - print("Running on Linux") - generate_bash_scripts() -else: - print(f"Unknown OS: {os_name}") - exit(1) +#!/usr/bin/env python3 + +import platform +import re +import subprocess +from pathlib import Path +import os +import stat +import logging + +logging.basicConfig( + level=logging.DEBUG, + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" +) +logger = logging.getLogger(__name__) + +year = str(input("Enter financial year in the format like (2026-27): ")) + + +def check_valid_financial_year(year: str): + if not re.fullmatch(r"\d{4}-\d{2}", year): + return False + start_year = year.split("-")[0][2:] + end_year = year.split("-")[1] + return int(start_year) + 1 == int(end_year) + + +def replace_in_template(input_file, output_file, placeholder, replacement): + logger.info(f"generating {output_file}") + with open(f"templates/{input_file}", "r") as f: + lines = f.readlines() + new_lines = [] + for line in lines: + new_line = line.replace(placeholder, replacement) + new_lines.append(new_line) + with open(output_file, "w") as f: + f.writelines(new_lines) + + +def make_executable(filename): + st = os.stat(filename) + os.chmod(filename, st.st_mode | stat.S_IXUSR) + + +def generate_bash_scripts(): + logger.info("generating bash scripts") + replace_in_template( + "download.template.sh", "download.sh", "{{PLACEHOLDER_YEAR}}", year + ) + replace_in_template("upload.template.sh", "upload.sh", "{{PLACEHOLDER_YEAR}}", year) + make_executable("download.sh") + make_executable("upload.sh") + make_executable("start.sh") + + +def generate_batch_scripts(): + logger.info("generating batch scripts") + replace_in_template( + "download.template.bat", "download.bat", "{{PLACEHOLDER_YEAR}}", year + ) + replace_in_template( + "upload.template.bat", "upload.bat", "{{PLACEHOLDER_YEAR}}", year + ) + + +def init_github_repository(): + repo_name = f"Satyam-Database-{year}" + if (Path(repo_name) / ".git").is_dir(): + logger.info(f"{repo_name} already exists, so skipping clone") + return + github_username = "drcbabu81" + repo_url = f"git@github.com:{github_username}/{repo_name}.git" + + try: + logger.info(f'cloning {repo_name}') + subprocess.run( + ["git", "clone", repo_url], check=True, capture_output=True, text=True + ) + + if (Path(repo_name) / ".git").is_dir(): + logger.info("clone successful") + else: + logger.error("git returned success but .git directory is missing") + + except subprocess.CalledProcessError as e: + logger.error("clone failed") + logger.error(e.stderr) + + +if not check_valid_financial_year(year): + logger.error("Please enter a valid financial year in the format like (2026-27)") + exit(0) + +os_name = platform.system() +init_github_repository() + +if os_name == "Windows": + generate_batch_scripts() +elif os_name == "Darwin": + generate_bash_scripts() +elif os_name == "Linux": + generate_bash_scripts() +else: + logger.error(f"Unknown OS: {os_name}") + exit(1) From f0a163a28f48783efcf148cc3cb664f4bc4a00de Mon Sep 17 00:00:00 2001 From: Rajdeep Roy Chowdhury Date: Sun, 14 Jun 2026 11:13:24 +0530 Subject: [PATCH 4/4] refactor: formatting Signed-off-by: Rajdeep Roy Chowdhury --- scripts/configure-backup.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/configure-backup.py b/scripts/configure-backup.py index f2c7503..28a5ce9 100644 --- a/scripts/configure-backup.py +++ b/scripts/configure-backup.py @@ -9,8 +9,7 @@ import logging logging.basicConfig( - level=logging.DEBUG, - format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" + level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) logger = logging.getLogger(__name__) @@ -72,7 +71,7 @@ def init_github_repository(): repo_url = f"git@github.com:{github_username}/{repo_name}.git" try: - logger.info(f'cloning {repo_name}') + logger.info(f"cloning {repo_name}") subprocess.run( ["git", "clone", repo_url], check=True, capture_output=True, text=True )