# 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 cmd_unlock(con, arg): if arg in locks: del locks[arg] def cmd_lock_soft(con, arg): lock(con, arg, False) def cmd_lock_hard(con, arg): lock(con, arg, True) logfile=open(os.environ['HOME']+'/pld-ftp-admin/var/log', 'a') def cmd_log(con, 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): con.name=name cmdlist={'lcks':cmd_lock_soft, 'lckh':cmd_lock_hard, 'ulck':cmd_unlock, 'log1':cmd_log, 'name':cmd_name}