]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blob - modules/cmds.py
46bb55b286bcadc746246305615841229700164e
[projects/pld-ftp-admin.git] / modules / cmds.py
1 # vi: encoding=utf-8 ts=8 sts=4 sw=4 et
2
3 import os
4 import time
5
6 CmdError="CmdError"
7
8 def parse(con):
9     if '\0' not in con.data:
10         return
11     cmds=con.data.split('\0')[:-1]
12
13     for cmd in cmds:
14         con.data=con.data[len(cmd)+1:]
15         cmdname=cmd[:4]
16         if cmdname in cmdlist:
17             cmdlist[cmdname](con, cmd[5:])
18         else:
19             raise CmdError
20             # TODO: log this
21
22 locks={}
23
24 def lock(con, arg, hard):
25     if arg not in locks:
26         locks[arg]=hard
27         con.sock.send("OK")
28     elif locks[arg]:
29         con.sock.send("HARD") # Hard lock - you can go get a cup of tea
30     else:
31         con.sock.send("SOFT") # Soft lock - try in a second or two
32         
33     
34 def cmd_unlock(con, arg):
35     if arg in locks:
36         del locks[arg]
37
38 def cmd_lock_soft(con, arg):
39     lock(con, arg, False)
40
41 def cmd_lock_hard(con, arg):
42     lock(con, arg, True)
43
44 logfile=open(os.environ['HOME']+'/pld-ftp-admin/var/log', 'a')
45
46 def cmd_log(con, msg):
47     logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), 
48                                        con.name, msg))
49     logfile.flush()
50
51 def cmd_name(con, name):
52     con.name=name
53
54 cmdlist={'lcks':cmd_lock_soft, 'lckh':cmd_lock_hard, 'ulck':cmd_unlock,
55          'log1':cmd_log, 'name':cmd_name}
56
This page took 0.027732 seconds and 3 git commands to generate.