turdbot/py/init.py

37 lines
1.2 KiB
Python
Raw Normal View History

2022-10-29 13:13:55 -06:00
#imports
2022-10-29 11:39:40 -06:00
import version
2022-10-29 12:32:37 -06:00
import sys
import os
2022-11-03 19:20:55 -06:00
import configparser
import wget
import shutil
2022-10-29 13:13:55 -06:00
#funky stuff to deal with relative file paths
2022-11-07 12:45:00 -07:00
randir = os.getcwd()
2022-10-29 13:13:55 -06:00
os.chdir(os.path.dirname(os.path.realpath(__file__)))
2022-11-03 19:20:55 -06:00
config = configparser.ConfigParser()
config.read("config.conf")
if config["config"]["autoupdate"] == "true":
versionl = version.local()
versionr = version.remote()
2022-11-07 12:45:00 -07:00
print(versionr.join("."))
2022-11-03 19:20:55 -06:00
2022-10-29 13:13:55 -06:00
#updater
2022-11-07 12:45:00 -07:00
if ".".join(versionl)<".".join(versionr):
print("outdated version",versionl,"<",versionr)
2022-11-03 19:20:55 -06:00
if config["config"]["autoupdate"] == "true":
print("autoupdate is enabled, attempting to update")
2022-11-07 12:45:00 -07:00
wget.download("https://github.com/ionburger/turdbot/archive/refs/tags/"+versionr+".zip",out = "turdbottmp.zip")
shutil.unpack_archive("turdbottmp.zip","turdbottmp")
for file in os.listdir("turdbottmp/turdbot-"+versionr+"/py/"):
if file.endswith(".py"):
shutil.move("turdbottmp/turdbot-"+versionr+"/py/"+file,file)
with open("VERSION","w") as file:
file.write(versionr)
os.chdir(randir)
2022-11-03 19:20:55 -06:00
os.execl(sys.executable, sys.executable, *sys.argv)
2022-10-29 11:39:40 -06:00
else:
2022-11-07 12:45:00 -07:00
print("running latest version of turdbot",versionl)