]> git.pld-linux.org Git - projects/pld-ftp-admin.git/blob - modules/cmds.py
- logging support
[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 unlock(con, arg):
35     if arg in locks:
36         del locks[arg]
37
38 def lock_soft(con, arg):
39     lock(con, arg, False)
40
41 def 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 log(con, msg):
47     logfile.write('%s -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), msg))
48     logfile.flush()
49
50 cmdlist={'lcks':lock_soft, 'lckh':lock_hard, 'ulck':unlock, 'log1':log}
51
This page took 0.026823 seconds and 3 git commands to generate.