sys.path.append("../lib")



import os
import xml.dom
from xml.dom import EMPTY_NAMESPACE
from xml.dom.ext import PrettyPrint
from xml.dom.ext.reader import Sax2
from xml import xpath


from comoonics import ComDisk
from comoonics.ecbase import ComUtils
from comoonics.enterprisecopy import ComCopyset


def printDom(doc):
    PrettyPrint(doc)

# create Reader object
reader = Sax2.Reader()

#parse the document
file=os.fdopen(os.open("./example_config.xml",os.O_RDONLY))
doc = reader.fromStream(file)

#element = xpath.Evaluate('businesscopy/copyset[@type=partition]', doc)[0]
element = xpath.Evaluate('enterprisecopy/copyset[@type="partition"]', doc)[0]
copyset=ComCopyset.getCopyset(element, doc)
copyset.doCopy()
if len(sys.argv) > 1:
    filename=sys.argv[1]

file=os.fdopen(os.open(filename,os.O_RDONLY))
doc = reader.fromStream(file)

line("XML Document")
PrettyPrint(doc)

line("sets of copyset@lvm")
sets = Evaluate('enterprisecopy/copyset[@type="lvm"]', doc)
print sets
try:
    for i in range(len(sets)):
        line("set[%u]" % i)
        cs=ComCopyset.getCopyset(sets[i], doc)
        print "Copyset: ", cs
        print "XML: "
        PrettyPrint(cs.getElement())
        line("write to dest: %s" % cs)
        ComSystem.__EXEC_REALLY_DO="ask"
        cs.doCopy()
except Exception, e:
    ComLog.getLogger("testMetadataCopyset").warn("Exception %s caught during copy. Undoing." % e)
    import traceback
    traceback.print_exc()
    cs.undoCopy()

##################
# $Log: testmetadata.py,v $
# Revision 1.2  2006-11-27 12:13:29  marc
    sys.exit(127)


print len(sys.argv)
if len(sys.argv) < 2:
    usage()

if sys.argv[1] == "fs2fs":
    xml = xml_fs2fs
elif sys.argv[1] == "fs2arc":
    xml = xml_fs2arc
elif sys.argv[1] == "arc2fs":
    xml = xml_arc2fs
else:
    usage()

#file=os.fdopen(os.open("./example_config.xml",os.O_RDONLY))
#doc = reader.fromStream(file)

doc = reader.fromString(xml)

PrettyPrint(doc)

sets = xpath.Evaluate('root/copyset[@type="filesystem"]', doc)
print sets
for i in range(len(sets)):
    print sets[i]
    cs = ComCopyset.getCopyset(sets[i], doc)
    cs.doCopy()
    print("NOW DO THE UNDO")
    cs.undoCopy()
import traceback

sys.path.append("../lib")

import os
import xml.dom
from xml.dom import EMPTY_NAMESPACE
from xml.dom.ext import PrettyPrint
from xml.dom.ext.reader import Sax2
from xml import xpath

from comoonics import ComDisk
from comoonics.ecbase import ComUtils
from comoonics.enterprisecopy import ComCopyset


def printDom(doc):
    PrettyPrint(doc)


# create Reader object
reader = Sax2.Reader()

#parse the document
file = os.fdopen(os.open("./example_config.xml", os.O_RDONLY))
doc = reader.fromStream(file)

#element = xpath.Evaluate('businesscopy/copyset[@type=partition]', doc)[0]
element = xpath.Evaluate('enterprisecopy/copyset[@type="partition"]', doc)[0]
copyset = ComCopyset.getCopyset(element, doc)
copyset.doCopy()