コード例 #1
0
ファイル: common.py プロジェクト: svanzoest/aksy
 def rename(self, old_path, new_path):
     if LOG.isEnabledFor(logging.DEBUG):
         LOG.debug('rename(%s, %s)', old_path, new_path)
     new_dir = os.path.dirname(new_path)
     if os.path.dirname(old_path) != new_dir:
         file_obj = self.get_file(old_path)
         if hasattr(file_obj, 'save'):
             folder = self.cache[new_dir]
             folder.set_current()
             file_obj.save(False, False)
         elif hasattr(file_obj, 'load'):
             file_obj.load()
         else:
             raiseUnsupportedOperationException() 
         return
             
     new_name = os.path.basename(new_path)
     if fileutils.is_dirpath(old_path):
         folder = self.cache[old_path]
         folder.rename(new_name)
         self.cache[new_path] = folder
         del self.cache[old_path]
     else: 
         file_obj = self.get_file(old_path)
         file_obj.rename(new_name)
コード例 #2
0
ファイル: common.py プロジェクト: svanzoest/aksy
 def getattr(self, path):
     if LOG.isEnabledFor(logging.DEBUG):
         LOG.debug( 'getattr(%s)', path)
     if fileutils.is_dirpath(path):
         return self.stat_directory(path)
     else:
         return self.stat_file(path)
コード例 #3
0
ファイル: ftpd.py プロジェクト: svanzoest/aksy
    def format_list(self, basedir, listing):
        """Return a directory listing emulating "/bin/ls -lgA" UNIX command
        output.

        <basedir> is the absolute dirname, <listing> is a list of files
        contained in that directory.

        For portability reasons permissions, hard links numbers, owners and
        groups listed are static and unreliable but it shouldn't represent a
        problem for most ftp clients around.
        If you want reliable values on unix systems override this method and
        use other attributes provided by os.stat().
        This is how output appears to client:

        -rwxrwxrwx   1 owner    group         7045120 Sep 02  3:47 music.mp3
        drwxrwxrwx   1 owner    group               0 Aug 31 18:50 e-books
        -rwxrwxrwx   1 owner    group             380 Sep 02  3:40 module.py
        """
        result = []
        for basename in listing:
            f = os.path.join(basedir, basename)
            stat = self.getattr(f)

            # stat.st_mtime could fail (-1) if file's last modification time is
            # too old, in that case we return local time as last modification time.
            try:
                mtime = time.strftime("%b %d %H:%M", time.localtime(stat.st_mtime))
            except ValueError:
                mtime = time.strftime("%b %d %H:%M")

            if fileutils.is_dirpath(f):
                result.append("drwxrwxrwx   1 owner    group %15s %s %s\r\n" %(
                    '0', # no size
                    mtime, 
                    basename))
            else:
                result.append("-rw-rw-rw-   1 owner    group %15s %s %s\r\n" %(
                    stat.st_size, 
                    mtime, 
                    basename))
        return ''.join(result)
コード例 #4
0
    def format_list(self, basedir, listing):
        """Return a directory listing emulating "/bin/ls -lgA" UNIX command
        output.

        <basedir> is the absolute dirname, <listing> is a list of files
        contained in that directory.

        For portability reasons permissions, hard links numbers, owners and
        groups listed are static and unreliable but it shouldn't represent a
        problem for most ftp clients around.
        If you want reliable values on unix systems override this method and
        use other attributes provided by os.stat().
        This is how output appears to client:

        -rwxrwxrwx   1 owner    group         7045120 Sep 02  3:47 music.mp3
        drwxrwxrwx   1 owner    group               0 Aug 31 18:50 e-books
        -rwxrwxrwx   1 owner    group             380 Sep 02  3:40 module.py
        """
        result = []
        for basename in listing:
            f = os.path.join(basedir, basename)
            stat = self.getattr(f)

            # stat.st_mtime could fail (-1) if file's last modification time is
            # too old, in that case we return local time as last modification time.
            try:
                mtime = time.strftime("%b %d %H:%M",
                                      time.localtime(stat.st_mtime))
            except ValueError:
                mtime = time.strftime("%b %d %H:%M")

            if fileutils.is_dirpath(f):
                result.append("drwxrwxrwx   1 owner    group %15s %s %s\r\n" %
                              (
                                  '0',  # no size
                                  mtime,
                                  basename))
            else:
                result.append("-rw-rw-rw-   1 owner    group %15s %s %s\r\n" %
                              (stat.st_size, mtime, basename))
        return ''.join(result)
コード例 #5
0
ファイル: ftpd.py プロジェクト: svanzoest/aksy
 def isdir(self, abspath):
     """Return True if path is a directory."""
     return fileutils.is_dirpath(abspath)
コード例 #6
0
ファイル: ftpd.py プロジェクト: svanzoest/aksy
 def isfile(self, abspath):
     """Return True if path is a file."""
     return not fileutils.is_dirpath(abspath)
コード例 #7
0
 def isdir(self, abspath):
     """Return True if path is a directory."""
     return fileutils.is_dirpath(abspath)
コード例 #8
0
 def isfile(self, abspath):
     """Return True if path is a file."""
     return not fileutils.is_dirpath(abspath)
コード例 #9
0
ファイル: test_fileutils.py プロジェクト: svanzoest/aksy
 def test_is_valid_dirpath(self):
     for name in VALID_DIRNAMES:
         self.assertTrue(fileutils.is_dirpath(name), msg='%s should be valid' % name)