actionHist[action["type"]] += 1 actionOverviewHTML = " | ".join(map(lambda k_v: k_v[0] + "(" + str(k_v[1]) + ")", actionHist.items())) actionHTMLFile.write(templateParts[0].replace("<!-- OVERVIEW -->", actionOverviewHTML)) # Writing this directly is a lot faster than concatenating huge strings for action in actions: if action["type"] not in config["exclude_actionhtml_actions"]: # Insert zero width space, so that the line breaks at the backslashes itemClass = action["type"] itemText = action["type"] if "htmlFlags" in action["params"]: flags = action["params"]["htmlFlags"] itemClass += "_" + flags if flags == "emptyFolder": itemText += " (empty directory)" elif flags == "inNewDir": itemText += " (in new directory)" else: logging.error("Unknown html flags for action html: " + str(flags)) actionHTMLFile.write("\t\t<tr class=\"" + itemClass + "\"><td class=\"type\">" + itemText + "</td><td class=\"name\">" + action["params"]["name"].replace("\\", "\\​") + "</td>\n") actionHTMLFile.write(templateParts[1]) if config["open_actionhtml"]: os.startfile(actionHtmlFilePath) if config["apply_actions"]: executeActionList(backupDirectory, actions)
# Create the action object actionJson = "[\n" + ",\n".join(map(json.dumps, actions)) + "\n]" if config.SAVE_ACTIONFILE: # Write the action file actionFilePath = os.path.join(metadataDirectory, ACTIONS_FILENAME) logging.info("Saving the action file to " + actionFilePath) with open(actionFilePath, "w") as actionFile: actionFile.write(actionJson) if config.OPEN_ACTIONFILE: os.startfile(actionFilePath) if config.SAVE_ACTIONHTML: templatePath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "template.html") with open(templatePath, "r") as templateFile: template = templateFile.read() html = template.replace("<!-- JSON -->", actionJson) reportPath = os.path.join(metadataDirectory, ACTIONSHTML_FILENAME) with open(reportPath, "w") as reportFile: reportFile.write(html) if config.OPEN_ACTIONHTML: os.startfile(reportPath) if config.APPLY_ACTIONS: executeActionList(metadataDirectory, actions)
actions.append(Action("delete", name=element.path)) # Create the action object actionJson = "[\n" + ",\n".join(map(json.dumps, actions)) + "\n]" if config.SAVE_ACTIONFILE: # Write the action file actionFilePath = os.path.join(metadataDirectory, ACTIONS_FILENAME) logging.info("Saving the action file to " + actionFilePath) with open(actionFilePath, "w") as actionFile: actionFile.write(actionJson) if config.OPEN_ACTIONFILE: os.startfile(actionFilePath) if config.SAVE_ACTIONHTML: templatePath = os.path.join(os.path.dirname(os.path.abspath(__file__)), "template.html") with open(templatePath, "r") as templateFile: template = templateFile.read() html = template.replace("<!-- JSON -->", actionJson) reportPath = os.path.join(metadataDirectory, ACTIONSHTML_FILENAME) with open(reportPath, "w") as reportFile: reportFile.write(html) if config.OPEN_ACTIONHTML: os.startfile(reportPath) if config.APPLY_ACTIONS: executeActionList(metadataDirectory, actions)