Ejemplo n.º 1
0
    def format_list(self, cr, parent_node, listing, ignore_err=True):
        """Return an iterator object that yields the entries of given
        directory emulating the "/bin/ls -lA" UNIX command output.

         - (str) basedir: the parent directory node. Can be None
         - (list) listing: a list of nodes
         - (bool) ignore_err: when False raise exception if os.lstat()
         call fails.

        On platforms which do not support the pwd and grp modules (such
        as Windows), ownership is printed as "owner" and "group" as a
        default, and number of hard links is always "1". On UNIX
        systems, the actual owner, group, and number of links are
        printed.

        This is how output appears to client:

        -rw-rw-rw-   1 owner   group    7045120 Sep 02  3:47 music.mp3
        drwxrwxrwx   1 owner   group          0 Aug 31 18:50 e-books
        -rw-rw-rw-   1 owner   group        380 Sep 02  3:40 module.py
        """
        for node in listing:
            perms = filemode(node.unixperms)  # permissions
            nlinks = 1
            size = node.content_length or 0L
            uname = _to_decode(node.uuser)
            gname = _to_decode(node.ugroup)
            # stat.st_mtime could fail (-1) if last mtime is too old
            # in which case we return the local time as last mtime
            try:
                st_mtime = node.write_date or 0.0
                if isinstance(st_mtime, basestring):
                    st_mtime = time.strptime(st_mtime, '%Y-%m-%d %H:%M:%S')
                elif isinstance(st_mtime, float):
                    st_mtime = time.localtime(st_mtime)
                mname=_get_month_name(time.strftime("%m", st_mtime ))
                mtime = mname+' '+time.strftime("%d %H:%M", st_mtime)
            except ValueError:
                mname=_get_month_name(time.strftime("%m"))
                mtime = mname+' '+time.strftime("%d %H:%M")
            fpath = node.path
            if isinstance(fpath, (list, tuple)):
                fpath = fpath[-1]
            # formatting is matched with proftpd ls output
            path=_to_decode(fpath)
            yield "%s %3s %-8s %-8s %8s %s %s\r\n" %(perms, nlinks, uname, gname,
                                                     size, mtime, path)
Ejemplo n.º 2
0
    def format_list(self, cr, parent_node, listing, ignore_err=True):
        """Return an iterator object that yields the entries of given
        directory emulating the "/bin/ls -lA" UNIX command output.

         - (str) basedir: the parent directory node. Can be None
         - (list) listing: a list of nodes
         - (bool) ignore_err: when False raise exception if os.lstat()
         call fails.

        On platforms which do not support the pwd and grp modules (such
        as Windows), ownership is printed as "owner" and "group" as a
        default, and number of hard links is always "1". On UNIX
        systems, the actual owner, group, and number of links are
        printed.

        This is how output appears to client:

        -rw-rw-rw-   1 owner   group    7045120 Sep 02  3:47 music.mp3
        drwxrwxrwx   1 owner   group          0 Aug 31 18:50 e-books
        -rw-rw-rw-   1 owner   group        380 Sep 02  3:40 module.py
        """
        for node in listing:
            perms = filemode(node.unixperms)  # permissions
            nlinks = 1
            size = node.content_length or 0L
            uname = _to_decode(node.uuser)
            gname = _to_decode(node.ugroup)
            # stat.st_mtime could fail (-1) if last mtime is too old
            # in which case we return the local time as last mtime
            try:
                st_mtime = node.write_date or 0.0
                if isinstance(st_mtime, basestring):
                    st_mtime = time.strptime(st_mtime, '%Y-%m-%d %H:%M:%S')
                elif isinstance(st_mtime, float):
                    st_mtime = time.localtime(st_mtime)
                mname = _get_month_name(time.strftime("%m", st_mtime))
                mtime = mname + ' ' + time.strftime("%d %H:%M", st_mtime)
            except ValueError:
                mname = _get_month_name(time.strftime("%m"))
                mtime = mname + ' ' + time.strftime("%d %H:%M")
            fpath = node.path
            if isinstance(fpath, (list, tuple)):
                fpath = fpath[-1]
            # formatting is matched with proftpd ls output
            path = _to_decode(fpath)
            yield "%s %3s %-8s %-8s %8s %s %s\r\n" % (perms, nlinks, uname,
                                                      gname, size, mtime, path)
Ejemplo n.º 3
0
    def fs2ftp(self, node):
        """ Return the string path of a node, in ftp form
        """
        res = "/"
        if node:
            paths = node.full_path()
            res = "/" + node.context.dbname + "/" + _to_decode(os.path.join(*paths))

        return res
Ejemplo n.º 4
0
    def fs2ftp(self, node):
        """ Return the string path of a node, in ftp form
        """
        res = '/'
        if node:
            paths = node.full_path()
            res = '/' + node.context.dbname + '/' +  \
                _to_decode(os.path.join(*paths))

        return res
Ejemplo n.º 5
0
    def format_mlsx(self, cr, basedir, listing, perms, facts, ignore_err=True):
        """Return an iterator object that yields the entries of a given
        directory or of a single file in a form suitable with MLSD and
        MLST commands.

        Every entry includes a list of "facts" referring the listed
        element.  See RFC-3659, chapter 7, to see what every single
        fact stands for.

         - (str) basedir: the absolute dirname.
         - (list) listing: the names of the entries in basedir
         - (str) perms: the string referencing the user permissions.
         - (str) facts: the list of "facts" to be returned.
         - (bool) ignore_err: when False raise exception if os.stat()
         call fails.

        Note that "facts" returned may change depending on the platform
        and on what user specified by using the OPTS command.

        This is how output could appear to the client issuing
        a MLSD request:

        type=file;size=156;perm=r;modify=20071029155301;unique=801cd2; music.mp3
        type=dir;size=0;perm=el;modify=20071127230206;unique=801e33; ebooks
        type=file;size=211;perm=r;modify=20071103093626;unique=801e32; module.py
        """
        permdir = ''.join([x for x in perms if x not in 'arw'])
        permfile = ''.join([x for x in perms if x not in 'celmp'])
        if ('w' in perms) or ('a' in perms) or ('f' in perms):
            permdir += 'c'
        if 'd' in perms:
            permdir += 'p'
        type = size = perm = modify = create = unique = mode = uid = gid = ""
        for node in listing:
            # type + perm
            if self.isdir(node):
                if 'type' in facts:
                    type = 'type=dir;'
                if 'perm' in facts:
                    perm = 'perm=%s;' % permdir
            else:
                if 'type' in facts:
                    type = 'type=file;'
                if 'perm' in facts:
                    perm = 'perm=%s;' % permfile
            if 'size' in facts:
                size = 'size=%s;' % (node.content_length or 0L)
            # last modification time
            if 'modify' in facts:
                try:
                    st_mtime = node.write_date or 0.0
                    if isinstance(st_mtime, basestring):
                        st_mtime = time.strptime(st_mtime, '%Y-%m-%d %H:%M:%S')
                    elif isinstance(st_mtime, float):
                        st_mtime = time.localtime(st_mtime)
                    modify = 'modify=%s;' % time.strftime(
                        "%Y%m%d%H%M%S", st_mtime)
                except ValueError:
                    # stat.st_mtime could fail (-1) if last mtime is too old
                    modify = ""
            if 'create' in facts:
                # on Windows we can provide also the creation time
                try:
                    st_ctime = node.create_date or 0.0
                    if isinstance(st_ctime, basestring):
                        st_ctime = time.strptime(st_ctime, '%Y-%m-%d %H:%M:%S')
                    elif isinstance(st_mtime, float):
                        st_ctime = time.localtime(st_ctime)
                    create = 'create=%s;' % time.strftime(
                        "%Y%m%d%H%M%S", st_ctime)
                except ValueError:
                    create = ""
            # UNIX only
            if 'unix.mode' in facts:
                mode = 'unix.mode=%s;' % oct(node.unixperms & 0777)
            if 'unix.uid' in facts:
                uid = 'unix.uid=%s;' % _to_decode(node.uuser)
            if 'unix.gid' in facts:
                gid = 'unix.gid=%s;' % _to_decode(node.ugroup)
            # We provide unique fact (see RFC-3659, chapter 7.5.2) on
            # posix platforms only; we get it by mixing st_dev and
            # st_ino values which should be enough for granting an
            # uniqueness for the file listed.
            # The same approach is used by pure-ftpd.
            # Implementors who want to provide unique fact on other
            # platforms should use some platform-specific method (e.g.
            # on Windows NTFS filesystems MTF records could be used).
            # if 'unique' in facts: todo
            #    unique = "unique=%x%x;" %(st.st_dev, st.st_ino)
            path = node.path
            if isinstance(path, (list, tuple)):
                path = path[-1]
            path = _to_decode(path)
            yield "%s%s%s%s%s%s%s%s%s %s\r\n" % (
                type, size, perm, modify, create, mode, uid, gid, unique, path)
Ejemplo n.º 6
0
 def get_cwd(self):
     """ return the cwd, decoded in utf"""
     return _to_decode(self.cwd)
Ejemplo n.º 7
0
    def format_mlsx(self, cr, basedir, listing, perms, facts, ignore_err=True):
        """Return an iterator object that yields the entries of a given
        directory or of a single file in a form suitable with MLSD and
        MLST commands.

        Every entry includes a list of "facts" referring the listed
        element.  See RFC-3659, chapter 7, to see what every single
        fact stands for.

         - (str) basedir: the absolute dirname.
         - (list) listing: the names of the entries in basedir
         - (str) perms: the string referencing the user permissions.
         - (str) facts: the list of "facts" to be returned.
         - (bool) ignore_err: when False raise exception if os.stat()
         call fails.

        Note that "facts" returned may change depending on the platform
        and on what user specified by using the OPTS command.

        This is how output could appear to the client issuing
        a MLSD request:

        type=file;size=156;perm=r;modify=20071029155301;unique=801cd2; music.mp3
        type=dir;size=0;perm=el;modify=20071127230206;unique=801e33; ebooks
        type=file;size=211;perm=r;modify=20071103093626;unique=801e32; module.py
        """
        permdir = "".join([x for x in perms if x not in "arw"])
        permfile = "".join([x for x in perms if x not in "celmp"])
        if ("w" in perms) or ("a" in perms) or ("f" in perms):
            permdir += "c"
        if "d" in perms:
            permdir += "p"
        type = size = perm = modify = create = unique = mode = uid = gid = ""
        for node in listing:
            # type + perm
            if self.isdir(node):
                if "type" in facts:
                    type = "type=dir;"
                if "perm" in facts:
                    perm = "perm=%s;" % permdir
            else:
                if "type" in facts:
                    type = "type=file;"
                if "perm" in facts:
                    perm = "perm=%s;" % permfile
            if "size" in facts:
                size = "size=%s;" % (node.content_length or 0L)
            # last modification time
            if "modify" in facts:
                try:
                    st_mtime = node.write_date or 0.0
                    if isinstance(st_mtime, basestring):
                        st_mtime = time.strptime(st_mtime, "%Y-%m-%d %H:%M:%S")
                    elif isinstance(st_mtime, float):
                        st_mtime = time.localtime(st_mtime)
                    modify = "modify=%s;" % time.strftime("%Y%m%d%H%M%S", st_mtime)
                except ValueError:
                    # stat.st_mtime could fail (-1) if last mtime is too old
                    modify = ""
            if "create" in facts:
                # on Windows we can provide also the creation time
                try:
                    st_ctime = node.create_date or 0.0
                    if isinstance(st_ctime, basestring):
                        st_ctime = time.strptime(st_ctime, "%Y-%m-%d %H:%M:%S")
                    elif isinstance(st_mtime, float):
                        st_ctime = time.localtime(st_ctime)
                    create = "create=%s;" % time.strftime("%Y%m%d%H%M%S", st_ctime)
                except ValueError:
                    create = ""
            # UNIX only
            if "unix.mode" in facts:
                mode = "unix.mode=%s;" % oct(node.unixperms & 0777)
            if "unix.uid" in facts:
                uid = "unix.uid=%s;" % _to_decode(node.uuser)
            if "unix.gid" in facts:
                gid = "unix.gid=%s;" % _to_decode(node.ugroup)
            # We provide unique fact (see RFC-3659, chapter 7.5.2) on
            # posix platforms only; we get it by mixing st_dev and
            # st_ino values which should be enough for granting an
            # uniqueness for the file listed.
            # The same approach is used by pure-ftpd.
            # Implementors who want to provide unique fact on other
            # platforms should use some platform-specific method (e.g.
            # on Windows NTFS filesystems MTF records could be used).
            # if 'unique' in facts: todo
            #    unique = "unique=%x%x;" %(st.st_dev, st.st_ino)
            path = node.path
            if isinstance(path, (list, tuple)):
                path = path[-1]
            path = _to_decode(path)
            yield "%s%s%s%s%s%s%s%s%s %s\r\n" % (type, size, perm, modify, create, mode, uid, gid, unique, path)
Ejemplo n.º 8
0
 def get_cwd(self):
     """ return the cwd, decoded in utf"""
     return _to_decode(self.cwd)