]> git.pld-linux.org Git - projects/pld-ftp-admin.git/commitdiff
- extend ftpiod to be able to get locks info over the protocol
authorElan Ruusamäe <glen@pld-linux.org>
Mon, 2 Apr 2012 20:43:09 +0000 (20:43 +0000)
committerElan Ruusamäe <glen@pld-linux.org>
Mon, 2 Apr 2012 20:43:09 +0000 (20:43 +0000)
Changed files:
    bin/pfa-dump-locks -> 1.2
    modules/cmds.py -> 1.15
    modules/cons.py -> 1.8
    modules/ftpio.py -> 1.9
    modules/ftptree.py -> 1.55

bin/pfa-dump-locks
modules/cmds.py
modules/cons.py
modules/ftpio.py
modules/ftptree.py

index 640b87502b31958ceb327976d973cb12c0c79ea8..32fdfdf9491120d0e5d8ac0704fda3ce664a4eb8 100644 (file)
@@ -8,4 +8,4 @@ import ftpio
 import config
 
 ftpio.connect()
-ftpio.locks_dump()
+print ftpio.locks_dump()
index 76a413bad65ccb6a49c0e1abe8508e33d3abddbd..192dbf672ea73af9acc1c3d692405e28223c7375 100644 (file)
@@ -35,7 +35,6 @@ def parse(con):
             raise BailOut
             # TODO: log this
 
-
 def lock(con, arg, hard):
     if arg not in locks:
         locks[arg]={'hard': hard, 'name': con.name, 'time': int(time.time())}
@@ -44,8 +43,7 @@ def lock(con, arg, hard):
         con.sock.send("HARD") # Hard lock - you can go get a cup of tea
     else:
         con.sock.send("SOFT") # Soft lock - try in a second or two
-        
-    
+
 def cmd_unlock(con, arg):
     if arg in locks:
         del locks[arg]
@@ -62,16 +60,21 @@ def cmd_lock_hard(con, arg):
 def cmd_show_locks(con):
     cmd_log(con, "Dumping locks data:");
     if len(locks):
+        res = ""
         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']))))
+            msg = "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'])))
+            cmd_log(con, msg)
+            res = res + msg
+#        con.sock.send("BLOB:%d" % len(res))
+        con.sock.send(res)
     else:
         cmd_log(con, "No locks found.");
+        con.sock.send("NLCK");
 
 def cmd_log(con, msg):
-    logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), 
-                                       con.name, msg))
+    logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), con.name, msg))
     logfile.flush()
 
 def cmd_name(con, name):
index b72501352a37e11306d2e5f1887b556af883310a..61569f6e86c7d543031b701d45edcfd301ffaf05 100644 (file)
@@ -15,17 +15,23 @@ class Connection:
         self.fileno=sock.fileno
         self.name=""
         self.data=""
+
     def destroy(self):
         self.sock.close()
         rm(self)
+
     def handleinput(self):
+        newdata = None
         try:
-            newdata=self.sock.recv(8192)
+            newdata = self.sock.recv(8192)
         except:
             self.destroy()
+
         if not newdata:
             self.destroy()
-        self.data=self.data+newdata
+        else:
+            self.data = self.data + newdata
+
         try:
             cmds.parse(self)
         except cmds.BailOut:
index 1adf5e4d1771e27761faff37fdf29d8f0243e182..5e0132b69ddf2596d6b43a74e058738927ea1089 100644 (file)
@@ -72,6 +72,13 @@ def log(msg):
 
 def locks_dump():
     sock.send('slck\0')
+    ret = sock.recv(4096)
+    if ret == "NLCK":
+        return "No locks held"
+
+#    nbytes = int(ret.split("BLOB:")[1])
+#    ret = sock.recv(nbytes)
+    return ret
 
 def gettree():
     sock.send('gett\0')
index c62d1d6040063e76c8dfadd9986d9d26487c54ec..b0b2a8f6366a6fb157a5b3c2bdb5be77189cb5a7 100644 (file)
@@ -306,7 +306,7 @@ class FtpTree(BaseFtpTree):
         self.__checksigns(dsttree, self.marked4moving, test = True)
         self.__checkforobsoletes(dsttree, self.marked4moving, test = True)
         self.__checkforrelease(dsttree, self.marked4moving, test = True)
-        
+
         if not self.treename.count("archive"):
             self.__rmolderfromsrc(test = True)
 
This page took 0.068396 seconds and 4 git commands to generate.