refactor code snippets and concatenate os.chdir
lines under os specific ops
This commit is contained in:
parent
1561a1f6d1
commit
dac69d1ea5
28
installer.py
28
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)
|
||||||
|
|
||||||
#operating system specific operations.
|
# `global` sets these variables to exist outside of the scope of these specific `if` statements.
|
||||||
#we find the minecraft folder in this section.
|
|
||||||
if platform.system() == "Linux":
|
|
||||||
print("Operating system detected: Linux")
|
|
||||||
global mcfolder
|
global mcfolder
|
||||||
global modfolder
|
global modfolder
|
||||||
|
|
||||||
|
if platform.system() == "Linux":
|
||||||
|
print("Operating system detected: Linux")
|
||||||
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.
|
||||||
|
def del_dir():
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(str("mods"))
|
shutil.rmtree(str("mods"))
|
||||||
print("Cleared previous mods.")
|
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()
|
||||||
|
|
||||||
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:
|
||||||
@ -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