refactor code snippets and concatenate os.chdir
lines under os specific ops
This commit is contained in:
parent
210082ce3e
commit
a0594137d1
40
installer.py
40
installer.py
@ -1,22 +1,21 @@
|
|||||||
import wget
|
import wget
|
||||||
import urllib.request
|
|
||||||
import tarfile
|
import tarfile
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import time
|
import time
|
||||||
import shutil
|
import shutil
|
||||||
import sys
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
#detect operating system and find home folder
|
#detect operating system and find home, minecraft, & mod folders
|
||||||
homedir = os.path.expanduser("~")
|
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
|
||||||
|
|
||||||
#operating system specific operations.
|
|
||||||
#we find the minecraft folder in this section.
|
|
||||||
if platform.system() == "Linux":
|
if platform.system() == "Linux":
|
||||||
print("Operating system detected: Linux")
|
print("Operating system detected: Linux")
|
||||||
global mcfolder
|
|
||||||
global modfolder
|
|
||||||
os.chdir(homedir + '/.minecraft')
|
os.chdir(homedir + '/.minecraft')
|
||||||
mcfolder = Path.cwd()
|
mcfolder = Path.cwd()
|
||||||
modfolder = homedir + '/.minecraft/mods'
|
modfolder = homedir + '/.minecraft/mods'
|
||||||
@ -26,10 +25,7 @@ if platform.system() == "Linux":
|
|||||||
|
|
||||||
elif platform.system() == "Windows":
|
elif platform.system() == "Windows":
|
||||||
print("Operating system detected: Windows")
|
print("Operating system detected: Windows")
|
||||||
os.chdir(homedir)
|
os.chdir("AppData/Roaming/.minecraft/mods")
|
||||||
os.chdir("AppData")
|
|
||||||
os.chdir("Roaming")
|
|
||||||
os.chdir(".minecraft")
|
|
||||||
mcfolder = Path.cwd()
|
mcfolder = Path.cwd()
|
||||||
os.chdir("mods")
|
os.chdir("mods")
|
||||||
modfolder = Path.cwd
|
modfolder = Path.cwd
|
||||||
@ -39,19 +35,21 @@ elif platform.system() == "Windows":
|
|||||||
|
|
||||||
os.chdir(mcfolder)
|
os.chdir(mcfolder)
|
||||||
|
|
||||||
#begin mod deletion
|
# delete previous mods
|
||||||
#THIS DOESN'T CURRENTLY BACK UP EXISTING MODS.
|
# WARN: THIS DOESN'T CURRENTLY BACK UP EXISTING MODS.
|
||||||
try:
|
def del_dir():
|
||||||
shutil.rmtree(str("mods"))
|
try:
|
||||||
print("Cleared previous mods.")
|
shutil.rmtree(str("mods"))
|
||||||
except OSError as e:
|
print("Cleared previous mods.")
|
||||||
print("Error: %s - %s." % (e.filename, e.strerror))
|
except OSError as e:
|
||||||
|
print("Error: %s - %s." % (e.filename, e.strerror))
|
||||||
|
del_dir()
|
||||||
|
|
||||||
os.mkdir(str("mods"))
|
os.mkdir(str("mods"))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#begin download and extract
|
# download mod archive from https://git.adolin.xyz/saru and extract
|
||||||
#this snippet below defines a tar extract FUNCTION
|
#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:
|
||||||
@ -61,7 +59,7 @@ print("Starting install...")
|
|||||||
|
|
||||||
print("Fetching mods...")
|
print("Fetching mods...")
|
||||||
# #this is the SIMPLEST implementation of curl i have ever seen i just NUTTED SO FUCKING HARD
|
# #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?
|
# 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')
|
wget.download('https://git.adolin.xyz/saru/lobotomy-mod-pack/raw/branch/main/mods.tar.gz')
|
||||||
|
|
||||||
print("Extracting and writing to disk...")
|
print("Extracting and writing to disk...")
|
||||||
@ -108,8 +106,8 @@ def ascii():
|
|||||||
print(" ....")
|
print(" ....")
|
||||||
#someone's gonna think im a furry or a femboy or some shit because of this.
|
#someone's gonna think im a furry or a femboy or some shit because of this.
|
||||||
print()
|
print()
|
||||||
|
|
||||||
ascii()
|
ascii()
|
||||||
|
|
||||||
print("sigma")
|
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. :)")
|
||||||
|
Reference in New Issue
Block a user