aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorduvallj <jediguy9@gmail.com>2019-02-02 16:34:48 -0500
committerduvallj <jediguy9@gmail.com>2019-02-02 16:34:48 -0500
commitd3c7b517043f6d759b454a9e14cd2b3b9639888a (patch)
tree1995b47758d1a645fef062a4c9d659ad90202da1
parentce4cb0b5cd157c77396344958b403c41a4f0f8b3 (diff)
downloadmodpackman-d3c7b517043f6d759b454a9e14cd2b3b9639888a.tar.gz
modpackman-d3c7b517043f6d759b454a9e14cd2b3b9639888a.zip
Make 1F335 slightly happier
-rw-r--r--readme.md2
-rw-r--r--requirements.txt3
-rwxr-xr-xupdate.py61
3 files changed, 31 insertions, 35 deletions
diff --git a/readme.md b/readme.md
index 0438f1e..5461962 100644
--- a/readme.md
+++ b/readme.md
@@ -6,7 +6,7 @@ Script to update modpacks automatically
#### To Use
First, install [Python 3](https://www.python.org/downloads/) and [Git](https://git-scm.com/downloads) and add them to your `$PATH`.
-Then, run `pip install -r requirements.txt` to install all the Python module requirements.
+Then, run `pip install requests` to install the Python Requests module (required to run the script).
Simply put the location of your `mods` folder in `pack-location.txt` and run `python update.py install`
diff --git a/requirements.txt b/requirements.txt
deleted file mode 100644
index 5f37ed8..0000000
--- a/requirements.txt
+++ /dev/null
@@ -1,3 +0,0 @@
-requests
-colorama
-termcolor \ No newline at end of file
diff --git a/update.py b/update.py
index a04df5c..b2d1039 100755
--- a/update.py
+++ b/update.py
@@ -1,15 +1,12 @@
#!/usr/bin/env python3
import argparse
-import textwrap
import os
import sys
import hashlib
import shutil
import requests
-import colorama
-from termcolor import colored
parser = argparse.ArgumentParser(
description="A Simple Git-Based Modpack Manager",
@@ -17,8 +14,8 @@ parser = argparse.ArgumentParser(
epilog='''\
Available commands:
install : Downloads mods listed in downloads.txt and populates the mods folder specified in pack-location.txt
- apply_updates : Using the latest downloads in latest-urls.txt, repopulates downloads.txt to reflect the most recent mod versions
- check_updates : Compares downloads.txt and latest-urls.txt to see if any mods can be updated
+ apply_updates : Using the urls in mods.txt, repopulates downloads.txt to reflect the most recent mod versions
+ check_updates : Compares downloads.txt and mods.txt to see if any mods can be updated
''')
parser.add_argument('command',
@@ -29,10 +26,10 @@ parser.add_argument('filename',
nargs='?',
default="mods.txt",
help="Optional filename to specify latest mods (default: mods.txt)")
-parser.add_argument('--url-file',
+parser.add_argument('--version-file',
type=str,
default="downloads.txt",
- help="Optional custom URL file to download mods from (default: downloads.txt)")
+ help="Optional custom version file to download mods from (default: downloads.txt)")
parser.add_argument('--pack-location',
type=str,
help="Optional custom modpack folder location (default: read from pack-location.txt)")
@@ -50,9 +47,9 @@ def read_file(fil):
# Apply updates to the actual mod pack
def install(args):
- print(colored("Updating pack...", 'green', attrs=['bold']))
+ print("Updating pack...")
# (fname, checksum, url)
- mods = read_file(args.url_file)
+ mods = read_file(args.version_file)
names = [mod[0] for mod in mods]
for mod in mods:
@@ -61,30 +58,30 @@ def install(args):
hashlib.sha1(open(mod_path, 'rb').read()).hexdigest() == mod[1]:
print("Skipping {mod[0]}, already up to date".format(mod=mod))
else:
- print(colored('Installing {mod[0]} from {mod[2]}...'.format(mod=mod), attrs=['bold']))
+ print('Installing {mod[0]} from {mod[2]}...'.format(mod=mod))
download_obj = requests.get(mod[2], stream=True)
with open(mod_path, "wb") as write_file:
shutil.copyfileobj(download_obj.raw, write_file)
print("Done!")
print()
- print(colored("Removing old mods...", 'green', attrs=['bold']))
+ print("Removing old mods...")
for jar in os.listdir(args.pack_location):
if jar not in names and os.path.splitext(jar)[1] == ".jar":
os.remove(os.path.join(args.pack_location, jar))
- print(colored("Removing '{jar}'".format(jar=jar), attrs=['bold']))
+ print("Removing '{jar}'".format(jar=jar))
print()
- print(colored("Finished installing mods!", 'green', attrs=['bold']))
+ print("Finished installing mods!")
-# Using the latest urls, update downloads.txt to match the urls and have the correct sha1
+# Using the latest urls, update downloads.txt to match and have the correct sha1
def apply_updates(args):
- print(colored("Populating URL File...", 'green', attrs=['bold']))
+ print("Populating URL File...")
mods = read_file(args.filename)
- print(colored("Getting new versions of all mods...", attrs=['bold']))
- with open(args.url_file, 'w') as f:
+ print("Getting new versions of all mods...")
+ with open(args.version_file, 'w') as f:
f.write('# Format: <jarname> <hex digested sha1> <direct download url>\n')
for mod in mods:
print("Fetching {mod[0]}...".format(mod=mod))
@@ -93,25 +90,28 @@ def apply_updates(args):
f.write('{mod[0]} {hsh} {resp.url}\n'.format(mod=mod, hsh=hsh, resp=resp))
print()
print("Done!")
- print(colored("Updates applied to downloads.txt", 'green', attrs=['bold']))
- print(colored("[!] No mods were installed. To update your mods folder, run 'update.py install'", 'white', 'on_red', attrs=['bold', 'underline']))
+ print("Updates applied to {args.version_file}".format(args=args))
+ print("[!] No mods were installed. To update your mods folder, run 'update.py install'")
+
# Find if any updates are available
def check_updates(args):
- print(colored("Checking for updates to mods...", 'green', attrs=['bold']))
+ print("Checking for updates to mods...")
latest = read_file(args.filename)
- old = read_file(args.url_file)
+ old = read_file(args.version_file)
old_urls = [mod[2] for mod in old]
- print(colored("Checking updates...", attrs=['bold']))
+ print("Checking updates...")
for mod in latest:
- print('\033[2K',end="") # ANSI code to clear line
- print("Checking for updates to {mod[0]}...".format(mod=mod),end="\r")
+ print("Checking for updates to {mod[0]}...".format(mod=mod), end="")
+ sys.stdout.flush() # takes care of line-buffered terminals
resp = requests.get(mod[1])
- if not resp.url in old_urls:
- print(colored(" -> Found update for {mod[0]}: {resp.url.split('/')[-1]}".format(mod=mod, resp=resp), attrs=['bold']))
+ if resp.url in old_urls:
+ print(" No updates")
+ else:
+ print(" Found update: {resp.url.split('/')[-1]}".format(resp=resp))
- print('\033[2K' + colored("Finished checking for updates!", attrs=['bold']))
+ print("Finished checking for updates!")
COMMAND_MAP = {
'install': install,
@@ -120,7 +120,6 @@ COMMAND_MAP = {
}
if __name__ == "__main__":
- colorama.init()
args = parser.parse_args()
if not args.pack_location:
@@ -129,16 +128,16 @@ if __name__ == "__main__":
args.pack_location = f.read().strip()
if not os.path.exists(args.pack_location):
- print(colored("Error: mod folder \"" + args.pack_location + "\" does not exist.", 'red', attrs=['bold']))
+ print("Error: mod folder \"" + args.pack_location + "\" does not exist.")
parser.print_help()
sys.exit(1)
elif not os.path.isdir(args.pack_location):
- print(colored("Error: mod folder \"" + args.pack_location + "\" is not actually a folder.", 'red', attrs=['bold']))
+ print("Error: mod folder \"" + args.pack_location + "\" is not actually a folder.")
parser.print_help()
sys.exit(1)
if not (args.command in COMMAND_MAP):
- print(colored("Error: command \"" + args.command + "\" does not exist", 'red', attrs=['bold']))
+ print("Error: command \"" + args.command + "\" does not exist")
parser.print_help()
sys.exit(1)