Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # coding: utf8
- # Cossacks 3 mod manager V 1.0
- #require python 3.5.x download link https://www.python.org/downloads/
- import sys
- def main(argv):
- if len (argv) == 1:
- printhelp()
- return
- if argv[1] == "install":
- if len(argv) < 2:
- mod = input("Please type name of mod file: ")
- else:
- mod = argv[2]
- mod = open(mod, "r").read().split("*PATH*")
- for _mod in mod:
- if _mod == "":
- continue
- path, instruction = _mod.split("\n", 1)
- if not backup(path):
- print("Fatal error")
- return
- else:
- print("Backup of", path, "succed!")
- if not apply(instruction, path):
- print("Fatal error")
- return
- else:
- print("Patching of", path, "succed!")
- def backup(path):
- try:
- open(path + ".backup", "w").write(open(path, "r").read())
- return True
- except:
- print("Impossible to write in", path)
- return False
- def apply(instruction, path):
- try:
- txt = open(path, "r").read()
- except:
- print("File", path, "don't exist or you havn't access to it.")
- return False
- try:
- mod = [(old, new) for old, new in [_instruction.split("*REPLACE*") for _instruction in instruction.split("*END*") if _instruction != '']]
- except:
- print("Bad format file for", mod)
- return False
- for old, new in mod:
- txt = txt.replace(old, new)
- try:
- open(path, "w").write(txt)
- except:
- print("Impossible to write in", path)
- return False
- return True
- def printhelp():
- print("python c3mm.py [instruction] [options]\n\t Instruction:\n\tinstall + path : install a cossacks3 mod files.")
- if __name__ == "__main__":
- main(sys.argv)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement