mirror of
https://github.com/krateng/maloja.git
synced 2023-08-10 21:12:55 +03:00
Better install script, some imports moved out of functions
This commit is contained in:
101
maloja
101
maloja
@@ -13,25 +13,100 @@ neededmodules = [
|
||||
"setproctitle"
|
||||
]
|
||||
|
||||
recommendedmodules = [
|
||||
"wand"
|
||||
]
|
||||
|
||||
SOURCE_URL = "https://github.com/krateng/maloja/archive/master.zip"
|
||||
|
||||
|
||||
|
||||
def install():
|
||||
toinstall = []
|
||||
toinstallr = []
|
||||
for m in neededmodules:
|
||||
try:
|
||||
exec("import " + m) #I'm sorry
|
||||
except:
|
||||
toinstall.append(m)
|
||||
|
||||
for m in recommendedmodules:
|
||||
try:
|
||||
exec("import " + m)
|
||||
except:
|
||||
toinstallr.append(m)
|
||||
|
||||
if toinstall != []:
|
||||
print("The following python modules need to be installed:")
|
||||
for m in toinstall:
|
||||
print("\t" + m)
|
||||
else:
|
||||
return
|
||||
if toinstallr != []:
|
||||
print("The following python modules are highly recommended, some features will not work without them:")
|
||||
for m in toinstallr:
|
||||
print("\t" + m)
|
||||
|
||||
if toinstall != [] or toinstallr != []:
|
||||
if os.geteuid() != 0:
|
||||
print("Installing python modules should be fairly straight-forward, but Maloja can try to install \
|
||||
them automatically. For this, you need to run this script as a root user.")
|
||||
return False
|
||||
else:
|
||||
print("Installing python modules should be fairly straight-forward, but Maloja can try to install \
|
||||
them automatically, This might or might not work / bloat your system / cause a nuclear war.")
|
||||
fail = False
|
||||
if toinstall != []:
|
||||
print("Attempt to install required modules? [Y/n]")
|
||||
answer = input()
|
||||
|
||||
if answer.lower() in ["y","yes","yea","1","positive","true"]:
|
||||
for m in neededmodules:
|
||||
try:
|
||||
print("Installing " + m + " with pip...")
|
||||
import pip
|
||||
#os.system("pip3 install " + m)
|
||||
pip.main(["install",m])
|
||||
print("Success!")
|
||||
except:
|
||||
print("Failure!")
|
||||
fail = True
|
||||
|
||||
elif answer.lower() in ["n","no","nay","0","negative","false"]:
|
||||
return False #if you dont want to auto install required, you probably dont want to install recommended
|
||||
else:
|
||||
print("What?")
|
||||
return False
|
||||
if toinstallr != []:
|
||||
print("Attempt to install recommended modules? [Y/n]")
|
||||
answer = input()
|
||||
|
||||
if answer.lower() in ["y","yes","yea","1","positive","true",""]:
|
||||
for m in recommendedmodules:
|
||||
try:
|
||||
print("Installing " + m + " with pip...")
|
||||
import pip
|
||||
#os.system("pip3 install " + m)
|
||||
pip.main(["install",m])
|
||||
print("Success!")
|
||||
except:
|
||||
print("Failure!")
|
||||
fail = True
|
||||
|
||||
elif answer.lower() in ["n","no","nay","0","negative","false"]:
|
||||
return False
|
||||
else:
|
||||
print("What?")
|
||||
return False
|
||||
|
||||
if fail: return False
|
||||
print("All modules successfully installed!")
|
||||
return True
|
||||
|
||||
else:
|
||||
print("All necessary modules seem to be installed.")
|
||||
return True
|
||||
|
||||
|
||||
|
||||
def getInstance():
|
||||
try:
|
||||
output = subprocess.check_output(["pidof","Maloja"])
|
||||
@@ -44,15 +119,16 @@ def getInstance():
|
||||
|
||||
|
||||
def start():
|
||||
install()
|
||||
if install():
|
||||
|
||||
try:
|
||||
p = subprocess.Popen(["python3","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
|
||||
print("Maloja started! PID: " + str(p.pid))
|
||||
return True
|
||||
except:
|
||||
print("Error while starting Maloja. Are you sure it's not already running?")
|
||||
return False
|
||||
try:
|
||||
p = subprocess.Popen(["python3","server.py"],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL)
|
||||
print("Maloja started! PID: " + str(p.pid))
|
||||
return True
|
||||
except:
|
||||
print("Error while starting Maloja. Are you sure it's not already running?")
|
||||
return False
|
||||
|
||||
|
||||
|
||||
def restart():
|
||||
@@ -73,8 +149,8 @@ def stop():
|
||||
print("Server is not running")
|
||||
return False
|
||||
else:
|
||||
print("Stopping " + str(pid))
|
||||
os.kill(pid,signal.SIGTERM)
|
||||
print("Maloja stopped! PID: " + str(pid))
|
||||
return True
|
||||
|
||||
def update():
|
||||
@@ -93,7 +169,7 @@ def update():
|
||||
with zipfile.ZipFile(tmpfile.name,"r") as z:
|
||||
|
||||
for f in z.namelist():
|
||||
print("extracting " + f)
|
||||
#print("extracting " + f)
|
||||
z.extract(f)
|
||||
|
||||
|
||||
@@ -112,4 +188,5 @@ if __name__ == "__main__":
|
||||
elif sys.argv[1] == "restart": restart()
|
||||
elif sys.argv[1] == "stop": stop()
|
||||
elif sys.argv[1] == "update": update()
|
||||
else: print("Valid commands: start restart stop update")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user