コード例 #1
0
    def _getDestinationHandler(self,destinationpath,is_dir=False,recursive=True, tempdir=j.dirs.tmpDir, Atype='copy'):
        """
        Handle all protocol related stuff
        Returns a dict with the src and dst
        """

        dst_proto = self._determineProtocol(destinationpath)
        if(dst_proto == "cifs" or dst_proto == "smb"):
            dst_elements = self._parseCifsURL(destinationpath)
        else:
            dst_elements = urllib.urlparse(destinationpath)
        self.logger.info('PARSING DEST RETURNED %s' %str(dst_elements))

        # Determine the object we need to call
        self.logger.info("_getDestinationHandler: destination protocol [%s]" % (dst_proto))

        if(dst_proto == "cifs" or dst_proto == "smb"):
            dst_fs = CifsFS('dst',server=dst_elements.hostname,share=dst_elements.path,username=dst_elements.username,password=dst_elements.password,is_dir=is_dir,recursive=recursive,tempdir=tempdir, Atype=Atype)
        elif (dst_proto == 'ftp'):
            dst_fs = FtpFS('dst',server=dst_elements.hostname,path=dst_elements.path,username=dst_elements.username,password=dst_elements.password,is_dir=is_dir,recursive=recursive,tempdir=tempdir, Atype=Atype)
        elif (dst_proto == 'file'):
            dst_fs = FileFS('dst',path=dst_elements.path,is_dir=is_dir,recursive=recursive,tempdir=tempdir, Atype=Atype)
        elif (dst_proto == 'http'):
            raise j.exceptions.RuntimeError('http as a destination is not supported')
        elif (dst_proto == 'sftp'):
            dst_fs = SshFS('dst', server=dst_elements.hostname,directory=dst_elements.path,username=dst_elements.username,password=dst_elements.password,is_dir=is_dir,recursive=recursive,tempdir=tempdir, Atype=Atype)
        else:
            q.eventhandler.raiseError('Unsupported protocol [%s] for the destinationpath [%s]'%(dst_proto, destinationpath))
        return dst_fs
コード例 #2
0
    def listDir(self, path):
        """
        List content of specified path
        """
        is_dir = True
        recursive = False

        self.logger.info("listDir: supplied path is [%s]" % path )

        proto = self._determineProtocol(path)
        if(proto == "cifs" or proto == "smb"):
            path_elements = self._parseCifsURL(path)
            self.logger.info('CIFS LISTDIR path_elements: %s' %str(path_elements))
        else:
            path_elements = urllib.urlparse(path)

        # Determine the object we need to call
        self.logger.info("listDir: protocol [%s]" % proto )

        # for the source
        if(proto == "cifs" or proto == "smb"):
            fs = CifsFS('src',server=path_elements.hostname,share=path_elements.path,username=path_elements.username,password=path_elements.password,is_dir=is_dir,recursive=recursive)
        elif (proto == "ftp"):
            fs = FtpFS('src',server=path_elements.hostname,path=path_elements.path,username=path_elements.username,password=path_elements.password,is_dir=is_dir,recursive=recursive)
        elif (proto == 'file'):
            fs = FileFS('src',path=path_elements.path,is_dir=is_dir,recursive=recursive)
        elif (proto == 'sftp'):
            fs = SshFS('src', server=path_elements.hostname,directory=path_elements.path,username=path_elements.username,password=path_elements.password,is_dir=is_dir,recursive=recursive)
        else:
            q.eventhandler.raiseError('Unsupported protocol [%s] for the path [%s]'%(proto, path))

        dir_list = fs.list()
        fs.cleanup()

        return dir_list
コード例 #3
0
    def _getSourceHandler(self, sourcepath, is_dir=False,recursive=True, tempdir=j.dirs.tmpDir, Atype='copy'):
        """
        Handle all protocol related stuff
        Returns a dict with the src and dst
        """

        src_proto = self._determineProtocol(sourcepath)
        if(src_proto == "cifs" or src_proto == "smb"):
            src_elements = self._parseCifsURL(sourcepath)
        else:
            src_elements = urllib.urlparse(sourcepath)

        self.logger.info('PARSING SRC RETURNED %s' %str(src_elements))

        # Determine the object we need to call
        self.logger.info("_getSourceHandler: source protocol [%s]" % (src_proto))

        # for the source
        if(src_proto == "cifs" or src_proto == "smb"):
            src_fs = CifsFS('src',server=src_elements.hostname,share=src_elements.path,username=src_elements.username,password=src_elements.password,is_dir=is_dir,recursive=recursive,tempdir=tempdir, Atype=Atype)
        elif (src_proto == "ftp"):
            src_fs = FtpFS('src',server=src_elements.hostname,path=src_elements.path,username=src_elements.username,password=src_elements.password,is_dir=is_dir,recursive=recursive,tempdir=tempdir, Atype=Atype)
        elif (src_proto == 'file'):
            src_fs = FileFS('src',path=src_elements.path,is_dir=is_dir,recursive=recursive,tempdir=tempdir, Atype=Atype)
        elif (src_proto == 'http'):
            src_fs = HttpFS('src', server=src_elements.netloc,path=src_elements.path,tempdir=tempdir, Atype=Atype)
        elif (src_proto == 'sftp'):
            src_fs = SshFS('src', server=src_elements.hostname,directory=src_elements.path,username=src_elements.username,password=src_elements.password,is_dir=is_dir,recursive=recursive,tempdir=tempdir, Atype=Atype)
        else:
            q.eventhandler.raiseError('Unsupported protocol [%s] for the sourcepath [%s]'%(src_proto, sourcepath))

        return src_fs