massive code refactor

most if not all functions were moved out of the main code body, lots of reformatting, whitespace and general spacing fixes, etc.
This commit is contained in:
Obie Hinojosa 2024-10-30 21:33:57 -07:00
parent 944c9e8b0c
commit dd2e5a6eb6

View File

@ -6,65 +6,23 @@ import time
import shutil import shutil
from pathlib import Path from pathlib import Path
#detect operating system and find home, minecraft, & mod folders
homedir = os.path.expanduser("~")
os.chdir(homedir)
# `global` sets these variables to exist outside of the scope of these specific `if` statements.
global mcfolder
global modfolder
if platform.system() == "Linux":
print("Operating system detected: Linux")
os.chdir(homedir + '/.minecraft')
mcfolder = Path.cwd()
modfolder = mcfolder + '/mods'
elif platform.system() == "Windows":
print("Operating system detected: Windows")
os.chdir("AppData/Roaming/.minecraft/mods")
mcfolder = Path.cwd()
modfolder = mcfolder + '/mods'
os.chdir(mcfolder) #define some functions ahead of time
print("Changed current working directory to '" + str(mcfolder) + "'")
time.sleep(2)
# delete previous mods def delete_directory(directory):
# WARN: THIS DOESN'T CURRENTLY BACK UP EXISTING MODS.
def del_dir():
try: try:
shutil.rmtree(str("mods")) shutil.rmtree(str(directory))
print("Cleared previous mods.")
except OSError as e: except OSError as e:
print("Error: %s - %s." % (e.filename, e.strerror)) print("Error: %s - %s." % (e.filename, e.strerror))
del_dir() #this defines a function to delete a directory (no shit)
os.mkdir(str("mods"))
# download mod archive from https://git.adolin.xyz/saru and extract
#this snippet below defines a tar extract FUNCTION
def extract_tar_archive(tar_file_path, extract_to): def extract_tar_archive(tar_file_path, extract_to):
with tarfile.open(tar_file_path, 'r') as tar: with tarfile.open(tar_file_path, 'r') as tar:
tar.extractall(extract_to) tar.extractall(extract_to)
#this defines a function to decompress a tar.gz file
print("Starting install...") def ascii_art():
print("Fetching mods...")
# #this is the SIMPLEST implementation of curl i have ever seen i just NUTTED SO FUCKING HARD
# take the last one back, this is fucking insane. wget the fucking goat. who knew windows package manager was so damn cool?
wget.download('https://git.adolin.xyz/saru/lobotomy-mod-pack/raw/branch/main/mods.tar.gz')
print("Extracting and writing to disk...")
tar_file_path = 'mods.tar.gz'
extract_to = 'mods'
extract_tar_archive(tar_file_path, extract_to)
def ascii():
print() print()
print() print()
print(" :+++++=") print(" :+++++=")
@ -100,11 +58,61 @@ def ascii():
print(" =: =:") print(" =: =:")
print(" --::.--") print(" --::.--")
print(" ....") print(" ....")
#someone's gonna think im a furry or a femboy or some shit because of this.
print() print()
ascii() #someone's gonna think im a furry or a femboy or some shit because of this.
print("sigma")
#detect operating system and find home, minecraft, & mod folders
homedir = os.path.expanduser("~")
os.chdir(homedir)
global mcfolder
global modfolder
# `global` sets these variables to exist outside of the scope of these specific `if` statements.
if platform.system() == "Linux":
print("Operating system detected: Linux")
os.chdir(homedir + '/.minecraft')
mcfolder = Path.cwd()
modfolder = mcfolder + '/mods'
elif platform.system() == "Windows":
print("Operating system detected: Windows")
os.chdir("AppData/Roaming/.minecraft/mods")
mcfolder = Path.cwd()
modfolder = mcfolder + '/mods'
os.chdir(mcfolder)
print("Changed current working directory to '" + str(mcfolder) + "'")
time.sleep(2)
#clear out preexisting mods
delete_directory("mods")
print("Deleted mod folder contents.")
os.mkdir(str("mods"))
# download mod archive from https://git.adolin.xyz/saru and extract
print("Starting install...")
print("Fetching mods...")
wget.download('https://git.adolin.xyz/saru/lobotomy-mod-pack/raw/branch/main/mods.tar.gz')
# #this is the SIMPLEST implementation of curl i have ever seen i just NUTTED SO FUCKING HARD
# take the last one back, this is fucking insane. `wget` the fucking goat. who knew windows package manager was so damn cool?
print("Extracting and writing to disk...")
extract_tar_archive('mods.tar.gz', 'mods')
# ('tarfile', 'directory to extract to')
ascii_art()
#call func to print ascii art to console
print("sigma!")
print("all done!") print("all done!")
print("This script will exit and close in ten seconds. :)") print("This script will exit and close in ten seconds. :)")
time.sleep(10) time.sleep(10)