两个文件,一个shell脚本,一个python脚本: #!/bin/bash # Filename : repairEasymule.sh # Author : Jasmine Ding ( celavi#126.com ) # Date : 2011-4-12 # Location : Shanghai, China # Purpose : call parse.xml to repair damaged tasks caused by easyMule exceptional exit cp ~/Library/Application/ Support/easyMule2/EMEnv/Services/FileTransferService/Tasks.xml ./TasksBak.xml head -2 TasksBak.xml > taskhead tail -1 TasksBak.xml > tasktail sed 's/&#//g' TasksBak.xml > Tasks.xml :> allTasks.xml; find ~/Library/Application/ Support/easyMule2/EMEnv/Services/FileTransferService/Tasks/ -name taskBasicInformationBackUp.xml -exec cat {} >> allTasks.xml /; sed 's/<?xml version="1.0" encoding="UTF-8" ?>//' allTasks.xml > allTasks_tmp1.xml sed 's/&#//g' allTasks_tmp1.xml > allTasks_tmp2.xml cat taskhead allTasks_tmp2.xml tasktail > allTasks2.xml python parse.py rm allTasks.xml allTasks2.xml allTasks_tmp1.xml allTasks_tmp2.xml Tasks.xml taskhead tasktail echo "--------------------------------------------------------------------------------" echo "Automatic process is over, now please do manual steps as below:" echo "Step 1: Please backup your easyMule Tasks.xml!" echo "Step 2: then copy the TasksNew.xml to your easyMule directory manually." echo "Step 3: rename the TasksNew.xml to Tasks.xml" echo "For your reference: the path is $HOME/Library/Application/ Support/easyMule2/EMEnv/Services/FileTransferService/" echo "--------------------------------------------------------------------------------" #!/usr/bin/python # Filename : parse.py # Author : Jasmine Ding ( celavi#126.com ) # Date : 2011-4-12 # Location : Shanghai, China # Purpose : called by repairEasymule.sh to repair damaged tasks caused by easyMule exceptional exit import xml.etree.ElementTree as etree # 1. The Tasks.xml is the original easyMule Tasks.xml, copied here by repairEasymule.sh tree = etree.parse('Tasks.xml') # 2. The allTasks2.xml is the transformed one from all task backup xml, created by repairEasymule.sh tree2 = etree.parse('allTasks2.xml') # 3. begin xml process (Only repair tasks which lost DisplayNames and OriginalURL and are not completed) root = tree.getroot() root2 = tree2.getroot() i = 0 for task in root: dname = task.find("DisplayName").text ctime = task.find("CreateTime").text size = task.find("Size").text comp = task.find("Completed").text ourl = task.find("TaskConfig/OriginalURL").text if dname == None and ourl == None and comp < size: # 4. print the information of repaired task print "CreateTime:", ctime, "Size:", size, "Completed:", comp for task2 in root2: dname2 = task2.find("DisplayName").text ctime2 = task2.find("CreateTime").text size2 = task2.find("Size").text comp2 = task2.find("Completed").text ourl2 = task2.find("TaskConfig/OriginalURL").text if ctime == ctime2: # 4. print the repaired DisplayName print '---->',dname2 task.find("DisplayName").text = dname2 task.find("TaskConfig/OriginalURL").text = ourl2 i = i + 1 # 5. put all tasks including the repaired ones to a new xml file which should be copied to easyMule dir manullly tree.write("TasksNew.xml", encoding='UTF-8') # 6. print the statistic information print "Total tasks:", len(root), "Repaired tasks:", i