def installModConfigs(mod, modEdits): pendingEdits = [] # read default configs editingConfigs = {} for sourcePath, targetPath in getConfigFiles(mod): data = file(sourcePath).read() editingConfigs[targetPath] = data # apply edits alreadyEditedLines = {} for mod, kind, oldId, newId in modEdits: success = False for targetPath, data in editingConfigs.iteritems(): data, thisFailed, editedLineText = applyConfigEdit(mod, data, kind, oldId, newId, excludeLineTexts=alreadyEditedLines.get(targetPath, set())) editingConfigs[targetPath] = data if not thisFailed: success = True # record this line as 'we edited it', so we don't edit it again if not alreadyEditedLines.has_key(targetPath): alreadyEditedLines[targetPath] = set() alreadyEditedLines[targetPath].add(editedLineText) break if not success: #print "MANUAL EDIT",mod,kind,oldId,newId pendingEdits.append((mod, kind, oldId, newId)) # write files needsMerge = False for targetPath, data in editingConfigs.iteritems(): print "Installing %s [%s]" % (targetPath, len(modEdits)) modanalyzer.mkdirContaining(targetPath) if os.path.exists(targetPath): print "NOTICE: Mod reuses config: installing configs for %s from %s but %s already exists - needs merge" % (mod, sourcePath, targetPath) readme = "\n" + ("#" * 70) + "\n# TODO: Merge from " + modanalyzer.getModName(mod) + "\n" + ("#" * 70) + "\n" data = readme + data needsMerge = True pendingEdits += modEdits # probably everything, to be safe # TODO: try to merge automatically? file(targetPath, "a").write(data) return pendingEdits
def getModGirth(contents, mod): key = modanalyzer.getModName(mod) + ".csv" if not contents.has_key(key): print "No mod analysis found for %s, please analyze" % (mod,) sys.exit(-1) content = contents[key] blocks = content.get("block", []) girth = len(blocks) * 1000 + len(content) # TODO: more in-depth analysis, weights for different content types? (blocks > item?) # TODO: also factor in id 'immobility', higher priority if can't move? return girth
def getPriority(m): if m.startswith("Minecraft"): return -1 return sortedMods.index(modanalyzer.getModName(m.replace(".csv", "")))