aboutsummaryrefslogblamecommitdiff
path: root/modpackman.py
blob: 50c50d27562dd338ee71af74c3276d956a7ea616 (plain) (tree)










































                                                                                                                        



























                                                                                           






                                                                              



                                                                       
#!/usr/bin/env python3
import argparse
import os
import sys
import shutil

import util


parser = argparse.ArgumentParser(
    description="A Simple Git-Based Modpack Manager",
    formatter_class=argparse.RawDescriptionHelpFormatter,
    epilog='''\
Available commands:
    install          : Downloads mods listed in version.txt and populates the mods folder specified in pack-location.txt
    apply_updates    : Using the urls in mods.txt, repopulates version.txt to reflect the most recent mod versions
    check_updates    : Compares version.txt and mods.txt to see if any mods can be updated
''')

parser.add_argument('command',
    nargs='?',
    default='install',
    help="The action to perform (default: install)")
parser.add_argument('filename',
    nargs='?',
    default="mods.txt",
    help="Optional filename to specify latest mods (default: mods.txt)")
parser.add_argument('--version-file',
    type=str,
    default="version.txt",
    help="Optional custom version file to download mods from (default: version.txt)")
parser.add_argument('--pack-location',
    type=str,
    help="Optional custom modpack folder location (default: read from pack-location.txt)")
parser.add_argument('--whitelist-file',
    type=str,
    default="whitelist.txt",
    help="Optional custom whitelist file that tells 'install' which files not to remove (default: whitelist.txt)")
parser.add_argument("--game-version",
    type=str,
    default=None,
    help="The maximum game version to update mods to")

if __name__ == "__main__":
    args = parser.parse_args()
    config = util.load_config()
    mods = config['mods']
    pack = config['pack']

    GAME_VERSION = util.game_version_from_string(pack["game_version"])
    if args.pack_location:
        pack['location'] = args.pack_location

    if not os.path.exists(args.version_file):
        print("Error: version file\"" + args.version_file + "\" does not exist.")
        parser.print_help()
        sys.exit(1)
    if args.pack_location and not os.path.exists(args.pack_location):
        print("Error: mod folder \"" + args.pack_location + "\" does not exist.")
        parser.print_help()
        sys.exit(1)
    elif args.pack_location and not os.path.isdir(args.pack_location):
        print("Error: mod folder \"" + args.pack_location + "\" is not actually a folder.")
        parser.print_help()
        sys.exit(1)
    if not os.path.exists(args.whitelist_file):
        print("Error: whitelist file \"" + args.whitelist_file + "\" does not exist.")
        sys.exit(1)
    if args.game_version:
        GAME_VERSION = util.game_version_from_string(args.game_version)
        
    # run the command
    if args.command == "install":
        util.install(args.version_file, args.whitelist_file, pack['location'])
    elif args.command == "apply_updates":
        util.apply_updates(mods, args.version_file, GAME_VERSION)
    elif args.command == "check_updates":
        util.check_updates(mods, args.version_file, GAME_VERSION)
    else:
        print("Error: command \"" + args.command + "\" does not exist")
        parser.print_help()
        sys.exit(1)