def install_mod(mod_name, address, mod_directory, csv_list, the_mod_version=None, alpha_build="12d", log1file="installed_mods.csv"): # Change the current dir to ensure working and setting the version of the mod os.chdir(dname) the_mod_version = fh.extractVersionNumber("mods.csv", mod_name) # Check if the mod is already installed if (fh.isNameInFile(log1file, mod_name) and (fh.extractVersionNumber(log1file, mod_name) == fh.extractVersionNumber("mods.csv", mod_name))): print("Mod is already installed and has the newest version, too!") return True # Check if the mod is outdated and needs an update elif (((fh.extractVersionNumber(log1file, mod_name) != fh.extractVersionNumber("mods.csv", mod_name))) and fh.isNameInFile(log1file, mod_name)): print("Mod is outdated, starting update now") # TODO Update routine elif not fh.isNameInFile(log1file, mod_name): print("The mod isn't installed.") # TODO Searching for incompatibilities has to be done print("Searching for dependencies...") # Searching for dependencies splitter = [i.split(';', 1)[0] for i in csv_list[4]] if splitter: if csv_list != "None": for i in splitter: install_mod(i, getModData(i, csv_list[7], 7), mod_directory, csv_list) else: print("Mod has no dependencies") print("Downloading: " + mod_name) # Downloading the zipped mod path_to_file = dname + "/temp_mod_d/" + mod_name try: urllib.request.urlretrieve(address, path_to_file) except ValueError: # FIXME: Error, every second time install_mod() is called print("URL WRONG") return # Unzip the mod print("Unzipping...") unzip(path_to_file, dname + "/unzipped/") # Adding the modmanager.csv files to set the mod visible for this program registerMod(dname+ "/unzipped/", mod_name, the_mod_version, alpha_build) # Logging the installation of the mod print("Logging...") fh.logData(log1file, "%s|%s|%s|%s" % (mod_name ,the_mod_version, alpha_build, strftime("%Y-%m-%d %H:%M:%S", gmtime()))) # Move the file into the mod folder print("Moving file into mod folder") try: copyTree("unzipped/", mod_directory) except FileExistsError: print("Already installed") # Delete files after this process finally: clearDownloadFolder("unzipped/")