Esempio n. 1
0
    def stat(self, path):
        if not isinstance(path, unicode):
            path = path.decode(self.encoding)

        info = self.fs.getinfo(path)

        stat = paramiko.SFTPAttributes()
        stat.filename = basename(path).encode(self.encoding)
        stat.st_size = info.get("size")

        if 'st_atime' in info:
            stat.st_atime = info.get('st_atime')
        elif 'accessed_time' in info:
            stat.st_atime = time.mktime(info.get("accessed_time").timetuple())

        if 'st_mtime' in info:
            stat.st_mtime = info.get('st_mtime')
        else:
            if 'modified_time' in info:
                stat.st_mtime = time.mktime(info.get("modified_time").timetuple())

        if isdir(self.fs, path, info):
            stat.st_mode = 0777 | statinfo.S_IFDIR
        else:
            stat.st_mode = 0777 | statinfo.S_IFREG
        return stat
Esempio n. 2
0
    def stat(self, path):
        if not isinstance(path, unicode):
            path = path.decode(self.encoding)

        info = self.fs.getinfo(path)
        get = info.get

        stat = paramiko.SFTPAttributes()
        stat.filename = basename(path).encode(self.encoding)
        stat.st_size = info.get("size")

        if 'st_atime' in info:
            stat.st_atime = get('st_atime')
        elif 'accessed_time' in info:
            stat.st_atime = time.mktime(get("accessed_time").timetuple())

        if 'st_mtime' in info:
            stat.st_mtime = get('st_mtime')
        else:
            if 'modified_time' in info:
                stat.st_mtime = time.mktime(get("modified_time").timetuple())

        if isdir(self.fs, path, info):
            stat.st_mode = 0777 | statinfo.S_IFDIR
        else:
            stat.st_mode = 0777 | statinfo.S_IFREG
        return stat
Esempio n. 3
0
    def listdirinfo(self,
                    path="./",
                    wildcard=None,
                    full=False,
                    absolute=False,
                    dirs_only=False,
                    files_only=False):
        npath = self._normpath(path)
        try:
            attrs = self.client.listdir_attr(npath)
            attrs_map = dict((a.filename, a) for a in attrs)
            paths = list(attrs_map.keys())
        except IOError as e:
            if getattr(e, "errno", None) == ENOENT:
                if self.isfile(path):
                    raise ResourceInvalidError(
                        path,
                        msg="Can't list directory contents of a file: %(path)s"
                    )
                raise ResourceNotFoundError(path)
            elif self.isfile(path):
                raise ResourceInvalidError(
                    path,
                    msg="Can't list directory contents of a file: %(path)s")
            raise

        if dirs_only:
            filter_paths = []
            for path, attr in attrs_map.items():
                if isdir(self, path, attr.__dict__):
                    filter_paths.append(path)
            paths = filter_paths
        elif files_only:
            filter_paths = []
            for path, attr in attrs_map.items():
                if isfile(self, path, attr.__dict__):
                    filter_paths.append(path)
            paths = filter_paths

        for (i, p) in enumerate(paths):
            if not isinstance(p, str):
                paths[i] = p.decode(self.encoding)

        def getinfo(p):
            resourcename = basename(p)
            info = attrs_map.get(resourcename)
            if info is None:
                return self.getinfo(pathjoin(path, p))
            return self._extract_info(info.__dict__)

        return [(p, getinfo(p)) for p in self._listdir_helper(
            path, paths, wildcard, full, absolute, False, False)]
Esempio n. 4
0
 def command_ls(self, params):
     if '-l' in params:
         self.writeline('total ' + str(self.total_file_size))  # report a fake random file size
         file_names = self.vfs.listdir(self.working_dir)
         for fname in file_names:
             abspath = self.vfs.getsyspath(self.working_dir + '/' + fname)
             self.writeline(path_to_ls(abspath))
     else:
         listing = []
         for item in self.vfs.listdir(self.working_dir):
             if isdir(self.vfs, os.path.join(self.working_dir, item)):
                 item += '/'  # Append a slash at the end of directory names
             listing.append(item)
         self.writeline(' '.join(listing))
Esempio n. 5
0
 def command_ls(self, params):
     if '-l' in params:
         self.writeline(
             'total ' +
             str(self.total_file_size))  # report a fake random file size
         file_names = self.vfs.listdir(self.working_dir)
         for fname in file_names:
             abspath = self.vfs.getsyspath(self.working_dir + '/' + fname)
             self.writeline(path_to_ls(abspath))
     else:
         listing = []
         for item in self.vfs.listdir(self.working_dir):
             if isdir(self.vfs, os.path.join(self.working_dir, item)):
                 item += '/'  # Append a slash at the end of directory names
             listing.append(item)
         self.writeline(' '.join(listing))
Esempio n. 6
0
            else:
                paths = self.client.listdir(npath)
        except IOError, e:
            if getattr(e,"errno",None) == ENOENT:
                if self.isfile(path):
                    raise ResourceInvalidError(path,msg="Can't list directory contents of a file: %(path)s")
                raise ResourceNotFoundError(path)
            elif self.isfile(path):
                raise ResourceInvalidError(path,msg="Can't list directory contents of a file: %(path)s")
            raise

        if attrs_map:
            if dirs_only:
                filter_paths = []
                for apath, attr in attrs_map.iteritems():
                    if isdir(self, path, attr.__dict__):
                        filter_paths.append(apath)
                paths = filter_paths
            elif files_only:
                filter_paths = []
                for apath, attr in attrs_map.iteritems():
                    if isfile(self, apath, attr.__dict__):
                        filter_paths.append(apath)
                paths = filter_paths

        for (i,p) in enumerate(paths):
            if not isinstance(p,unicode):
                paths[i] = p.decode(self.encoding)

        return self._listdir_helper(path, paths, wildcard, full, absolute, False, False)