Last active
August 29, 2015 13:56
-
-
Save belotn/9074429 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.etree.ElementTree as ET | |
import importlib | |
import sys | |
import os | |
if len(sys.argv) > 1: | |
xmlfile = sys.argv[1] | |
else: | |
xmlfile = os.path.normpath( os.getcwd() + "/backup.xml") | |
print(xmlfile) | |
tree = ET.parse(xmlfile) | |
root = tree.getroot() | |
modIncluded = [] | |
configuration = root.find('configuration') | |
if configuration.findall('lib'): | |
for inc in configuration.findall('lib'): | |
modIncluded.append ( importlib.import_module(inc.text ) ) | |
def FindFunction(name): | |
for mod in modIncluded: | |
if name in dir(mod): | |
return mod.__dict__[name] | |
backups = root.find('backups') | |
sources = root.find('sources') | |
destination = root.find('destinations') | |
print(" step 1 : fetching configuration") | |
for bck in backups: | |
source = bck.get('source') | |
dest = bck.get('destination') | |
print("need to backup " + source + " in " + dest) | |
nodeSource = sources.find("source[@name='" + source + "']") | |
nodeDestination = destination.find("destination[@name='" + dest + "']") | |
fun = FindFunction("Source_" + nodeSource.get('type').capitalize()) | |
#fun = globals()["Source_" + nodeSource.get('type').capitalize()] | |
file = fun(nodeSource) | |
fun=FindFunction("Destination_" + nodeDestination.get('type').capitalize()) | |
#fun = globals()["Destination_" + nodeDestination.get('type').capitalize()] | |
fun(file, nodeDestination) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment