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 urllib.request
|
||||
import tarfile
|
||||
import os
|
||||
import platform
|
||||
import time
|
||||
import shutil
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
#detect operating system and find home folder
|
||||
#detect operating system and find home, minecraft, & mod folders
|
||||
homedir = os.path.expanduser("~")
|
||||
os.chdir(homedir)
|
||||
|
||||
#operating system specific operations.
|
||||
#we find the minecraft folder in this section.
|
||||
if platform.system() == "Linux":
|
||||
print("Operating system detected: Linux")
|
||||
# `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 = homedir + '/.minecraft/mods'
|
||||
@ -26,10 +25,7 @@ if platform.system() == "Linux":
|
||||
|
||||
elif platform.system() == "Windows":
|
||||
print("Operating system detected: Windows")
|
||||
os.chdir(homedir)
|
||||
os.chdir("AppData")
|
||||
os.chdir("Roaming")
|
||||
os.chdir(".minecraft")
|
||||
os.chdir("AppData/Roaming/.minecraft/mods")
|
||||
mcfolder = Path.cwd()
|
||||
os.chdir("mods")
|
||||
modfolder = Path.cwd
|
||||
@ -39,19 +35,21 @@ elif platform.system() == "Windows":
|
||||
|
||||
os.chdir(mcfolder)
|
||||
|
||||
#begin mod deletion
|
||||
#THIS DOESN'T CURRENTLY BACK UP EXISTING MODS.
|
||||
# delete previous mods
|
||||
# WARN: THIS DOESN'T CURRENTLY BACK UP EXISTING MODS.
|
||||
def del_dir():
|
||||
try:
|
||||
shutil.rmtree(str("mods"))
|
||||
print("Cleared previous mods.")
|
||||
except OSError as e:
|
||||
print("Error: %s - %s." % (e.filename, e.strerror))
|
||||
del_dir()
|
||||
|
||||
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
|
||||
def extract_tar_archive(tar_file_path, extract_to):
|
||||
with tarfile.open(tar_file_path, 'r') as tar:
|
||||
@ -108,8 +106,8 @@ def ascii():
|
||||
print(" ....")
|
||||
#someone's gonna think im a furry or a femboy or some shit because of this.
|
||||
print()
|
||||
|
||||
ascii()
|
||||
|
||||
print("sigma")
|
||||
print("all done!")
|
||||
print("This script will exit and close in ten seconds. :)")
|
||||
|
Loading…
x
Reference in New Issue
Block a user