# vi: encoding=utf-8 ts=8 sts=4 sw=4 et import os import time CmdError="CmdError" def parse(con): if '\0' not in con.data: return cmds=con.data.split('\0')[:-1] for cmd in cmds: con.data=con.data[len(cmd)+1:] cmdname=cmd[:4] if cmdname in cmdlist: cmdlist[cmdname](con, cmd[5:]) else: raise CmdError # TODO: log this locks={} def lock(con, arg, hard): if arg not in locks: locks[arg]=hard con.sock.send("OK") elif locks[arg]: 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 unlock(con, arg): if arg in locks: del locks[arg] def lock_soft(con, arg): lock(con, arg, False) def lock_hard(con, arg): lock(con, arg, True) logfile=open(os.environ['HOME']+'/pld-ftp-admin/var/log', 'a') def log(con, msg): logfile.write('%s -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), msg)) logfile.flush() cmdlist={'lcks':lock_soft, 'lckh':lock_hard, 'ulck':unlock, 'log1':log}