# Copyright 2021, Price Hiller - All Rights Reserved # # Copying, distribution, usage, or modification of this file or the following source code, via any # method is strictly prohibited without the explicit written consent of Price Hiller (philler3138@gmail.com) # The following file contains proprietary and confidential content # # # Copying, distribution, usage, or modification of this file or the following source code, via any # method is strictly prohibited without the explicit written consent of Price Hiller (philler3138@gmail.com) # The following file contains proprietary and confidential content # import sys import subprocess from pathlib import Path from bs4 import BeautifulSoup current_script = Path(__file__) def show_help(): print( f"Usage:\n" f" python[3] {current_script.parts[-1]} " ) def parse_html(html: str) -> list[list[str, int]]: html = BeautifulSoup(html, "html.parser") modlist = html.find("div", {"class": "mod-list"}) table = modlist.find("table") mods = [] for mod in table.findAll("tr"): mod: BeautifulSoup mod_link = mod.find("a").get("href") if not mod_link: continue mod_workshop_id = int(mod_link.split("id=")[-1]) mod_name: str = mod.find("td").contents[-1].replace(" ", "_").replace("-", "") mods.append([mod_name, mod_workshop_id]) return mods def main(args: list[str]): if args[1].casefold() == "--help" or args[1].casefold() == "-h": show_help() exit(0) if len(args) != 4: print( f"Invalid number of arguments found, refer to help:\n" f" python[3] {current_script.parts[-1]} --help" ) exit(1) else: path = Path(args[1]) user = args[2].strip() try: server = int(args[3]) except ValueError: print("Server must be a number!") exit(1) if not path.exists(): print("Invalid path received:\n" f" Received: \"{path.__str__()}\"") exit(1) elif not path.is_file(): print("Expected a file, please use a path to a file") exit(1) else: print(f"Installing all mods located in {path.parts[-1]} ({path.absolute()})") with open(path) as f: html = f.read() mods = parse_html(html) for mod in mods: command = f"Arma-Install-Mod -s {server} -w {mod[-1]} -u {user}" print(f"Executing: \"{command}\"") result = subprocess.run( command.split(" ") ) if result.returncode == 0: continue else: print(f"The following command failed: \"{command}\"") exit(result.returncode) print(f"Finished installing mods from: {path.parts[-1]} ({path.absolute()})") if __name__ == "__main__": try: main(sys.argv) except KeyboardInterrupt: exit(0)