def transfer_tkinst(): global tkinst recieve_tkinst_util(tkinst) CMAN_install.recieve_tkinst_install(tkinst) CMAN_remove.recieve_tkinst_remove(tkinst) CMAN_upgrade.recieve_tkinst_upgrade(tkinst) CMAN_importexport.recieve_tkinst_importexport(tkinst) CMAN_gui.recieve_tkinst_gui(tkinst)
def gui_setup_config(_instance): global modfolder, versionsfolder, instance, gui os.chdir(os.path.join(execdir, "LocalData")) instance = _instance modfolder, versionsfolder = read_config(_instance) #gets config stuff os.chdir(execdir) init_config_util((modfolder, versionsfolder, execdir, instance, gui)) #transferring config data (and Tkinter instance) to all files CMAN_install.init_config_install((modfolder, versionsfolder, execdir, instance, gui)) CMAN_remove.init_config_remove((modfolder, versionsfolder, execdir, instance, gui)) CMAN_upgrade.init_config_upgrade((modfolder, versionsfolder, execdir, instance, gui)) CMAN_importexport.init_config_importexport((modfolder, versionsfolder, execdir, instance, gui)) init_config_gui((modfolder, versionsfolder, execdir, instance, gui))
def upgrade_mod(modname): os.chdir(execdir + "/Data/CMAN-Archive") if(modname == None): modname = input("Enter mod name: ") update = [get_installed_json(modname),get_json(modname)] if(os.path.exists(os.path.join(execdir + "/LocalData/ModsDownloaded/"+instance, modname + ".installed"))): # Telling user that file exists for file in glob.glob(modname + ".installed"): cprint(file + " found.") else: cprint("Mod "+modname+" not found.") return os.chdir(execdir + "/LocalData") #restoring current working dir if(update[1]["Version"] != update[0]["Version"] and mod_installed(modname)): CMAN_remove.remove_mod(modname) CMAN_install.install_mod(modname) elif(not mod_installed(modname)): cprint(modname+" is not installed.") else: cprint(modname+" is already up to date.")
def parsecmd(command): if (command.split(" ")[0] == "update"): update_archive() elif (command.split(" ")[0] == "upgrades"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): inst = command.split(" ")[1] if (inst == "*"): inst = None if (not instance_exists(inst) and inst != None): cprint("Instance " + inst + " does not exist.") return update_archive() CMAN_upgrade.check_upgrades(True, inst) elif (len(command.split(" ")) == 1): inst = input("Enter instance name: ") if (inst == "*"): inst = None if (not instance_exists(inst) and inst != None): cprint("Instance " + inst + " does not exist.") return update_archive() CMAN_upgrade.check_upgrades(True, inst) else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "upgrade"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): mod = command.split(" ")[1] update_archive() upgrades = CMAN_upgrade.get_upgrades() CMAN_upgrade.upgrade_mod(mod) elif (len(command.split(" ")) == 1): mod = None update_archive() upgrades = CMAN_upgrade.get_upgrades() CMAN_upgrade.upgrade_mod(mod) else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "upgradeall"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): inst = command.split(" ")[1] if (inst == "*"): inst = None if (not instance_exists(inst) and inst != None): cprint("Instance " + inst + " does not exist.") return elif (len(command.split(" ")) == 1): inst = input("Enter instance name: ") if (inst == "*"): inst = None if (not instance_exists(inst) and inst != None): cprint("Instance " + inst + " does not exist.") return else: cprint("Invalid command syntax.") update_archive() updates = CMAN_upgrade.get_upgrades(inst) if (len(updates) == 0): cprint("No upgrades available.") else: for update in updates: CMAN_upgrade.upgrade_mod(update[0]["Name"]) elif (command.split(" ")[0] == "install"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): mod = command.split(" ")[1] update_archive() CMAN_install.install_mod(mod) elif (len(command.split(" ")) == 1): mod = None update_archive() CMAN_install.install_mod(mod) else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "remove"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): mod = command.split(" ")[1] CMAN_remove.remove_mod(mod) elif (len(command.split(" ")) == 1): mod = None CMAN_remove.remove_mod(mod) else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "info"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): mod = command.split(" ")[1] get_info(mod) elif (len(command.split(" ")) == 1): mod = None get_info(mod) elif (command.split(" ")[0] == "installm" or command.split(" ")[0] == "installmany"): if (len(command.split(" ")) >= 2): modslist = command.split(" ")[1:] # separate mod names with spaces update_archive() string = "Attempting to install: " for item in modslist: string = string + item + ", " cprint(string[:-2] + "..." ) # [:-2] to cut off the extra ", " after the last element for item in modslist: CMAN_install.install_mod(item) else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "removem" or command.split(" ")[0] == "removemany"): if (len(command.split(" ")) >= 2): modslist = command.split(" ")[1:] # separate mod names with spaces update_archive() string = "Attempting to remove: " for item in modslist: string = string + item + ", " cprint(string[:-2] + "..." ) # [:-2] to cut off the extra ", " after the last element for item in modslist: CMAN_remove.remove_mod(item) else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "upgradem" or command.split(" ")[0] == "upgrademany"): if (len(command.split(" ")) >= 2): modslist = command.split(" ")[1:] # separate mod names with spaces update_archive() string = "Attempting to upgrade: " for item in modslist: string = string + item + ", " cprint(string[:-2] + "..." ) # [:-2] to cut off the extra ", " after the last element for item in modslist: CMAN_upgrade.upgrade_mod(item) else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "export"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): name = command.split(" ")[1] update_archive() CMAN_importexport.export_mods(name) elif (len(command.split(" ")) == 1): name = None update_archive() CMAN_importexport.export_mods(name) else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "import"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): path = command.split(" ")[1] update_archive() CMAN_importexport.import_mods(path) elif (len(command.split(" ")) == 1): path = None update_archive() CMAN_importexport.import_mods(path) else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "instance" or command.split(" ")[0] == "inst"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): name = command.split(" ")[1] if (instance_exists(name)): if (name == instance): cprint("Instance " + name + " already selected!") else: setup_config(name) cprint("Switched to instance " + name + ".") else: cprint("Instance " + name + " does not exist.") elif (len(command.split(" ")) == 1): name = input("Enter instance name: ") if (instance_exists(name)): if (name == instance): cprint("Instance " + name + " already selected!") else: setup_config(name) cprint("Switched to instance " + name + ".") else: cprint("Instance " + name + " does not exist.") else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "setdefaultinstance" or command.split(" ")[0] == "setdefaultinst"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): name = command.split(" ")[1] if (instance_exists(name)): if (name == read_default_instance()): cprint("Instance " + name + " already set as default!") else: with open("default_instance.txt", "w") as f: f.write(name) cprint("Set default instance as " + name + ".") else: cprint("Instance " + instance + " does not exist.") elif (len(command.split(" ")) == 1): name = input("Enter instance name: ") if (instance_exists(name)): if (name == read_default_instance()): cprint("Instance " + instance + " already set as default!") else: with open("default_instance.txt", "w") as f: f.write(name) cprint("Set default instance as " + name + ".") else: cprint("Instance " + name + " does not exist.") else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "addinstance" or command.split(" ")[0] == "addinst"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): name = command.split(" ")[1] if (instance_exists(name)): cprint("Instance " + name + " already exists.") else: new_config(name) elif (len(command.split(" ")) == 1): name = input("Enter instance name: ") if (instance_exists(name)): cprint("Instance " + name + " already exists.") else: new_config(name) else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "rminstance" or command.split(" ")[0] == "removeinstance" or command.split(" ")[0] == "rminst"): if (len(command.split(" ")) == 2 and command.split(" ")[1] != ""): name = command.split(" ")[1] if (instance_exists(name)): rm_config(name) else: cprint("Instance " + name + " does not exist.") elif (len(command.split(" ")) == 1): name = input("Enter instance name: ") if (instance_exists(name)): rm_config(name) else: cprint("Instance " + name + " does not exist.") else: cprint("Invalid command syntax.") elif (command.split(" ")[0] == "instances" or command.split(" ")[0] == "insts"): with open("config.json") as json_file: json_data = json.load(json_file) insts = json_data.keys() cprint("Instances:") for inst in insts: if (inst == instance): cprint(inst + " (selected)") else: cprint(inst) elif (command.split(" ")[0] == "list"): listmods() elif (command.split(" ")[0] == "version"): cprint("CMAN v" + version) elif (command.split(" ")[0] == "help" or command.split(" ")[0] == "?"): print_help() elif (command.split(" ")[0] == "exit"): sys.exit() elif (command == ""): pass # don't print "Unknown command." for empty line else: cprint("Unknown command.")
upgradesavailable = CMAN_upgrade.get_upgrades(instance) if (upgradesavailable == []): pass else: cprint("The following upgrades are available for instance " + instance + ":") for upgrade in upgradesavailable: cprint(" " + upgrade[0]["Name"] + " (current version: " + upgrade[1]["Version"] + ", you have: " + upgrade[0]["Version"] + ")") if (args.install != "None"): CMAN_install.install_mod(args.install) sys.exit() if (args.remove != "None"): CMAN_remove.remove_mod(args.remove) sys.exit() if (args.upgrade != "None"): CMAN_upgrade.upgrade_mod(args.upgrade) sys.exit() if (args.info != "None"): get_info(args.info) sys.exit() if (args.export != "None"): CMAN_importexport.export_mods(args.export) sys.exit() if (args.importa != "None"): CMAN_importexport.import_mods(args.importa) sys.exit() if (gui == False):
def removmods(): _mods = map(int, tkinst.mlisti.curselection()) for _mod in _mods: CMAN_remove.remove_mod(tkinst.modsi[int(_mod)]["Name"]) updateinst()