def getSourcePaths(self):
     """
     Returns a list of paths pointing to the destination(s). These might be multiple paths when talking
     about a shared cdsl or just one when talking about a hostdependent one. This is the counterpart to
     getDestPaths. Means the source path leads to the destpath.
     @return: a list of paths (relative)
     @rtype: list<string> 
     """
     from comoonics.cdsl import strippath, stripleadingsep
     _paths=list()
     _parent=self.getParent()
     if not _parent:
         _tail=self.src
         _path=self.src
     else:
         _tail=stripleadingsep(strippath(self.src, _parent.src))
         _path=os.path.join(self.cdslRepository.expandCdsl(_parent), _tail)
     if self.isShared():
         for _node in self.getNodenames():
             _paths.append(os.path.join(self.cdsltree, _node, _path))
     elif self.isHostdependent():
         if self.isNested():
             _paths.append(os.path.join(self.cdsltree_shared, _path))
         else:
             _paths.append(self.src)
     return _paths                  
    def findParent(self, path=None):
        """
        This method calls itself recursively on the dirpart of the cdsl until it finds a cdsl in the repo.
        This is returned and the "directest" parent.
        @param path: if path is given the path is taken instead of this cdsl itself.
        @type path: string  
        @return: eReturns the parent CDSL
        @rtype: ComoonicsCdsl
        """
        import os.path
        from comoonics.ComPath import Path
        from comoonics.cdsl import stripleadingsep
        from comoonics.cdsl.ComCdslRepository import CdslNotFoundException
        # getParent is always called from a already stripped cdsl!!
        stripsource=False
        if path == None:
            path=os.path.dirname(self.src)
#        self.logger.debug("getParent(path: %s)" %_path)
        if not path or path.strip() == "" or os.path.normpath(stripleadingsep(os.path.join(self.cdslRepository.root, self.cdslRepository.getMountpoint()))) == path:
            return None
        
        try:
            cwd=Path()
            cwd.pushd(self.cdslRepository.workingdir)
            cdsl=self.cdslRepository.getCdsl(src=path, repository=self.cdslRepository, stripsource=stripsource)
            cwd.popd()
            return cdsl
        except CdslNotFoundException:
            cwd.popd()
            return self.getParent(os.path.dirname(path))  
 def getParent(self, _path=None):
     """
     This method calls itself recursively on the dirpart of the cdsl until it finds a cdsl in the repo.
     This is returned and the "directest" parent.
     @param _path: if path is given the path is taken instead of this cdsl itself.
     @type _path: string  
     @return: eReturns the parent CDSL
     @rtype: ComoonicsCdsl
     """
     import os.path
     from comoonics.ComPath import Path
     from comoonics.cdsl import stripleadingsep
     from comoonics.cdsl.ComCdslRepository import CdslNotFoundException
     if _path == None:
         _path=os.path.dirname(self.src)
     self.logger.debug("getParent(path: %s)" %_path)
     if not _path or _path.strip() == "" or os.path.normpath(stripleadingsep(os.path.join(self.cdslRepository.root, self.cdslRepository.getMountpoint()))) == _path:
         return None
     
     try:
         cwd=Path()
         cwd.pushd(self.cdslRepository.workingdir)
         _cdsl=self.cdslRepository.getCdsl(_path)
         cwd.popd()
         return _cdsl
     except CdslNotFoundException:
         cwd.popd()
         return self.getParent(os.path.dirname(_path))  
    def getParent(self, _path=None):
        """
        This method calls itself recursively on the dirpart of the cdsl until it finds a cdsl in the repo.
        This is returned and the "directest" parent.
        @param _path: if path is given the path is taken instead of this cdsl itself.
        @type _path: string  
        @return: eReturns the parent CDSL
        @rtype: ComoonicsCdsl
        """
        import os.path
        from comoonics.ComPath import Path
        from comoonics.cdsl import stripleadingsep
        from comoonics.cdsl.ComCdslRepository import CdslNotFoundException
        if _path == None:
            _path = os.path.dirname(self.src)
        self.logger.debug("getParent(path: %s)" % _path)
        if not _path or _path.strip() == "" or os.path.normpath(
                stripleadingsep(
                    os.path.join(
                        self.cdslRepository.root,
                        self.cdslRepository.getMountpoint()))) == _path:
            return None

        try:
            cwd = Path()
            cwd.pushd(self.cdslRepository.workingdir)
            _cdsl = self.cdslRepository.getCdsl(_path)
            cwd.popd()
            return _cdsl
        except CdslNotFoundException:
            cwd.popd()
            return self.getParent(os.path.dirname(_path))
 def getSourcePaths(self):
     """
     Returns a list of paths pointing to the destination(s). These might be multiple paths when talking
     about a shared cdsl or just one when talking about a hostdependent one. This is the counterpart to
     getDestPaths. Means the source path leads to the destpath.
     @return: a list of paths (relative)
     @rtype: list<string> 
     """
     from comoonics.cdsl import strippath, stripleadingsep
     _paths = list()
     _parent = self.getParent()
     if not _parent:
         _tail = self.src
         _path = self.src
     else:
         _tail = stripleadingsep(strippath(self.src, _parent.src))
         _path = os.path.join(self.cdslRepository.expandCdsl(_parent),
                              _tail)
     if self.isShared():
         for _node in self.getNodenames():
             _paths.append(os.path.join(self.cdsltree, _node, _path))
     elif self.isHostdependent():
         if self.isNested():
             _paths.append(os.path.join(self.cdsltree_shared, _path))
         else:
             _paths.append(self.src)
     return _paths
 def testMigration(self):
     import comoonics.cdsl.migration
     from comoonics.cdsl.ComCdslRepository import ComoonicsCdslRepository
     from comoonics import XmlTools
     from comoonics.cdsl import stripleadingsep
     fromsource = os.path.join(baseSetup.testpath, "cdsl4.xml")
     cwd = Path()
     cwd.pushd(baseSetup.tmppath)
     repository = comoonics.cdsl.migration.migrate(
         None,
         ComoonicsCdslRepository.version,
         fromresource=fromsource,
         root=baseSetup.tmppath,
         mountpoint="repo8",
         ignoreerrors=True)
     oldelement = XmlTools.parseXMLFile(fromsource)
     wanttocdsls = oldelement.documentElement.getElementsByTagName("cdsl")
     for i in range(len(wanttocdsls)):
         wanttocdsl = wanttocdsls[i]
         src = stripleadingsep(wanttocdsl.getAttribute("src"))
         iscdsl = repository.getCdsl(src)
         self.assertTrue(wanttocdsl.getAttribute("timestamp") == iscdsl.getAttribute("timestamp") and \
                         wanttocdsl.getAttribute("type") == iscdsl.getAttribute("type"), \
                         "Cdsl %s has different timestamp or type after migration" %iscdsl)
     os.remove(
         os.path.join(repository.root, repository.getMountpoint(),
                      repository.resource))
     cwd.popd()
 def testMigration(self):
     import comoonics.cdsl.migration
     from comoonics.cdsl.ComCdslRepository import ComoonicsCdslRepository
     from comoonics import XmlTools
     from comoonics.cdsl import stripleadingsep
     fromsource=os.path.join(baseSetup.testpath, "cdsl4.xml")
     cwd=Path()
     cwd.pushd(baseSetup.tmppath)
     repository=comoonics.cdsl.migration.migrate(None, ComoonicsCdslRepository.version, fromresource=fromsource, root=baseSetup.tmppath, mountpoint="repo8", ignoreerrors=True)
     oldelement=XmlTools.parseXMLFile(fromsource)
     wanttocdsls=oldelement.documentElement.getElementsByTagName("cdsl")
     for i in range(len(wanttocdsls)):
         wanttocdsl=wanttocdsls[i]
         src=stripleadingsep(wanttocdsl.getAttribute("src"))
         iscdsl=repository.getCdsl(src)
         self.assertTrue(wanttocdsl.getAttribute("timestamp") == iscdsl.getAttribute("timestamp") and \
                         wanttocdsl.getAttribute("type") == iscdsl.getAttribute("type"), \
                         "Cdsl %s has different timestamp or type after migration" %iscdsl)
     os.remove(os.path.join(repository.root, repository.getMountpoint(), repository.resource))
     cwd.popd()