def testInit(self):
        from file_system import FileSystem
        from system import System, system
        fileSystem = FileSystem()

        print IceCommon.openOfficeName
        IceCommon.setup(system, fileSystem)
Exemple #2
0
    def setUp(self):
        # Make/setup self.sRep (with a basePath of tempRepPath)
        # Also set self.__fs to tempRepPath
        if self.recreateFSRep:
            removeTempFSRep()
            createTempFSRep()

        if IceCommon.system.isWindows:
            global tempRepPath
            tempRepPath = tempfile.mkdtemp()

        self.client = pysvn.Client()
        if self.recreateTempRep:
            removeTempRep()
            self.client.checkout(url=tempFSRepUrl + "/TestRep",
                                 path=tempRepPath,
                                 recurse=True)
        iceContext = IceCommon.IceContext
        self.rep = MockRep(IceCommon.FileSystem(tempRepPath))
        iceContext.rep = self.rep
        self.sRep = SvnRep(iceContext,
                           basePath=tempRepPath,
                           svnUrl=tempFSRepUrl + "/TestRep")
        if self.recreateTempRep == False:
            self.revert()
        self.fs = IceCommon.FileSystem(tempRepPath)
    def xtestObjectReplacementHack(self):
        buildTestFile = True
        fs = FileSystem(".")
        converter = oooConverter()
        fromBookFile = noMathtype
        toBookFile = "testData/testObjectReplacementHackResult.odt"
        fs.delete(toBookFile)
        self.assertFalse(fs.isFile(toBookFile))

        docs = [ (sample_mathtype, ""), (noMathtype, ""), \
                (sample_mathtypeAndNoMathType, ""), (linkfile, "") ]

        try:
            # build test infomation
            converter.buildBook(fromBookFile,
                                docs,
                                toBookFile,
                                baseUrl="http://localhost:8000",
                                title=None)

            self.assertTrue(fs.isFile(toBookFile))

            xmlString = """<root 
                        xmlns:draw='urn:oasis:names:tc:opendocument:xmlns:drawing:1.0' 
                        xmlns:xlink='http://www.w3.org/1999/xlink'
                        xmlns:text='urn:oasis:names:tc:opendocument:xmlns:text:1.0'
                        xmlns:svg='urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0'>"""

            # now assert the the toBookFile contains all the orginal enbedded objects.
            tempFs = fs.unzipToTempDirectory(toBookFile)
            xml = IceCommon.Xml(tempFs.absolutePath("content.xml"), nsList)
            nodes = xml.getNodes("//draw:frame")

            if buildTestFile == True:
                print "Building expectedxmlString.xml"
                for node in nodes:
                    xmlString += str(node)

                xmlString += "</root>"
                fs.writeFile("testData/expectedxmlString.xml", xmlString)
            else:
                #Compare current Book xml with the expected xml result
                xmlExpected = IceCommon.Xml("testData/expectedxmlString.xml",
                                            nsList)
                expectedNodes = xmlExpected.getNodes("//draw:frame")

                for node, expectedNode in zip(nodes, expectedNodes):
                    #Hack: for now just remove namespaces for testing
                    nodeStr = str(node).replace(":", "_")
                    expectedNodeStr = str(expectedNode).replace(":", "_")
                    self.assertSameXml(nodeStr, expectedNodeStr, \
                                "Nodes are not the same!")

                xmlExpected.close()
        finally:
            xml.close()
            tempFs.delete()
def test_getPreviousItem():
    print "test_getPreviousItem()"
    mockOrg = mockOrganization()
    
    xml = IceCommon.Xml(nestedItemTestXml)
    nestedItemTestNode = xml.getRootNode()
    item = imsItem(mockOrg, itemXmlNode=nestedItemTestNode)
    mockOrg.addItem(item)
    xml.close()

    print "===="
    print mockOrg.__class__.__name__
    print mockOrg.parentItem
    print mockOrg
    print "===="

    aItem = item.getNextItem().getNextItem()
    print "aItem=", aItem.title
    prevItem = aItem.getPreviousItem()
    print "prevItem=", prevItem.title
    assert prevItem.title == "Module 1 About Stuff"
    prevItem = prevItem.getPreviousItem()
    print "prevItem=", prevItem.title
    assert prevItem.title == "Study Guide"
    
    print "---"
    print prevItem.__class__.__name__
    print prevItem.parentItem
    print "---"
    prevItem = prevItem.getPreviousItem()
    print prevItem
    print "-----"
    def testAssertSameXml(self):
        xmlStr1 = "<root><item a='2' b='1'/></root>"
        xmlStr2 = "<root><item b=\"1\" a='2'></item></root>"
        xmlStr3 = "<root><item a='2' b='11'/></root>"
        t = self.test

        # should assert to being the same
        t.assertSameXml("<root/>", "<root></root>")
        t.assertSameXml(xmlStr1, xmlStr2)
        xml = IceCommon.Xml(xmlStr1)
        t.assertSameXml(xml, xmlStr1)
        t.assertSameXml(xml, xmlStr2)
        t.assertSameXml(xmlStr2, xml)
        xml.close()

        # should raise an AssertionError
        msg = self.__expectAssertionError(None, None)
        expectedMsg = 'Xml not the same!\n\t(not XML data) actual==None and expected==None!'
        self.assertEqual(msg, expectedMsg)
        #print repr(msg)

        msg = self.__expectAssertionError("", "")
        expectedMsg = 'Xml not the same!\n\tActual is not well-formed XML! (or is not an xmlString or dom/node)'
        self.assertEqual(msg, expectedMsg)
        #print repr(msg)

        msg = self.__expectAssertionError(None, "<root/>")
        expectedMsg = 'Xml not the same!\n\tactual==None and actual!=expected!'
        self.assertEqual(msg, expectedMsg)
        #print repr(msg)

        msg = self.__expectAssertionError(xmlStr1, xmlStr3)
        expectedMsg = 'Xml not the same!\n\t  <root>\n\n-   <item a="2" b="1"></item>\n\n+   <item a="2" b="11"></item>\n\n?                  +\n\n  </root>\n\nactual = \'<root>\n  <item a="2" b="1"></item>\n</root>\'\nexpected = \'<root>\n  <item a="2" b="11"></item>\n</root>\''
        self.assertEqual(msg, expectedMsg)
    def xtestExternalLinkReport(self):
        manifestItem = {"/": ["Package Title", 1, 0], "one.odt": ["One Title", 0, "one.htm"]}
        rep = MockRep(self.iceContext, {"/one.htm":""}, {"/one.htm":{"http://www.python.org":"linkText"}}, manifest=manifestItem)
        checker = CourseLinkCheck(self.iceContext)
        report = checker.report("/")
#        print report
#        print "----"
        dom = IceCommon.Xml(report)
        try:
            h1 = dom.getNode("//h1[1]")
            h1msg = h1.getNextSibling().content
            self.assertEqual(h1msg, "\nNo invalid internal links\n")
            
            h1 = dom.getNode("//h1[2]")
            #print str(h1)
            nextSibling = h1.getNextSibling()
            if nextSibling.getType()=="text":
                nextSibling = nextSibling.getNextSibling()
            listItem = nextSibling.getNode("li[1]")
            #print str(listItem)
            self.assertEqual(len(listItem.getNodes("a")), 1)
            self.assertEqual(listItem.getNode("a/@href").content, "/one.htm")
            #print h1msg
            #self.assertEqual(h1msg, "No external links found")
        finally:
            dom.close()
 def testProperties(self):
     rep = self.getRep()
     item = self.getItem(rep, relPath="testDir/test.odt")
     data = IceCommon.fs.readFile(testOdt)
     item.write(data)
     self.assertEquals(item.relPath, "/testDir/test.odt")
     self.assertTrue(item._propAbsPath.endswith("/testDir/.ice/test.odt"))
     self.assertEquals(len(item.guid), 32)
     self.assertFalse(item.convertFlag)
     self.assertFalse(item.hasPdf)
     self.assertFalse(item.hasHtml)
     self.assertEquals(item.hasSlide, None)
     self.assertFalse(item.needsUpdating)
     self.assertEquals(item.tags, [])
     self.assertEquals(item.inlineAnnotations, None)
     self.assertEquals(item.bookInfo, None)
     self.assertEquals(item.lastChangedRevisionNumber, -1)
     self.assertFalse(item.isRenderable)
     parent = item.parentItem
     #setConvertedData()
     cd = item.iceContext.ConvertedData()
     cd.addMeta("title", "TestTitle")
     cd.addRenditionData(".xhtml.body", "<div><p>TestPara</p></div>")
     cd.addRenditionData(".pdf", "[PDF-DATA]")
     item.setConvertedData(cd)
     #item.hasHtml, item.hasPdf  still both False
     self.assertEquals(item.metaNames, ["title"])
     self.assertEquals(item.getMeta("title"), "TestTitle")
     self.assertEquals(item.getRendition(".pdf"), "[PDF-DATA]")
     rep.serverData = IceCommon.Object()
     def getIdForRelPath(relPath):
         return 0x555
     rep.serverData.getIdForRelPath = getIdForRelPath
     self.assertEquals(item.getIdUrl(), "test_i555r-1.odt")
def iceWebServer(IceCommon, options, outputWriter):
    iceContext = IceCommon.IceContext(options=options)
    iceContext.loadRepositories()
    settings = iceContext.settings
    asServiceOnly = bool(
        options.get("asserviceonly", settings.get("asServiceOnly", False)))
    enableExternalAccess = bool(
        options.get("enableexternalaccess",
                    settings.get("enableExternalAccess", False)))
    port = int(options.get("port", options.get("p", iceContext.config.port)))
    settings["asServiceOnly"] = asServiceOnly
    settings["enableExternalAccess"] = enableExternalAccess
    webserver = options.get("webserver", settings.get("webServer", "default"))
    iceContext.isServer = options.get("server", settings.get("server", False))
    settings["webserver"] = webserver
    iceContext.config.setPort(str(port))
    if asServiceOnly:
        outputWriter("* asServiceOnly *\n")
    if enableExternalAccess:
        outputWriter("* external access enabled *\n")
    if iceContext.isServer:
        outputWriter("* running as a server!\n")
    iceServer = IceServer(iceContext, IceRequest, ServerRequestData,
                          ServerResponseData)
    iceServer.serve()
def test_load():
    print "test_load()"
    item = imsItem(mockOrg)

    xml = IceCommon.Xml(simpleItemTestXml)
    simpleItemTestNode = xml.getRootNode()
    item.load(simpleItemTestNode)
    assertSameXml(str(item), str(simpleItemTestNode))
    xml.close()
    
    
    xml = IceCommon.Xml(nestedItemTestXml)
    nestedItemTestNode = xml.getRootNode()
    item.load(nestedItemTestNode)
    assertSameXml(str(item), str(nestedItemTestNode))
    xml.close()
Exemple #10
0
def test_serialize():
    #    serialize(xml)  - (overriden)
    org = getTestOrg()

    xml = IceCommon.Xml("<root/>")
    orgNode = org.serialize(xml)
    assertSameXml(str(orgNode), organizationXmlStr)
    xml.close()
 def __init__(self, IceCommon):
     self.fs = IceCommon.FileSystem(".")
     self.system = system
     self.xmlUtils = IceCommon.xmlUtils
     self.rep = MockRep(self.fs)
     self.isWindows = system.isWindows
     self.isLinux = system.isLinux
     self.isMac = system.isMac
def test_serialize():
    print "test_serialize()"
    xml = IceCommon.Xml(simpleItemTestXml)
    simpleItemTestNode = xml.getRootNode()
    item = imsItem(mockOrg, itemXmlNode=simpleItemTestNode)
    node = item.serialize(xml)
    assertSameXml(str(node), simpleItemTestXml)
    xml.close()
Exemple #13
0
def getTestOrg():
    parent = mockParent()
    org = imsOrganization(parent)
    xml = IceCommon.Xml(organizationXmlStr)
    node = xml.getRootNode()
    org.load(node)
    xml.close()
    return org
 def getRep(self):
     iceContext = IceCommon.IceContext(None)
     output = iceContext.output
     iceContext.output = None
     setupRep(self.fs)
     rep = IceRepository(iceContext, testRep, repUrl=repUrl, 
                         iceRender=MockIceRender(iceContext))
     iceContext.output = output
     return rep
def main(IceCommon, args, sys, outputWriter):
    shortOptionNames = {"h":"help", "f":"file", "d":"directory", "dir":"directory",
                        "converter":"convert", "v":"verbose", "test":"testing"}
    flags = ["help", "convert", "atompub", "atomconvertpub", "upgrade",
             "verbose", "asserviceonly", "enableexternalaccess", "test"]
    progName = args.pop(0)
    options = IceCommon.getOptions(args, shortOptionNames, flags)
    iceWebServer(IceCommon, options, outputWriter)
    outputWriter("\n")
    return 0
def processTest(name, xsltSrc, xmlSrc, expectedXml):
    print "--- Test: '%s' ---" % name
    xslt = xslt_util.xslt(xsltSrc)

    r = "<root"
    for ns in nsList:
        r += "  xmlns:" + ns[0] + '="' + ns[1] + '"\n'
    r += ">\n"
    r += xmlSrc + "\n</root>"
    xml = IceCommon.Xml(r, nsList)
    newXml = xml.applyXslt(xslt)
    xslt.close()
    xml.close()
    expected = expectedXml.replace("utfx:expected",
                                   "body").replace(' validate="no"', "")
    html = """<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type"></meta>
  <title> Untitled </title>
  <style type="text/css" xml:space="preserve">table {border-spacing: 0;empty-cells: show;} </style>
</head>
<body>
</body>
</html>"""
    xml = IceCommon.Xml(expected, nsList)
    import diff_util
    same = diff_util.sameXml(newXml.getNode("//body"), xml.getNode("//body"),
                             False)
    print "Same=", same
    if same is False:
        for node in newXml.getNode("//body").getChildren():
            if node.getType() != "text":
                print node
        print
        for node in xml.getNode("//body").getChildren():
            if node.getType() != "text":
                print node

    newXml.close()
    xml.close()
    print "--- Done ---\n"
def test_load_serialize():
    parent = mockParent()
    orgs = imsOrganizations(parent)
    xml = IceCommon.Xml(orgsXmlTestStr)

    orgs.load(xml.getRootNode())

    orgsNode = orgs.serialize(xml)
    expected = """<organizations default="default"><mockOrganization identifier="default"/><mockOrganization identifier="test-id"/></organizations>"""
    assertSameXml(orgsNode, expected)

    xml.close()
Exemple #18
0
def formatPart(xmlStr, match, format=True):
    xml = IceCommon.Xml(xmlStr, [("", "http://www.w3.org/1999/xhtml"),
                                 ("html", "http://www.w3.org/1999/xhtml")])
    matchContent = xml.getNode(match)
    s = str(matchContent)
    if format:
        pr = prettyPrint(s)
        pr = pr[pr.find("\n") + 1:]
    else:
        pr = s
    xml.close()
    return pr
def test_title():
    print "test_title"
    item = imsItem(mockOrg)
    xml = IceCommon.Xml(simpleItemTestXml)
    simpleItemTestNode = xml.getRootNode()
    
    assert item.title == ""
    item.load(simpleItemTestNode)
    assert item.title == "Introduction"
    item.title = "test"
    assert item.title == "test"
    xml.close()
def test_getItem():
    print "test_getItem()"
    
    xml = IceCommon.Xml(nestedItemTestXml)
    nestedItemTestNode = xml.getRootNode()
    item = imsItem(mockOrg, itemXmlNode=nestedItemTestNode)

    childItems = item.getAllChildItems()
    for childItem in childItems:
        i = item.getItem(childItem.identifier)
        assert i is childItem
    xml.close()
    assert item.getItem(item.identifier) is item
def test_resource():
    print "test_resource"
    item = imsItem(mockOrg)
    
    xml = IceCommon.Xml(simpleItemTestXml)
    simpleItemTestNode = xml.getRootNode()
    item.load(simpleItemTestNode)
    id = simpleItemTestNode.getAttribute("identifierref")
    
    resource = item.resource
    res = mockOrg.resources[id]
    assert resource is res
    xml.close()
def test_getItemByIdRef():
    # NOTE: returns the first item found with this idRef
    print "test_getItemByIdRef()"

    xml = IceCommon.Xml(nestedItemTestXml)
    nestedItemTestNode = xml.getRootNode()
    item = imsItem(mockOrg, itemXmlNode=nestedItemTestNode)

    childItems = item.getAllChildItems()
    for childItem in childItems:
        i = item.getItemByIdRef(childItem.identifierRef)
        assert i is childItem
    xml.close()
    assert item.getItemByIdRef(item.identifierRef) is item
def test_isWordDoc():
    print "test_isWordDoc"
    item = imsItem(mockOrg)
    
    xml = IceCommon.Xml(simpleItemTestXml)
    simpleItemTestNode = xml.getRootNode()
    
    item.load(simpleItemTestNode)
    assert item.isWordDoc == False
    
    item.resource.isWordDoc = True
    assert item.isWordDoc == True
    
    xml.close()
 def read(self):
     file = self.relPath
     data = None
     if file.endswith("/manifest.xml"):
         dom = IceCommon.Xml("<dummy xmlns='http://www.imsglobal.org/xsd/imscp_v1p1'/>", \
                 [("x", "http://www.imsglobal.org/xsd/imscp_v1p1")])
         rNode = dom.getRootNode()
         resNode = dom.createElement("resource")
         rNode.addChild(resNode)
         for name in self.contents.keys():
             fNode = dom.createElement("file", href=name)
             resNode.addChild(fNode)
         data = str(dom)
         dom.close()
     return data
    def xtestImageObject(self):
        fs = FileSystem(".")
        fromBookFile = noMathtype

        tempFs = fs.unzipToTempDirectory(fromBookFile)
        xml = IceCommon.Xml(tempFs.absolutePath("content.xml"), nsList)
        nodes = xml.getNodes("//draw:frame")
        #nodes = xml.getNodes("//draw:frame[draw:object-ole]")

        for node in nodes:
            objectOleNode = node.getNode("*[local-name()='object-ole']")
            self.assertFalse(objectOleNode == None,
                             "Only Image File not Object")

        xml.close()
def setupRep(fs=None):
    global repUrl
    if fs is None:
        fs = IceCommon.FileSystem(".")
    try:
        fs.delete(testSvnRep)
    except: pass
    try:
        fs.delete(testRep)
    except: pass
    if IceCommon.system.isWindows:
        repUrl = "file:///" + fs.join(fs.absolutePath("."), testSvnRep)
    else:
        repUrl = "file://" + fs.join(fs.absolutePath("."), testSvnRep)
    repUrl += "/testRep"
    fs.unzipToDirectory(testSvnRepZip, testSvnRep)
def test_addItemBefore():
    print "test_addItemBefore()"
    item1 = imsItem(mockOrg)
    item1.title = "One"
    item2 = imsItem(mockOrg)
    item2.title = "Two"
    item3 = imsItem(item2)
    item3.title = "Three"
    
    item1.addItem(item2)
    item1.addItemBeforeItem(item3, item2)
    xml = IceCommon.Xml("<root/>")
    xml.addChild(item1.serialize(xml))
    assert xml.getContent("/item/title") == "One"
    assert xml.getContent("/item/item/title") == "Three"
    assert xml.getContent("/item/item[2]/title") == "Two"
    xml.close()
 def xtestEmptyReport(self):
     rep = MockRep(self.iceContext)
     checker = CourseLinkCheck(self.iceContext)
     report = checker.report("/")
     
     dom = IceCommon.Xml(report)
     try:
         h1 = dom.getNode("//h1[1]")
         h1msg = h1.getNextSibling().content
         #print h1msg
         self.assertEqual(h1msg, "\nNo invalid internal links\n")
         
         h1 = dom.getNode("//h1[2]")
         h1msg = h1.getNextSibling().content
         #print h1msg
         self.assertEqual(h1msg, "\nNo external links found\n")
     finally:
         dom.close()
def test_itemInit():
    print "test_itemInit()"
    item = imsItem(mockOrg)
    xmlStr = str(item)
    assert xmlStr == """<item identifierref="" identifier="" isvisible="True"><title></title></item>"""

    xml = IceCommon.Xml(simpleItemTestXml)
    simpleItemTestNode = xml.getRootNode()    
    item = imsItem(mockOrg, itemXmlNode=simpleItemTestNode)
    assertSameXml(str(item), str(simpleItemTestNode))
    
    resource = mockOrg.resources.testGetResource(0)
    item = imsItem(mockOrg, resource=resource)
    expected = """<item identifierref="61259e595362bef92c48bbc3a018263c" identifier="mock-61259e595362bef92c48bbc3a018263c-1" isvisible="True"><title>/test/intro/introduction.htm-title</title></item>"""
    print (str(item))
    assertSameXml(str(item), expected)

    xml.close()
def test_load_serialize():
    parent = mockParent()
    ress = ImsResources(parent)

    xml = IceCommon.Xml(resourcesXmlStr)
    ress.load(xml.getRootNode())
    
    href = "intro/assessment.htm"
    id = "1d8994d66d3f5774b5d92b143bfd2daa"
    assert ress.containsResource(href)
    assert ress.getResourceByHref(href) is not None
    assert ress[id] is not None
    
    ressXmlStr = """<resources><resource href="intro/assessment.htm" identifier="1d8994d66d3f5774b5d92b143bfd2daa" mock="True"/></resources>"""
    assert str(ress) == ressXmlStr
    ressNode = ress.serialize(xml)
    assertSameXml(ressNode, ressXmlStr)
    
    xml.close()
def main(IceCommon, args, sys, outputWriter):
    shortOptionNames = {
        "h": "help",
        "f": "file",
        "d": "directory",
        "dir": "directory",
        "converter": "convert",
        "v": "verbose",
        "test": "testing"
    }
    flags = [
        "help", "convert", "atompub", "atomconvertpub", "upgrade", "verbose",
        "asserviceonly", "enableexternalaccess", "test"
    ]
    progName = args.pop(0)
    options = IceCommon.getOptions(args, shortOptionNames, flags)
    iceWebServer(IceCommon, options, outputWriter)
    outputWriter("\n")
    return 0
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

from ice_common import IceCommon
IceCommon.setup()


from xml_diff import XmlTestCase, XmlDiff

from ims_resources import ImsResources


imsNSList = [ \
            ("ims", "http://www.imsglobal.org/xsd/imscp_v1p1"), \
            ("imsmd", "http://www.imsglobal.org/xsd/imsmd_v1p2"), \
            ("xsi", "http://www.w3.org/2001/XMLSchema-instance"), \
         ]

resourcesXmlStr = """<resources>
    <resource identifier="1d8994d66d3f5774b5d92b143bfd2daa" type="webcontent"
def main(args, sys, outputWriter):
    shortOptionNames = {"h":"help", "f":"file", "d":"directory", "dir":"directory",
                        "converter":"convert", "v":"verbose", "test":"testing"}
    flags = ["help", "convert", "atompub", "atomconvertpub", "upgrade",
             "verbose", "asserviceonly", "enableexternalaccess", "test", "open"]
    progName = args.pop(0)
    options = IceCommon.getOptions(args, shortOptionNames, flags)
    fs = IceCommon.FileSystem(IceCommon.workingDirectory)
    convert = options.get("convert", False)
    atompub = options.get("atompub", False) or options.get("atomconvertpub", False)
    if convert or atompub:
        file = options.get("file")
        directory = options.get("directory")
        template = options.get("template")
        if file is not None:
            options["file"] = fs.absolutePath(file)
        if directory is not None:
            options["directory"] = fs.absolutePath(directory)
        if template is not None:
            options["template"] = fs.absolutePath(template)
        class OurOutput(object):
            def __init__(self):
                import tempfile
                self.__f = open(tempfile.gettempdir() + "/ice.log", "wb")
            def write(self, data):
                sys.stdout.write(data)
                self.__f.write(data.replace("\n", "\r\n"))
            def close(self):
                self.__f.close()
        output = OurOutput()
        stderr = sys.stderr
        sys.stderr = output
        converterAppMain(progName, options, fs=fs, output=output)
        output.close()
        sys.stderr = stderr
    elif options.get("svn", None) is not None:
        # SVN command
        usageMessage = "Usage: -svn:export -path:UrlOrAbsolutePathToExport -dir:exportToDirectory"
        svnCommand = options.get("svn").lower()
        if options.get("help") is not None:
            outputWriter("%s\n" % usageMessage)
            return(1)
        if svnCommand=="export":
            # from 'path' to 'dir'
            path = options.get("path")
            toDir = options.get("directory")
            if path is None or toDir is None:
                outputWriter("%s\n" % usageMessage)
            else:
                try:
                    outputWriter("Exporting '%s' to '%s'.  Please wait...\n" % (path, toDir))
                    import pysvn
                    client = pysvn.Client()
                    #path = fs.absolutePath(path)
                    #toDir = fs.absolutePath(toDir)
                    result = client.export(path, toDir, force=True, revision=pysvn.Revision(pysvn.opt_revision_kind.head), recurse=True)

                    outputWriter("Exported: %s\n" % str(result))
                    outputWriter("Export completed.\n")
                except Exception, e:
                    outputWriter("Error exporting: %s\n" % str(e))
        else:
            outputWriter("%s\n" % usageMessage)
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#

try:
    from ice_common import IceCommon
    IceCommon.setup()
except:
    import sys, os
    sys.path.append(".") 
    os.chdir("../../")
    from ice_common import IceCommon
# XmlTestCase        # self.assertSameXml


from plugin_tags import *


class MockProperty(object):
    def __init__(self):
        self.guid = 1234
        self.relPath = "relPath/"
 def setUp(self):
     # change the logger printHandler so that it does not print
     try:
         for handler in logger.handlers:
             if handler.__class__.__name__=="printHandler":
                 def emit(record):
                     #print handler.format(record)
                     pass
                 handler.emit = emit
     except: 
         pass
     
     self.output = StringIO()
     iceRender = IceRender(IceCommon)
     if False:   # use mock objects
         self.basePath = "/root/"
         self.svnUrl = "http://testingSvnUrl/"
         self.history = []
         
         self.files = {"/root/.site/site.py":("#data", None)}
         self.mockFs = MockFileSystem(self.files)
         self.mockSvnRep = MockSvnRep(basePath=self.basePath, svnUrl=self.svnUrl, \
                         files=self.files, history=self.history)
         self.iceRep = IceRepository(basePath=self.basePath, repUrl=self.svnUrl, \
                     name="Default", svnRep=self.mockSvnRep, fileSystem=self.mockFs, \
                     output=self.output, iceRender=iceRender)
         self.iceRep.setExecDataMethod(self.dummyMethod)
     else:
         removeTempFSRep()
         createTempFSRep()
         self.svnUrl = tempFSRepUrl
         self.basePath = tempRepPath
         basePath = fs.absolutePath(self.basePath)
         iceContext = IceCommon()
         iceContext.output = self.output
         # use the dummy indexer for testing
         iceContext.RepositoryIndexer = iceContext.DummyRepositoryIndexer  
         svnRep = IceCommon.SvnRep(iceContext, basePath=basePath, svnUrl=self.svnUrl, \
                                 iceLogger=None, output=None)
         self.iceRep = IceRepository(iceContext, basePath=self.basePath, repUrl=self.svnUrl, \
                     name="Default", svnRep=svnRep, fileSystem=fs, output=self.output, \
                     iceRender=MockIceRender(iceContext))
                     #iceRender=iceRender)
         #print "---"
         #print iceRender.getRenderableFrom(".odt")
         #print iceRender.getRenderableTypes(".odt")
         #print iceRender.getRenderableExtensions()
         #print "---"
         self.iceRep2 = None
         #
         #global fs
         #fs = FileSystem(".")
         #
         def wrappedReadFile(path):
             #print "readFile('%s')" % path
             if path.endswith("/.site/site.py"):
                 return "#"
             return readFile(path)
         if fs.readFile!=wrappedReadFile:
             readFile = fs.readFile
             fs.readFile = wrappedReadFile
         #
         def wrappedIsFile(path):
             #print "isFile('%s')" % path
             if path.endswith("/.site/site.py"):
                 return True
             r = isFile(path)
             return r
         if fs.isFile!=wrappedIsFile:
             isFile = fs.isFile
             fs.isFile = wrappedIsFile
     self.xmlContent = "<body>This is some testdata.</body>"
     self.title = "Title"