add update system
This commit is contained in:
parent
f08f7911e7
commit
f139af4f52
13
src/cli.py
13
src/cli.py
@ -3,6 +3,8 @@ import argparse
|
|||||||
import importlib
|
import importlib
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
import src
|
||||||
|
|
||||||
BANNER = """
|
BANNER = """
|
||||||
. o8o oooo o8o . o8o
|
. o8o oooo o8o . o8o
|
||||||
.o8 `"' `888 `"' .o8 `"'
|
.o8 `"' `888 `"' .o8 `"'
|
||||||
@ -17,11 +19,20 @@ def main():
|
|||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
description='Run a specific script by name. If no name is provided, start a REPL.'
|
description='Run a specific script by name. If no name is provided, start a REPL.'
|
||||||
)
|
)
|
||||||
parser.add_argument('user_input', type=str, nargs='*',
|
parser.add_argument(
|
||||||
|
'user_input',
|
||||||
|
type=str,
|
||||||
|
nargs='*',
|
||||||
help='The name of the script that you want to run plus any arguments for that script.')
|
help='The name of the script that you want to run plus any arguments for that script.')
|
||||||
|
parser.add_argument(
|
||||||
|
'--version', action='store_true', help="Print out the version string."
|
||||||
|
)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
user_input = args.user_input
|
user_input = args.user_input
|
||||||
|
if args.version is True:
|
||||||
|
print(src.__version__)
|
||||||
|
sys.exit()
|
||||||
if len(user_input) == 0:
|
if len(user_input) == 0:
|
||||||
code.interact(banner=BANNER, local=locals())
|
code.interact(banner=BANNER, local=locals())
|
||||||
else:
|
else:
|
||||||
|
@ -1,15 +1,9 @@
|
|||||||
import httpx
|
import httpx
|
||||||
import json
|
|
||||||
import sys
|
import src
|
||||||
import zipfile
|
|
||||||
from datetime import datetime
|
|
||||||
|
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
self_name = sys.argv[0].strip(".").strip("/") # todo: is this resilient?
|
|
||||||
data = json.loads(zipfile.ZipFile(self_name).read("environment.json"))
|
|
||||||
build_time = datetime.fromisoformat(data['built_at'])
|
|
||||||
|
|
||||||
release_data = httpx.get(
|
release_data = httpx.get(
|
||||||
'https://api.github.com/repos/itsthejoker/utils/releases/latest'
|
'https://api.github.com/repos/itsthejoker/utils/releases/latest'
|
||||||
)
|
)
|
||||||
@ -19,4 +13,14 @@ def main(args):
|
|||||||
f" {release_data.status_code} with the following content:\n"
|
f" {release_data.status_code} with the following content:\n"
|
||||||
f"{release_data.content}"
|
f"{release_data.content}"
|
||||||
)
|
)
|
||||||
sys.exit()
|
return
|
||||||
|
json_data = release_data.json()
|
||||||
|
if json_data['name'] == src.__version__:
|
||||||
|
print("Server version is the same as current version; nothing to update.")
|
||||||
|
return
|
||||||
|
|
||||||
|
url = json_data['assets'][0]['browser_download_url']
|
||||||
|
with open('utils', 'wb') as f, httpx.stream("GET", url, follow_redirects=True) as r:
|
||||||
|
for line in r.iter_bytes():
|
||||||
|
f.write(line)
|
||||||
|
print(f"Updated to {json_data['name']}! 🎉")
|
||||||
|
Loading…
Reference in New Issue
Block a user