当前位置: 首页>>代码示例>>Python>>正文


Python ComSystem.execMethod方法代码示例

本文整理汇总了Python中comoonics.ComSystem.execMethod方法的典型用法代码示例。如果您正苦于以下问题:Python ComSystem.execMethod方法的具体用法?Python ComSystem.execMethod怎么用?Python ComSystem.execMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在comoonics.ComSystem的用法示例。


在下文中一共展示了ComSystem.execMethod方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mount

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
   def mount(self, device, mountpoint):
      """ mount a filesystem
      device: ComDevice.Device
      mountpoint: ComMountPoint.MountPoint
      """

      exclusive=self.getAttribute("exlock", "")
      mkdir=self.getAttributeBoolean("mkdir", True)

      mp=mountpoint.getAttribute("name")
      if not isinstance(self, nfsFileSystem) and not os.path.exists(device.getDevicePath()):
         raise IOError("Devicepath %s does not exist." %device.getDevicePath())
      if not os.path.exists(mp) and mkdir:
         log.debug("Path %s does not exists. I'll create it." % mp)
         ComSystem.execMethod(os.makedirs, mp)

      if exclusive and exclusive != "" and os.path.exists(exclusive):
         raise ComException("lockfile " + exclusive + " exists!")

      cmd = self.mkmountcmd(device, mountpoint)
      rc, ret = ComSystem.execLocalStatusOutput(cmd)
      log.debug("mount:" + cmd + ": " + ret)
      if rc != 0:
         raise ComException(cmd + ret)
      if exclusive:
         fd=open(exclusive, 'w')
         fd.write(device.getDevicePath() + " is mounted ")
开发者ID:MarcGrimme,项目名称:comoonics-cluster-suite,代码行数:29,代码来源:ComFileSystem.py

示例2: mount

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
    def mount(self, device, mountpoint):
        """ mount a filesystem
        device: ComDevice.Device
        mountpoint: ComMountPoint.MountPoint
        """

        __exclusive=self.getAttribute("exlock", "")
        __mkdir=self.getAttributeBoolean("mkdir", True)

        __mp=mountpoint.getAttribute("name")
        if not os.path.exists(__mp) and __mkdir:
            log.debug("Path %s does not exists. I'll create it." % __mp)
            ComSystem.execMethod(os.makedirs, __mp)

        if __exclusive and __exclusive != "" and os.path.exists(__exclusive):
            raise ComException("lockfile " + __exclusive + " exists!")

        __cmd = self.mkmountcmd(device, mountpoint)
        __rc, __ret = ComSystem.execLocalStatusOutput(__cmd)
        log.debug("mount:" + __cmd + ": " + __ret)
        if __rc != 0:
            raise ComException(__cmd + __ret)
        if __exclusive:
            __fd=open(__exclusive, 'w')
            __fd.write(device.getDevicePath() + " is mounted ")
开发者ID:radicke-atix-de,项目名称:comoonics-cluster-suite,代码行数:27,代码来源:ComFileSystem.py

示例3: doPre

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
    def doPre(self):
        """
        Unpacks the given file to dest
        """
        srcfile=self.getAttribute("name")
        destfile=self.getAttribute("dest")
        __mkdir=self.getAttributeBoolean("mkdir", default=True)

        if not ComSystem.execMethod(os.path.exists, destfile) and __mkdir:
            ComLog.getLogger(ArchiveRequirement.__logStrLevel__).debug("Path %s does not exists. I'll create it." % destfile)
            os.makedirs(destfile)

        if self.check() and not ComSystem.isSimulate():
            if not os.access(srcfile, os.R_OK) or not os.access(destfile, os.F_OK) or not os.access(destfile, os.W_OK):
                raise ArchiveRequirementException("Either srcfile %s is not readable or dest %s is not writeable" % (srcfile, destfile))

        __cmd="rm -rf %s/*" % destfile
        (rc, rv) = ComSystem.execLocalGetResult(__cmd)
        if rc >> 8 != 0:
            raise RuntimeError("running \"%s\" failed: %u, %s" % (__cmd, rc,rv))

        self.olddir=os.curdir
        ComSystem.execMethod(os.chdir, destfile)
        __cmd="gzip -cd %s | cpio -i" % srcfile
        (rc, rv, stderr) = ComSystem.execLocalGetResult(__cmd, True)
        if rc >> 8 != 0:
            raise RuntimeError("running \"%s\" failed: %u, %s, %s" % (__cmd, rc,rv, stderr))
开发者ID:MarcGrimme,项目名称:comoonics-cluster-suite,代码行数:29,代码来源:ComArchiveRequirement.py

示例4: __prepare

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
 def __prepare(self):
     import os
     self.origpath=self.path.getPath()
     ComSystem.execMethod(self.path.mkdir)
     ComSystem.execMethod(self.path.pushd, self.path.getPath())
     if not ComSystem.isSimulate():
         self.journal(self.path, "pushd")
     PathCopyObject.logger.debug("prepareAsSource() CWD: " + os.getcwd())
开发者ID:MarcGrimme,项目名称:comoonics-cluster-suite,代码行数:10,代码来源:ComPathCopyObject.py

示例5: doPost

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
    def doPost(self):
        """
        Does something afterwards
        """
        srcfile=self.getAttribute("name")
        destfile=self.getAttribute("dest")

        if self.check() and not ComSystem.isSimulate():
            if not os.access(srcfile, os.R_OK) or not os.access(destfile, os.F_OK) or not os.access(destfile, os.W_OK):
                raise ArchiveRequirementException("Either srcfile %s is not readable or dest %s is not writeable" % (srcfile, destfile))
        ComSystem.execMethod(os.chdir, destfile)
        __cmd="cp %s %s" %(srcfile, srcfile+self.getAttribute("bak_suffix", ".bak"))
        try:
            (rc, rv, stderr) = ComSystem.execLocalGetResult(__cmd, True)
            if rc >> 8 != 0:
                raise RuntimeError("running \"%s\" failed: %u, %s, errors: %s" % (__cmd, rc,rv, stderr))
        except RuntimeError, re:
            ComLog.getLogger(ArchiveRequirement.__logStrLevel__).warn("Cannot backup sourcefile %s=%s, %s." %(srcfile, srcfile+".bak", re))
开发者ID:MarcGrimme,项目名称:comoonics-cluster-suite,代码行数:20,代码来源:ComArchiveRequirement.py

示例6: _removePath

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
 def _removePath(self,path,onerror=None):
     """
     Removes given path or paths.
     @param path: Path to file or directory to delete
     @type path: string|list<string>
     """
     if isinstance(path, basestring):
         if os.path.exists(path) or os.path.islink(path):
             self.logger.debug("Remove " + path)
             if not os.path.islink(path) and os.path.isdir(path):
                 ComSystem.execMethod(shutil.rmtree, path)
             else:
                 ComSystem.execMethod(os.remove, path)
         else:
             if onerror:
                 onerror(path)
             else:
                 self.logger.debug("_removePath(%s) does not exist. Skipping." %path)
     else:
         for _path in path:
             self._removePath(_path)
开发者ID:radicke-atix-de,项目名称:comoonics-cluster-suite,代码行数:23,代码来源:ComCdsl.py

示例7: prepareAsDest

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
 def prepareAsDest(self):
     """ writes all metadata to archive"""
     self.log.debug("prepareAsDest()")
     ComSystem.execMethod(self.serializer.serialize, self.metadata)
开发者ID:radicke-atix-de,项目名称:comoonics-cluster-suite,代码行数:6,代码来源:ComArchiveCopyObject.py

示例8: exists

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
 def exists(self):
    return ComSystem.execMethod(os.path.exists, self.getDeviceName())
开发者ID:MarcGrimme,项目名称:comoonics-cluster-suite,代码行数:4,代码来源:ComDisk.py

示例9: delete

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]

#.........这里部分代码省略.........
            for cdsl in _tmp:
                cdsl.delete(recursive=recursive, force=force, symbolic=symbolic)
        
        if self.getChilds():
            raise CdslHasChildren("Cdsl %s has children but no recursive option specified." %self.src)
        _cwd=Path()
        _cwd.pushd(self.getBasePath())
        
        #delete or move cdsl from filesystem first is from second to if second=None it is removed
        _delpaths=list()
        _movepairs=dict()
        _delpaths2=list()
        for _path in self.getSourcePaths():
            # This one is always a link to be removed
            if os.path.lexists(_path):
                _delpaths.append(_path)

        for _path in self.getDestPaths():
            if not symbolic:
                _delpaths.append(_path)
            else:            
                self.logger.debug(".delete(%s): Skipping path %s" %(self.src, _path))
                if self.isShared():
                    _movepairs[_path]=self.src
                else:
                    _nodeid=getNodeFromPath(_path, self.cdslRepository, not force)
                    _movepairs[_path]="%s.%s" %(self.src, _nodeid)
#                _delpaths[_path]=self.
                
        # tidy up the rest
        # Means:
        # * if we have siblings: clean up to longest common path with all siblings
        prefixes=list()
        if self.isHostdependent():
            for nodename in self.getNodenames():
                prefixes.append(os.path.join(self.cdslRepository.getTreePath(), nodename))
        elif self.isShared():
            prefixes.append(self.cdslRepository.getSharedTreepath())
        
        # Let's find our parent of same type
#        parent2nd=None
#        if self.getParent()!=None and self.getParent().getParent() != None:
#            parent2nd=self.getParent().getParent()        parent2nd=None
        parent=self.getParent()
            
        subpaths=list()
        siblings=self.getSiblings()
        if len(siblings) > 0:
            longestcommon=""
            for sibling in siblings:
                common=commonpath(self.src, sibling.src)
#                while common and common != longestcommon:
                if isSubPath(common, longestcommon):
                    longestcommon=common
            for _path in subpathsto(longestcommon, self.src):
                subpaths.append(_path)
        # * if we have a parent of same type and no siblings:  clean up to parent
#        elif parent2nd != None:
#            for _path in subpathsto(parent2nd.src, self.src):
#                subpaths.append(_path)
        # * if we don't have a parent and no siblings:  clean up to root+mountpoint
        # * if we have a parent of same type and no siblings:  clean up to parent
        elif parent != None and parent.getParent() != None:
            for _path in subpathsto(parent.src, self.src):
                subpaths.append(_path)
        else:
            for _path in subpathsto("", self.src):
                subpaths.append(_path)
                
        for path in subpaths:
            if str(path) != str(self.src):
                for prefix in prefixes:
                    if os.path.lexists(os.path.join(prefix, path)):
                        _delpaths2.append(os.path.join(prefix, path))
            
        self.logger.debug("delpaths2: %s" %_delpaths2)
                        
        self.logger.debug("delete: cwd: %s" %_cwd)
        self._removePath(_delpaths)
        for _from, _to in _movepairs.items():
            if not _to:
                self._removePath(_from)
            else:
#                for _delpath in _delpaths:
#                    if os.path.samefile(_delpath, _to):
#                        _delpaths.remove(_delpath)
                if os.path.islink(_to):
                    self._removePath(_to)
                shutil.move(_from, _to)
                # We must remove paths from the delpaths that have been moved to as they are
#                for _delpath in _delpaths:
#                    if os.path.samefile(_to, _delpath):
#                        _delpaths.remove(_delpath)
        self._removePath(_delpaths2)
        _deleted=ComSystem.execMethod(self.cdslRepository.delete, self)
        _cwd.popd()
        self.logger.debug("Delete CDSL from Inventoryfile")
        #delete cdsl also from xml inventory file
        #self.cdslRepository.delete(self)
        return _deleted
开发者ID:radicke-atix-de,项目名称:comoonics-cluster-suite,代码行数:104,代码来源:ComCdsl.py

示例10: commit

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
    def commit(self,force=False):
        """
        Commit new or changed cdsl to filesystem and inventoryfile
        @param force: skip Backup when set and overwrite existing files/directories/links
        @type force: Boolean
        """
        from comoonics.ComPath import Path
        from comoonics.cdsl import isSubPath
        #important pathes to work with cdsls
        #####
        # Chancel creation of cdsl if it already exists
        # or a cdsl of another type with same src exists
        # or creation is insane because underlying structure 
        # is of same type as cdsl which should be created
        #####       
        if self.exists():
            self.logger.debug("CDSL already exists, chancel commit")
            raise CdslAlreadyExists("Cdsl %s is already existant." %self.src)
        if self.isShared() and (self.getParent() == None or self.getParent().isShared()):
            self.logger.debug("The cdsl %s to be shared back seems to recide already in a shared area." %self.src)
            raise CdslOfSameType("The cdsl %s to be shared seems to recide already in a shared area." %self.src)
        if self.isHostdependent() and self.getParent() != None and self.getParent().isHostdependent():
            self.logger.debug("The cdsl %s to be hostdependent seems to recide alreay in an hostdependent area." %self.src)
            raise CdslOfSameType("The cdsl %s to be hostdependent seems to recide alreay in an hostdependent area." %self.src)
        elif self.isShared():
            if isSubPath(self.src, self.cdsltree_shared):
                self.logger.debug("Given source is already part of a hostdependent CDSL")
                raise CdslAlreadyExists("Cdsl %s is already a hostdependent cdsl." %self.src)
        elif self.isHostdependent():
            if isSubPath(self.src, self.getCDSLLinkPath()):
                self.logger.debug("Given source is already part of a hostdependent CDSL")
                raise CdslAlreadyExists("Cdsl %s is already a shared cdsl." %self.src)

        _path=Path()
        _path.pushd(self.getBasePath())
        if not os.path.exists(self.src):
            raise CdslDoesNotExistException("File %s for cdsl does not exist (cwd: %s). Cannot create." %(self.src, self.getBasePath()))
        self.cdslRepository.updateInfrastructure(nodes=self.getNodenames())
                
#        _expanded=self.cdslRepository.expandCdsl(self)
#        parent=self.getParent()
#        if parent:
#            _tail=strippath(self.src, parent.src)
#            _expandedforparent=os.path.join(parent.cdslRepository.expandCdsl(parent), _tail)
#        else:
#            _expandedforparent=_expanded
        _depth = self._pathdepth(self.src) -1
        if _depth > 0:
            if self.isShared():
                _depth=_depth+self._pathdepth(self.cdsltree)+1 # 1 because we need to add the node
            elif self.isHostdependent() and self.getParent() != None:
                _depth=_depth+self._pathdepth(self.cdsltree_shared)
            _relativepath = _depth * "../"
        else:
            _relativepath = ""
        
        # First copy or move the files to the destpaths...
        for destpath in self.getDestPaths():
            
            # Create the parentdir if it does not already exist
            parentdir=os.path.dirname(destpath)
            if not os.path.exists(parentdir):
                self.logger.debug("Create Directory " + parentdir)
                os.makedirs(parentdir)
            
            # if symlink and relative adapt to the relativness.
            if os.path.islink(self.src) and not self.src.startswith(os.sep):
                self.logger.debug("Creating link from %s => %s" %(os.path.join(_relativepath, self.src), destpath))
                ComSystem.execMethod(os.symlink, os.path.join(self._pathdepth(self.getCDSLLinkPath())*"../", os.path.realpath(self.src)[1:]), destpath)
            else:
                # Let's copy the data
                self.logger.debug("Copy Files: " + self.src + " => " + destpath)
                ComSystem.execLocalStatusOutput("cp -a " + self.src + " " + destpath)
            # if cdsl is shared we need to copy only once.
            if self.isShared():
                break

        # createdefault destination
#        if self.isHostdependent():
#            self.logger.debug("Copy Files: " + self.src + " => " + os.path.join(self.cdslRepository.getTree(), self.cdslRepository.getDefaultPath()))
#            ComSystem.execLocalStatusOutput("cp -a " + self.src + " " + self.cdslRepository.getDefaultPath())

        if self.isHostdependent():
            if force:
                self.logger.debug("Removing oldfile %s" %self.src)
                ComSystem.execLocalStatusOutput("rm -rf %s" %self.src)
            elif not force:
                self.logger.debug("Moving %s => %s.orig" %(self.src, self.src))
                ComSystem.execLocalStatusOutput("mv %s %s.orig" %(self.src, self.src))
        
        # Now create the symlinks
        for sourcepath in self.getSourcePaths():
            if self.isShared():
                # Either backup or remove!
                if not force:
                    self.logger.debug("Backup Files: " + sourcepath + " => " + sourcepath + ".orig")
                    ComSystem.execLocalStatusOutput("mv " + sourcepath + " " + sourcepath + ".orig")
                else:
                    self.logger.debug("Remove Files: " + sourcepath)
                    if os.path.isdir(sourcepath):
#.........这里部分代码省略.........
开发者ID:radicke-atix-de,项目名称:comoonics-cluster-suite,代码行数:103,代码来源:ComCdsl.py

示例11: testExecMethodErrSim

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
 def testExecMethodErrSim(self):
     ComSystem.setExecMode(ComSystem.SIMULATE)
     result = ComSystem.execMethod(ComSystem.execLocalGetResult, self.cmd1, True)
     self.assertEquals(result, True)
开发者ID:radicke-atix-de,项目名称:comoonics-cluster-suite,代码行数:6,代码来源:testComSystem.py

示例12: testExecMethodErr

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
 def testExecMethodErr(self):
     ComSystem.setExecMode(None)
     result = ComSystem.execMethod(ComSystem.execLocalGetResult, self.cmd1, True)
     self.assertEquals(result, self.cmd1_result[3])
开发者ID:radicke-atix-de,项目名称:comoonics-cluster-suite,代码行数:6,代码来源:testComSystem.py

示例13: doModifications

# 需要导入模块: from comoonics import ComSystem [as 别名]
# 或者: from comoonics.ComSystem import execMethod [as 别名]
 def doModifications(self, file):
     save=True
     if self.hasAttribute("nobackup"):
         if self.getAttribute("nobackup") == "1":
             save=False
     ComSystem.execMethod(self.doRegexpModifications, file, save)
开发者ID:Open-Sharedroot,项目名称:Open-Sharedroot-cluster-suite,代码行数:8,代码来源:ComRegexpModification.py


注:本文中的comoonics.ComSystem.execMethod方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。