pld-ftp-admin: modules/cmds.py, modules/ftpio.py - command to dump...

arekm arekm at pld-linux.org
Sun Sep 11 16:33:43 CEST 2005


Author: arekm                        Date: Sun Sep 11 14:33:43 2005 GMT
Module: pld-ftp-admin                 Tag: HEAD
---- Log message:
- command to dump locks data into log file
- unlock can fail when tree is already unlocked

---- Files affected:
pld-ftp-admin/modules:
   cmds.py (1.12 -> 1.13) , ftpio.py (1.7 -> 1.8) 

---- Diffs:

================================================================
Index: pld-ftp-admin/modules/cmds.py
diff -u pld-ftp-admin/modules/cmds.py:1.12 pld-ftp-admin/modules/cmds.py:1.13
--- pld-ftp-admin/modules/cmds.py:1.12	Sun Sep 11 15:14:03 2005
+++ pld-ftp-admin/modules/cmds.py	Sun Sep 11 16:33:38 2005
@@ -49,6 +49,9 @@
 def cmd_unlock(con, arg):
     if arg in locks:
         del locks[arg]
+        con.sock.send("OK")
+    else:
+        con.sock.send("FAIL")
 
 def cmd_lock_soft(con, arg):
     lock(con, arg, False)
@@ -56,6 +59,15 @@
 def cmd_lock_hard(con, arg):
     lock(con, arg, True)
 
+def cmd_show_locks(con):
+    cmd_log(con, "Dumping locks data:");
+    if len(locks):
+        for lockdata in locks.iteritems():
+            tree, data = lockdata
+            cmd_log(con, "Tree: %s, Conn name: %s, Hard Lock: %s, Time: %s"
+                    % (tree, data['name'], data['hard'], time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(data['time']))))
+    else:
+        cmd_log(con, "No locks found.");
 
 def cmd_log(con, msg):
     logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), 
@@ -65,7 +77,6 @@
 def cmd_name(con, name):
     con.name=name
 
-
 def load_creds():
     global users, cookies
     users={}
@@ -161,7 +172,7 @@
          'log1':cmd_log, 'name':cmd_name, 'linp':cmd_login_passwd,
          'linc':cmd_login_cookie}
 
-cmdlist_noargs={'lout':cmd_logout, 'gett':cmd_gettree}
+cmdlist_noargs={'lout':cmd_logout, 'gett':cmd_gettree, 'slck':cmd_show_locks}
 
 # Global stuff and initializations
 

================================================================
Index: pld-ftp-admin/modules/ftpio.py
diff -u pld-ftp-admin/modules/ftpio.py:1.7 pld-ftp-admin/modules/ftpio.py:1.8
--- pld-ftp-admin/modules/ftpio.py:1.7	Thu Jan 20 21:11:16 2005
+++ pld-ftp-admin/modules/ftpio.py	Sun Sep 11 16:33:38 2005
@@ -1,6 +1,7 @@
 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
 
 import os
+import sys
 import socket
 import time
 import config
@@ -17,8 +18,9 @@
     global sock
     sock=socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
     sock.connect(socketname)
-    if name:
-        sock.send('name %s\0' % name)
+    if not name:
+        name = "pid_%d_name_%s" % (os.getpid(), sys.argv[0])
+    sock.send('name %s\0' % name)
 
 def login_passwd(login, passwd):
     'Return cookie if ok'
@@ -60,9 +62,16 @@
     
 def unlock(path):
     sock.send('ulck %s\0' % path)
+    ret = sock.recv(20)
+    if ret == "OK":
+        return True
+    return False
 
 def log(msg):
     sock.send('log1 %s\0' % msg)
+
+def locks_dump():
+    sock.send('slck\0')
 
 def gettree():
     sock.send('gett\0')
================================================================

---- CVS-web:
    http://cvs.pld-linux.org/pld-ftp-admin/modules/cmds.py?r1=1.12&r2=1.13&f=u
    http://cvs.pld-linux.org/pld-ftp-admin/modules/ftpio.py?r1=1.7&r2=1.8&f=u




More information about the pld-cvs-commit mailing list