diff options
author | Alexander Hayden <alexhayden25@gmail.com> | 2020-12-19 19:16:41 -0500 |
---|---|---|
committer | Alexander Hayden <alexhayden25@gmail.com> | 2020-12-19 19:16:41 -0500 |
commit | a47f0a0dd1dd43f90a1a86fa6b67ae551c13a844 (patch) | |
tree | 3f3179cb3148ab3f1065b75024146cb262499ac5 /util.py | |
parent | f1d6329799d4b32ce532b9d97e5e86420ec23326 (diff) | |
download | modpackman-a47f0a0dd1dd43f90a1a86fa6b67ae551c13a844.tar.gz modpackman-a47f0a0dd1dd43f90a1a86fa6b67ae551c13a844.zip |
installer downloads updates & write readme
Diffstat (limited to 'util.py')
-rw-r--r-- | util.py | 27 |
1 files changed, 24 insertions, 3 deletions
@@ -9,7 +9,7 @@ import urllib.parse import multiprocessing import pathlib import base64 -from configparser import ConfigParser +from configparser import RawConfigParser import requests @@ -19,7 +19,7 @@ def load_config(): Load configuarion from pack and local configuration files Fill in reasonable defaults where applicable. """ - config_p = ConfigParser() + config_p = RawConfigParser() config_p.read(["pack.ini", "local-config.ini"]) config = config_p._sections config["pack"]["sanitized_name"] = sanitize_text(config["pack"]["name"]) @@ -44,8 +44,21 @@ def update_self(): in order to update to the latest version. Will overwrite any existing pack.ini and other config files, so be careful! """ + global config + + base_url = config["pack"]["pack_base_url"].strip("/") + "/" + download_file(base_url + "pack.ini", "pack.ini") + download_file(base_url + "pack-lock.ini", "pack-lock.ini") + download_file(base_url + "icon.png", "icon.png") + + pack_lock = RawConfigParser() + pack_lock.read(["pack-lock.ini"]) + for path in pack_lock["global"]["config_files"].split(","): + if not path: + continue + download_file(f"{base_url}config/{path}", os.path.join("config", path)) - raise NotImplementedError() + config = load_config() def find_minecraft_directory(): @@ -78,6 +91,14 @@ def find_jre(): return "C:\\Program Files (x86)\\Minecraft Launcher\\runtime\\jre-x64\\java.exe" raise RuntimeError("Unable to detect an installed JRE. Please install Java in order to use modpackman.") +def download_file(url, destination): + """ + given a url, performs a requests request to get the remote object + and write it to destination + """ + with open(destination, "wb") as f: + dl = requests.get(url, stream=True) + shutil.copyfileobj(dl.raw, f) # take a string and only keep filename-friendly parts def sanitize_text(text): |