aboutsummaryrefslogtreecommitdiff
path: root/update.py
diff options
context:
space:
mode:
authorAlexander Hayden <alexhayden25@gmail.com>2019-01-30 10:21:29 -0500
committerAlexander Hayden <alexhayden25@gmail.com>2019-01-30 10:21:29 -0500
commit802af0c909bbf843df01e423b89dd4b8e2c18169 (patch)
tree0b8b3d87f4ed161893768944b056f7ea07bc9db7 /update.py
parentcc19a6dda838720ecede3d4d5610d8d0675b8e04 (diff)
downloadmodpackman-802af0c909bbf843df01e423b89dd4b8e2c18169.tar.gz
modpackman-802af0c909bbf843df01e423b89dd4b8e2c18169.zip
Make code nicer
Diffstat (limited to 'update.py')
-rwxr-xr-xupdate.py62
1 files changed, 22 insertions, 40 deletions
diff --git a/update.py b/update.py
index 70f3d51..68e598a 100755
--- a/update.py
+++ b/update.py
@@ -14,19 +14,9 @@ with open("pack-location.txt", "r") as f:
# Apply updates to the actual mod pack
def install():
print("Updating pack...")
- # (fname, url)
- mods = []
- # Set of jar file names
- names = set()
-
- with open("downloads.txt", "r") as f:
- for line in f:
- mod = line.strip().split(" ")
- if len(line) >= 1 and line[0] != '#':
- # run strip on each element
- mod = tuple(map(lambda x: x.strip(), mod))
- mods.append(mod)
- names.add(mod[0])
+ # (fname, checksum, url)
+ mods = read_file("downloads.txt")
+ names = [mod[0] for mod in mods]
for mod in mods:
if mod[0] in os.listdir(INSTALL_DIR) and hashlib.sha1(open(os.path.join(INSTALL_DIR, mod[0]), 'rb').read()).hexdigest() == mod[1]:
print("Skipping " + mod[0] + ", already up to date")
@@ -49,14 +39,7 @@ def install():
# Using the latest urls, update downloads.txt to match the urls and have the correct sha1
def apply_updates():
print("Reading update file...")
- mods = set()
- with open('latest-urls.txt') as f:
- for line in f:
- mod = line.strip().split()
- if len(line) >= 1 and line[0] != '#':
- # run strip on each element
- mod = tuple(map(lambda x: x.strip(), mod))
- mods.add(mod)
+ mods = read_file("latest-urls.txt")
print("Downloading new versions of all mods...")
with open('downloads.txt', 'w') as f:
f.write('# Format: <jarname> <hex digested sha1> <direct download url>\n')
@@ -70,28 +53,27 @@ def apply_updates():
# Find if any updates are available
def check_updates():
print("Reading update files...")
- latest_urls = {}
- with open('latest-urls.txt') as f:
- for line in f:
- mod = line.strip().split()
- if len(line) >= 1 and line[0] != '#':
- # run strip on each element
- mod = tuple(map(lambda x: x.strip(), mod))
- latest_urls[mod[0]] = mod[1]
- old_urls = {}
- with open('downloads.txt') as f:
+ latest = read_file("latest-urls.txt")
+ old = read_file("downloads.txt")
+ old_urls = [mod[2] for mod in old]
+
+ print("Checking updates...\nThe following mods have updates available:\n")
+ for mod in latest:
+ resp = requests.get(mod[1])
+ if not resp.url in old_urls:
+ print(f" -> Found update for {mod[0]}: {resp.url.split('/')[-1]}")
+ print("\nFinished checking for updates!")
+
+def read_file(fil):
+ strings = set()
+ with open(fil) as f:
for line in f:
- mod = line.strip().split()
+ string = line.strip().split()
if len(line) >= 1 and line[0] != '#':
# run strip on each element
- mod = tuple(map(lambda x: x.strip(), mod))
- old_urls[mod[0]] = mod[2]
- print("Checking updates...\nThe following mods have updates available:\n")
- for mod in latest_urls:
- resp = requests.get(latest_urls[mod])
- if resp.url != old_urls[mod]:
- print(f" -> Found update for {mod}!")
- print("Finished checking for updates!")
+ string = tuple(map(lambda x: x.strip(), string))
+ strings.add(string)
+ return strings
if len(sys.argv) < 2: