diff options
author | Alexander Hayden <alexhayden25@gmail.com> | 2019-01-29 23:43:40 -0500 |
---|---|---|
committer | Alexander Hayden <alexhayden25@gmail.com> | 2019-01-29 23:43:40 -0500 |
commit | cc19a6dda838720ecede3d4d5610d8d0675b8e04 (patch) | |
tree | 19d8f7310ba6407c8dd39e419b42647bcdcd8de3 /update.py | |
parent | db63ba0d3e1538db50eae90331815189651a022c (diff) | |
download | modpackman-cc19a6dda838720ecede3d4d5610d8d0675b8e04.tar.gz modpackman-cc19a6dda838720ecede3d4d5610d8d0675b8e04.zip |
Add `check_updates`
Diffstat (limited to 'update.py')
-rwxr-xr-x | update.py | 40 |
1 files changed, 34 insertions, 6 deletions
@@ -12,7 +12,7 @@ with open("pack-location.txt", "r") as f: # Apply updates to the actual mod pack -def apply_updates(): +def install(): print("Updating pack...") # (fname, url) mods = [] @@ -31,7 +31,7 @@ def apply_updates(): 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") else: - print("Installing " + mod[0] + " from " + mod[1] + "...") + print(f'Installing {mod[0]} from {mod[2]}...') download_obj = requests.get(mod[2], stream=True) with open(os.path.join(INSTALL_DIR, mod[0]), "wb") as write_file: shutil.copyfileobj(download_obj.raw, write_file) @@ -47,7 +47,7 @@ def apply_updates(): # Using the latest urls, update downloads.txt to match the urls and have the correct sha1 -def find_updates(): +def apply_updates(): print("Reading update file...") mods = set() with open('latest-urls.txt') as f: @@ -67,14 +67,42 @@ def find_updates(): f.write(f'{mod[0]} {hsh.hexdigest()} {resp.url}\n') print("\nDone downloading 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: + 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)) + 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!") + if len(sys.argv) < 2: print(f"Usage: {sys.argv[0]} <apply_updates|find_updates>") sys.exit(-1) +elif sys.argv[1] == 'install': + install() elif sys.argv[1] == 'apply_updates': apply_updates() -elif sys.argv[1] == 'find_updates': - find_updates() +elif sys.argv[1] == 'check_updates': + check_updates() else: - print(f"Usage: {sys.argv[0]} <apply_updates|find_updates>") + print(f"Usage: {sys.argv[0]} <install|apply_updates|check_updates>") sys.exit(-1) |