aboutsummaryrefslogtreecommitdiff
path: root/util.py
diff options
context:
space:
mode:
authorAlexander Hayden <alexhayden25@gmail.com>2020-11-28 01:38:09 -0500
committerAlexander Hayden <alexhayden25@gmail.com>2020-11-28 01:38:09 -0500
commit82202fea4f29698dddbc3d588e34e4adce26f2f8 (patch)
tree28668576c90ad71de286f1f27254506b1c01fa15 /util.py
parent912d7359c2c01e459b710a4b6b5c53f1a0fae129 (diff)
downloadmodpackman-82202fea4f29698dddbc3d588e34e4adce26f2f8.tar.gz
modpackman-82202fea4f29698dddbc3d588e34e4adce26f2f8.zip
(almost) finish refactor / ini conversion
Diffstat (limited to 'util.py')
-rw-r--r--[-rwxr-xr-x]util.py26
1 files changed, 20 insertions, 6 deletions
diff --git a/util.py b/util.py
index c50ca87..ed63631 100755..100644
--- a/util.py
+++ b/util.py
@@ -12,12 +12,26 @@ from configparser import ConfigParser
import requests
-def load_config(filename="pack.ini"):
- config = ConfigParser()
- config.read(filename)
+def load_config():
+ """
+ Load configuarion from pack and local configuration files
+ Fill in reasonable defaults where applicable.
+ """
+ config_p = ConfigParser()
+ config_p.read(["pack.ini", "local-config.ini"])
+ config = config_p._sections
config["pack"]["sanitized_name"] = sanitize_text(config["pack"]["name"])
+
+ if "whitelist" not in config["pack"]:
+ config["pack"]["whitelist"] = []
+ else:
+ config["pack"]["whitelist"] = config["pack"]["whitelist"].split(",")
+
+ config["pack"]["game_version"] = game_version_from_string(config["pack"]["game_version"])
+
#TODO generate a default pack location
- config["pack"]["location"] = f"/tmp/{config['pack']['sanitized_name']}"
+ if "location" not in config["pack"]:
+ config["pack"]["location"] = f"/tmp/{config['pack']['sanitized_name']}"
# return the whole config file, pack configuration and modlist
return config
@@ -66,7 +80,7 @@ def game_version_from_string(string):
# Apply updates to the actual mod pack
-def install(version_file, whitelist_file, pack_location):
+def install(version_file, whitelist, pack_location):
pack_version = get_version_from_file(version_file)
print("Updating pack with version " + str(pack_version) + "...")
print()
@@ -74,7 +88,7 @@ def install(version_file, whitelist_file, pack_location):
mods = read_file(version_file)
names = [mod[0] for mod in mods]
# whitelist client mods (e.g. optifine)
- names += [line[0] for line in read_file(whitelist_file)]
+ names += whitelist
i = 0
for mod in mods: