[Zope3-checkins] CVS: Zope3/src/zope/server/ftp - ftpserverchannel.py:1.4 osemulators.py:1.3

Jim Fulton jim@zope.com
Thu, 30 Jan 2003 11:01:42 -0500


Update of /cvs-repository/Zope3/src/zope/server/ftp
In directory cvs.zope.org:/tmp/cvs-serv19284

Modified Files:
	ftpserverchannel.py osemulators.py 
Log Message:
Added support for -l, -a, and -d options to list command handling.


=== Zope3/src/zope/server/ftp/ftpserverchannel.py 1.3 => 1.4 ===
--- Zope3/src/zope/server/ftp/ftpserverchannel.py:1.3	Thu Jan  9 05:27:53 2003
+++ Zope3/src/zope/server/ftp/ftpserverchannel.py	Thu Jan 30 11:01:09 2003
@@ -20,6 +20,7 @@
 import stat
 import socket
 import time
+from getopt import getopt, GetoptError
 
 from zope.server.linereceiver.lineserverchannel import LineServerChannel
 from zope.server.ftp.ftpstatusmessages import status_msgs
@@ -152,6 +153,21 @@
 
     def cmd_list(self, args, long=1):
         'See IFTPCommandHandler'
+        opts = ()
+        if args.strip().startswith('-'):
+            try:
+                opts, args = getopt(args.split(), 'lad')
+            except GetoptError:
+                self.reply('ERR_ARGS')
+                return
+                
+            if len(args) > 1:
+                self.reply('ERR_ARGS')
+                return
+
+            args = args and args[0] or ''
+                
+            
         fs = self._getFilesystem()
         path = self._generatePath(args)
         if not fs.exists(path):
@@ -159,7 +175,10 @@
             return
         args = args.split()
         try:
-            s = self.getList(args, long)
+            s = self.getList(
+                args, long,
+                directory=bool([opt for opt in opts if opt[0]=='-d'])
+                )
         except OSError, err:
             self.reply('ERR_NO_LIST', str(err))
             return
@@ -472,7 +491,7 @@
         return self.passive_acceptor
 
 
-    def getList(self, args, long=0):
+    def getList(self, args, long=0, directory=0):
         # we need to scan the command line for arguments to '/bin/ls'...
         fs = self._getFilesystem()
         path_args = []
@@ -488,7 +507,7 @@
             path = path_args[0]
 
         path = self._generatePath(path)
-        if fs.isdir(path):
+        if fs.isdir(path) and not directory:
             file_list = fs.listdir(path, long)
         else:
             file_list = [ (posixpath.split(path)[1], fs.stat(path)) ]


=== Zope3/src/zope/server/ftp/osemulators.py 1.2 => 1.3 ===
--- Zope3/src/zope/server/ftp/osemulators.py:1.2	Wed Dec 25 09:15:23 2002
+++ Zope3/src/zope/server/ftp/osemulators.py	Thu Jan 30 11:01:09 2003
@@ -70,9 +70,10 @@
          Oct 19  1995
        otherwise, it looks like this:
          Oct 19 17:33
+
     """
-    if abs((now - t).days) > 180:
-        return t.strftime('%b %d, %Y')
+    if now.date() - t.date() > datetime.timedelta(days=180):
+        return t.strftime('%b %d %Y')
     else:
         return t.strftime('%b %d %H:%M')