Exemple #1
0
    def isDir(self):
        """
        Attempts to determine whether the dir exists or not:
          Get the list of the parent dir.
          If the dirname is in parent dir and 'd' starts permissions.
        """
        try:
            ftp = FtpUtils.getFtpConnection(self)
            urlPath = self.split()['urlPath']
            # there has to be a '' path if we found the server.
            if urlPath == '':
                ftp.close()
                return True

            if urlPath.endswith('/'):
                urlPath.pop()

            parentDir = ''
            dirName = urlPath
            if '/' in urlPath:
                (parentDir, dirName) = urlPath.rsplit('/', 1)
            d = FtpUtils.getDirList(ftp, parentDir)
            ftp.quit()
            if dirName in d:
                if d[dirName]['permissions'].startswith('d'):
                    return True
            return False
        except Exception, e:
            try:
                FtpUtils.handleException(e, self)
            except ufsi.PathNotFoundError, e:
                return False
Exemple #2
0
    def isDir(self):
        """
        Attempts to determine whether the dir exists or not:
          Get the list of the parent dir.
          If the dirname is in parent dir and 'd' starts permissions.
        """
        try:
            ftp=FtpUtils.getFtpConnection(self)
            urlPath=self.split()['urlPath']
            # there has to be a '' path if we found the server.
            if urlPath=='':
                ftp.close()
                return True

            if urlPath.endswith('/'):
                urlPath.pop()

            parentDir=''
            dirName=urlPath
            if '/' in urlPath:
                (parentDir,dirName)=urlPath.rsplit('/',1)
            d=FtpUtils.getDirList(ftp,parentDir)
            ftp.quit()
            if dirName in d:
                if d[dirName]['permissions'].startswith('d'):
                    return True
            return False
        except  Exception,e:
            try:
                FtpUtils.handleException(e,self)
            except ufsi.PathNotFoundError,e:
                return False
Exemple #3
0
 def getDirList(self,filter=None,sort=None):
     """
     Returns a list of strings, the name of each dir or file in
     this directory.
     """
     try:
         ftp=FtpUtils.getFtpConnection(self.__path)
         d=FtpUtils.getDirList(ftp,self.__path.split()['urlPath'])
     except Exception,e:
         FtpUtils.handleException(e,self.__pathStr)
Exemple #4
0
    def getStat(self):
        """
        Returns a dict of information about this file.

        Expects the path to NOT end in a '/'.
        """
        try:
            s = self.__path.split()
            ftp = FtpUtils.getFtpConnection(self.__path)
            dl = FtpUtils.getDirList(ftp, s['urlPath'])
            ftp.quit()
            if not dl:
                raise ufsi.PathNotFoundError(
                    'Path "%s" not found.' % self.__path, e)
            return dl[s['fileName']]
        except Exception, e:
            FtpUtils.handleException(e, self.__pathStr)
Exemple #5
0
    def getStat(self):
        """
        Returns a dict of information about this file.

        Expects the path to NOT end in a '/'.
        """
        try:
            s=self.__path.split()
            ftp=FtpUtils.getFtpConnection(self.__path)
            dl=FtpUtils.getDirList(ftp,s['urlPath'])
            ftp.quit()
            if not dl:
                raise ufsi.PathNotFoundError('Path "%s" not found.'
                                             %self.__path,e)
            return dl[s['fileName']]
        except Exception,e:
            FtpUtils.handleException(e,self.__pathStr)
Exemple #6
0
    def getStat(self):
        """
        Returns a dict of information about this directory. Common
        values are:

        * size - size of the file system (as a string - may contain
          commas). TODO: remove commas from size.
        * permissions - a unix permissions string like: '-rwxrwxrwx'
        * owner - the owner of the file
        * group - the group of the file
          
        """
        try:
            # We must find the dir name in it's parent directory
            s=self.__path.split()
            urlPath=s['urlPath']
            if urlPath.endswith('/'):
                urlPath.pop()
            # Currently can't get any details from the root dir
            if urlPath=='':
                return {}

            # get parent dir (even if it's empty)
            parentDir=''
            dirName=urlPath
            if '/' in urlPath:
                (parentDir,dirName)=urlPath.rsplit('/',1)
                # cater for a urlPath of /dir
                parentDir+='/'

            ftp=FtpUtils.getFtpConnection(self.__path)
            
            dirList=FtpUtils.getDirList(ftp,parentDir)
            if dirName not in dirList:
                raise ufsi.PathNotFoundError('Path "%s" not found.'
                                             %self.__path)
            return dirList[dirName]
        except Exception,e:
            FtpUtils.handleException(e,self.__pathStr)
Exemple #7
0
 def isFile(self):
     """
     Attempts to determine whether the file exists or not:
       Get the list of the parent dir.
       If the filename is in the parent dir and '-' starts the
       permissions.
     
     This is simpler than isDir because we can list a file its
     self, and get the details from that.
     
     TODO: Exception: If filename is a dir and also has a filename
     file within it.
     
     """
     try:
         ftp = FtpUtils.getFtpConnection(self)
         d = FtpUtils.getDirList(ftp, self.split()['urlPath'])
         ftp.quit()
     except Exception, e:
         try:
             FtpUtils.handleException(e, self)
         except ufsi.PathNotFoundError, e:
             ftp.quit()
             return False
Exemple #8
0
 def isFile(self):
     """
     Attempts to determine whether the file exists or not:
       Get the list of the parent dir.
       If the filename is in the parent dir and '-' starts the
       permissions.
     
     This is simpler than isDir because we can list a file its
     self, and get the details from that.
     
     TODO: Exception: If filename is a dir and also has a filename
     file within it.
     
     """
     try:
         ftp=FtpUtils.getFtpConnection(self)
         d=FtpUtils.getDirList(ftp,self.split()['urlPath'])
         ftp.quit()
     except Exception,e:
         try:
             FtpUtils.handleException(e,self)
         except ufsi.PathNotFoundError,e:
             ftp.quit()
             return False