示例#1
0
 def check_entry(entries, filename):
     t = get_transport('.')
     stat = t.stat(urlutils.escape('%s/%s' % (parent_dir, filename)))
     named_entries = [
         entry for entry in entries if entry[0] == filename]
     self.assertEqual(1, len(named_entries))
     name, longname, attrs = named_entries[0]
     self.assertEqual(lsLine(name, stat), longname)
     self.assertEqual(self.sftp_server._translate_stat(stat), attrs)
示例#2
0
 def check_entry(entries, filename):
     t = get_transport('.')
     stat = t.stat(urlutils.escape('%s/%s' % (parent_dir, filename)))
     named_entries = [
         entry for entry in entries if entry[0] == filename]
     self.assertEqual(1, len(named_entries))
     name, longname, attrs = named_entries[0]
     self.assertEqual(lsLine(name, stat), longname)
     self.assertEqual(self.sftp_server._translate_stat(stat), attrs)
示例#3
0
 def __next__(self):
     try:
         f = self.files.pop(0)
     except IndexError:
         raise StopIteration
     else:
         s = self.server.avatar._runAsUser(os.lstat, os.path.join(self.dir, f))
         longname = lsLine(f, s)
         attrs = self.server._getAttrs(s)
         return (f, longname, attrs)
示例#4
0
 def _lsInTimezone(self, timezone, stat):
     """
     Call L{ls.lsLine} after setting the timezone to C{timezone} and return
     the result.
     """
     # Set the timezone to a well-known value so the timestamps are
     # predictable.
     os.environ['TZ'] = timezone
     time.tzset()
     return ls.lsLine('foo', stat)
 def next(self):
     try:
         f = self.files.pop(0)
     except IndexError:
         raise StopIteration
     else:
         s = self.server.avatar._runAsUser(os.lstat, os.path.join(self.dir, f))
         longname = lsLine(f, s)
         attrs = self.server._getAttrs(s)
         return (f, longname, attrs)
示例#6
0
 def _lsInTimezone(self, timezone, stat):
     """
     Call L{ls.lsLine} after setting the timezone to C{timezone} and return
     the result.
     """
     # Set the timezone to a well-known value so the timestamps are
     # predictable.
     os.environ['TZ'] = timezone
     time.tzset()
     return ls.lsLine('foo', stat)
示例#7
0
文件: essftp.py 项目: optionalg/ess
 def next(self):
     # TODO: problem - what if the user that logs in is not a user in the
     # system?
     if not self.files:
         raise StopIteration
     f = self.files.pop(0)
     followLink = False
     if not self.server._islink(f):
         #prevents fake directories and files from showing up as links
         followLink = True
     f.restat(followLink=followLink)
     longname = lsLine(f.basename(), f.statinfo)
     longname = longname[:15] + longname[32:]  # remove uid and gid
     return (f.basename(), longname, _simplifyAttributes(f))
示例#8
0
 def list_directory(self, path):
     assert path.startswith('/')
     if path == '/':
         searches = self.search_request.get_searches()
         for (name, ) in searches:
             name = name.encode('utf-8')
             s = self.stat('/%s' % name)
             yield (name, lsLine(name, s), self.attrs_from_stat(s))
     else:
         virtpath = self.split_virtual_path(path)
         for filepath, rset_file in self.dir_content(virtpath):
             if not rset_file:
                 s = self.stat(filepath, path_is_real=True)
             else:
                 # retrieve rset binary from database
                 rset = self.search_request.get_file_data(
                     file_eid=None,
                     rset_file=True,
                     search_name=virtpath.search_name)
                 s = self.stat_file_entity(rset.len)
             basename = osp.basename(filepath).encode('utf-8')
             longname = lsLine(basename, s)
             yield (basename, longname, self.attrs_from_stat(s))
示例#9
0
文件: essftp.py 项目: alex/ess
 def next(self):
     # TODO: problem - what if the user that logs in is not a user in the
     # system?
     if not self.files:
         raise StopIteration
     f = self.files.pop(0)
     followLink = False
     if not self.server._islink(f):
         #prevents fake directories and files from showing up as links
         followLink = True
     f.restat(followLink=followLink)
     longname = lsLine(f.basename(), f.statinfo)
     longname = longname[:15] + longname[32:]  # remove uid and gid
     return (f.basename(), longname, _simplifyAttributes(f))
示例#10
0
文件: sftp.py 项目: swift1911/twisted
            def next(self):

                (name, attrs) = self.iter.next()

                class st:
                    pass

                s = st()
                s.st_mode = attrs["permissions"]
                s.st_uid = attrs["uid"]
                s.st_gid = attrs["gid"]
                s.st_size = attrs["size"]
                s.st_mtime = attrs["mtime"]
                s.st_nlink = attrs["nlink"]
                return (name, lsLine(name, s), attrs)
示例#11
0
文件: sftp.py 项目: Almad/twisted
            def next(self):

                (name, attrs) = self.iter.next()

                class st:
                    pass

                s = st()
                s.st_mode   = attrs["permissions"]
                s.st_uid    = attrs["uid"]
                s.st_gid    = attrs["gid"]
                s.st_size   = attrs["size"]
                s.st_mtime  = attrs["mtime"]
                s.st_nlink  = attrs["nlink"]
                return ( name, lsLine(name, s), attrs )
示例#12
0
 def next(self):
     try:
         name, f = self.files.popitem(last=False)
         lstat = swift_stat(**f)
         longname = ls.lsLine(name, lstat)
         return (name, longname, {
             "size": lstat.st_size,
             "uid": lstat.st_uid,
             "gid": lstat.st_gid,
             "permissions": lstat.st_mode,
             "atime": int(lstat.st_atime),
             "mtime": int(lstat.st_mtime)
         })
     except KeyError:
         raise StopIteration
示例#13
0
 def next(self):
     try:
         name, f = self.files.popitem(last=False)
         lstat = swift_stat(**f)
         longname = ls.lsLine(name, lstat)
         return (name, longname, {
             "size": lstat.st_size,
             "uid": lstat.st_uid,
             "gid": lstat.st_gid,
             "permissions": lstat.st_mode,
             "atime": int(lstat.st_atime),
             "mtime": int(lstat.st_mtime)
         })
     except KeyError:
         raise StopIteration
 def list_directory(self, path):
     assert path.startswith('/')
     if path == '/':
         searches = self.search_request.get_searches()
         for (name,) in searches:
             name = name.encode('utf-8')
             s = self.stat('/%s' % name)
             yield (name,
                    lsLine(name, s),
                    self.attrs_from_stat(s))
     else:
         virtpath = self.split_virtual_path(path)
         for filepath, rset_file in self.dir_content(virtpath):
             if not rset_file:
                 s = self.stat(filepath, path_is_real=True)
             else:
                 # retrieve rset binary from database
                 rset = self.search_request.get_file_data(file_eid=None,
                                                          rset_file=True,
                                                          search_name=virtpath.search_name)
                 s = self.stat_file_entity(rset.len)
             basename = osp.basename(filepath).encode('utf-8')
             longname = lsLine(basename, s)
             yield (basename, longname, self.attrs_from_stat(s))
示例#15
0
    def next(self):
        (name, attrs) = self.iter.next()

        class st:
            pass

        s = st()
        attrs['permissions'] = s.st_mode = attrs.get('permissions', 040755)
        attrs['uid'] = s.st_uid = attrs.get('uid', 0)
        attrs['gid'] = s.st_gid = attrs.get('gid', DEFAULT_GID)
        attrs['size'] = s.st_size = attrs.get('size', 0)
        attrs['atime'] = s.st_atime = float(attrs.get('atime',
                                            self.env.startup_time))
        attrs['mtime'] = s.st_mtime = float(attrs.get('mtime',
                                            self.env.startup_time))
        attrs['nlink'] = s.st_nlink = 1
        return (name, lsLine(name, s), attrs)
示例#16
0
    def _format_directory_entries(self, stat_results, filenames):
        """Produce entries suitable for returning from `openDirectory`.

        :param stat_results: A list of the results of calling `stat` on each
            file in filenames.
        :param filenames: The list of filenames to produce entries for.
        :return: An iterator of ``(shortname, longname, attributes)``.
        """
        for stat_result, filename in zip(stat_results, filenames):
            shortname = urlutils.unescape(filename).encode('utf-8')
            stat_result = copy(stat_result)
            for attribute in ['st_uid', 'st_gid', 'st_mtime', 'st_nlink']:
                if getattr(stat_result, attribute, None) is None:
                    setattr(stat_result, attribute, 0)
            longname = lsLine(shortname, stat_result)
            attr_dict = self._translate_stat(stat_result)
            yield (shortname, longname, attr_dict)
示例#17
0
    def list_directory(self, path):
        """ Method to list a virtual folder.

        Virtual folders have a common root organization:

        ::

            instance name
                |
                ---- CWSearch name
                            |
                            ---- ...

        Parameters
        ----------
        path: string (mandatory)
            the virtual path we want to access.

        Returns
        -------
        out: iterator
            an iterator containing virtual folder description. Each iterator
            item is a 3-uplet of the form (basename, longname, stat).
        """
        # Create/update an association between cw rset and db name
        self.rset_map = dict((key.lstrip("/"), value) for key, value in zip(
            self.INSTANCE_NAMES, self.search_request.get_searches()))
        self.all_cw_search_names = []
        for name, rset in self.rset_map.iteritems():
            self.all_cw_search_names.extend(
                [r[0].encode("utf-8") for r in rset])

        # Check we are dealing with a path
        assert path.startswith('/')
        # print "LIST::", path

        # Construct root folder
        if path == "/":
            if self.INSTANCE_NAMES is not None:
                root_virtual_folders = [
                    r.encode("utf-8") for r in self.INSTANCE_NAMES
                ]
            else:
                root_virtual_folders = self.cw_search_names
            for name in root_virtual_folders:
                s = self.stat("/{0}".format(name))
                yield (name, lsLine(name, s), self.attrs_from_stat(s))

        # Construct search folders if root contains instances
        elif (self.INSTANCE_NAMES is not None
              and path.lstrip("/") in self.INSTANCE_NAMES):
            # Get the proper rset
            rset = self.rset_map[path.lstrip("/")]
            cw_search_names = [r[0].encode("utf-8") for r in rset]
            for name in cw_search_names:
                s = self.stat('/%s' % name)
                yield (name, lsLine(name, s), self.attrs_from_stat(s))

        # Otherwise the build the tree based on the file path contained in cw
        else:
            virtpath = self.split_virtual_path(path)
            session_index = self.INSTANCE_NAMES.index(virtpath.search_instance)
            for filepath, rset_file in self.dir_content(
                    virtpath, session_index):

                if not rset_file:
                    s = self.stat(filepath, path_is_real=True)
                else:
                    # retrieve rset binary from database
                    rset = self.search_request.get_file_data(
                        file_eid=None,
                        rset_file=True,
                        search_name=virtpath.search_name,
                        session_index=session_index)
                    s = self.stat_file_entity(rset.len)
                basename = osp.basename(filepath).encode('utf-8')
                longname = lsLine(basename, s)
                yield (basename, longname, self.attrs_from_stat(s))
示例#18
0
    def list_directory(self, path):
        """ Method to list a virtual folder.

        Virtual folders have a common root organization:
        
        ::

            instance name
                |
                ---- CWSearch name
                            |
                            ---- ...

        Parameters
        ----------
        path: string (mandatory)
            the virtual path we want to access.

        Returns
        -------
        out: iterator
            an iterator containing virtual folder description. Each iterator
            item is a 3-uplet of the form (basename, longname, stat). 
        """

        # Create an association between cw rset and db name
        self.rset_map = dict((key.lstrip("/"), value) for key, value in zip(
            self.INSTANCE_NAMES, self.search_request.get_searches()))
        self.all_cw_search_names = []
        for name, rset in self.rset_map.iteritems():
            self.all_cw_search_names.extend(
                [r[0].encode("utf-8") for r in rset])

        # Check we are dealing with a path
        assert path.startswith('/')

        # Construct root folder
        if path == "/":
            if self.INSTANCE_NAMES is not None:
                root_virtual_folders = [r.encode("utf-8")
                                        for r in self.INSTANCE_NAMES]
            else:
                root_virtual_folders = self.cw_search_names
            for name in root_virtual_folders:
                s = self.stat("/{0}".format(name))
                yield (name,
                       lsLine(name, s),
                       self.attrs_from_stat(s))

        # Construct search folders if root contains instances
        elif (self.INSTANCE_NAMES is not None and
              path.lstrip("/") in self.INSTANCE_NAMES):
            # Get the proper rset
            rset = self.rset_map[path.lstrip("/")]
            cw_search_names = [r[0].encode("utf-8") for r in rset]
            for name in cw_search_names:
                s = self.stat('/%s' % name)
                yield (name,
                       lsLine(name, s),
                       self.attrs_from_stat(s))

        # Otherwise the build the tree based on the file path contained in cw
        else:
            virtpath = self.split_virtual_path(path)
            session_index = self.INSTANCE_NAMES.index(virtpath.search_instance)
            for filepath, rset_file in self.dir_content(virtpath,
                                                        session_index):

                if not rset_file:
                    s = self.stat(filepath, path_is_real=True)
                else:
                    # retrieve rset binary from database
                    rset = self.search_request.get_file_data(
                        file_eid=None, rset_file=True,
                        search_name=virtpath.search_name,
                        session_index=session_index)
                    s = self.stat_file_entity(rset.len)
                basename = osp.basename(filepath).encode('utf-8')
                longname = lsLine(basename, s)
                yield (basename, longname, self.attrs_from_stat(s))