def lock(con, arg, hard):
if arg not in locks:
locks[arg]={'hard': hard, 'name': con.name, 'time': int(time.time())}
- con.sock.send("OK")
+ con.sock.send(bytearray("OK", encoding='utf-8'))
elif locks[arg]['hard']:
- con.sock.send("HARD") # Hard lock - you can go get a cup of tea
+ con.sock.send(bytearray("HARD", encoding='utf-8')) # Hard lock - you can go get a cup of tea
else:
- con.sock.send("SOFT") # Soft lock - try in a second or two
+ con.sock.send(bytearray("SOFT", encoding='utf-8')) # Soft lock - try in a second or two
def cmd_unlock(con, arg):
if arg in locks:
del locks[arg]
- con.sock.send("OK")
+ con.sock.send(bytearray("OK", encoding='utf-8'))
else:
- con.sock.send("FAIL")
+ con.sock.send(bytearray("FAIL", encoding='utf-8'))
def cmd_lock_soft(con, arg):
lock(con, arg, False)
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)
+# con.sock.send(bytearray("BLOB:%d" % len(res), encoding='utf-8')))
+ con.sock.send(bytearray(res, encoding='utf-8'))
else:
- cmd_log(con, "No locks found.");
- con.sock.send("NLCK");
+ cmd_log(con, "No locks found.")
+ con.sock.send(bytearray("NLCK", encoding='utf-8'))
def cmd_log(con, msg):
logfile.write('%s [%s] -- %s\n' % (time.strftime('%Y-%m-%d %H:%M:%S'), con.name, msg))
write_cookies()
con.username=login
con.authorized=True
- con.sock.send('OK '+cookie)
+ con.sock.send(bytearray('OK '+cookie, encoding='utf-8'))
else:
# TODO: log this
- con.sock.send('FAIL')
+ con.sock.send(bytearray('FAIL', encoding='utf-8'))
raise BailOut()
def cmd_login_cookie(con, cookie):
con.cookie=cookie
con.authorized=True
con.username=cookies[cookie]
- con.sock.send('OK '+cookies[cookie])
+ con.sock.send(bytearray('OK '+cookies[cookie], encoding='utf-8'))
else:
# TODO: log this (or not)
- con.sock.send('FAIL')
+ con.sock.send(bytearray('FAIL'))
def cmd_logout(con):
if con.cookie in cookies:
line=line+'\n0'
buf=buf+'\0'+line
if buf:
- con.sock.send('%.6d' % (len(buf)-1))
- con.sock.send(buf[1:])
+ con.sock.send(bytearray('%.6d' % (len(buf)-1), encoding='utf-8'))
+ con.sock.send(bytearray(buf[1:], encoding='utf-8'))
else:
- con.sock.send('000000')
+ con.sock.send(bytearray('000000', encoding='utf-8'))
cmdlist_args={'lcks':cmd_lock_soft, 'lckh':cmd_lock_hard, 'ulck':cmd_unlock,
sock.connect(socketname)
if not name:
name = "pid_%d_name_%s" % (os.getpid(), sys.argv[0])
- sock.send('name %s\0' % name)
+ sock.send(bytearray('name %s\0' % name, encoding='utf-8'))
def login_passwd(login, passwd):
'Return cookie if ok'
- sock.send('linp %s\n%s\0' % (login, passwd))
- retval=sock.recv(256)
+ sock.send(bytearray('linp %s\n%s\0' % (login, passwd), encoding='utf-8'))
+ retval=sock.recv(256).decode("utf-8")
if retval=='FAIL':
return ''
else:
def login_cookie(cookie):
'Return login if ok'
- sock.send('linc %s\0' % cookie)
- retval=sock.recv(256)
+ sock.send(bytearray('linc %s\0' % cookie, encoding='utf-8'))
+ retval=sock.recv(256).decode('utf-8')
if retval=='FAIL':
return ''
else:
return retval[3:]
def logout():
- sock.send('lout\0')
+ sock.send(bytearray('lout\0', encoding='utf-8'))
def lock(path, hard=False):
def dolock():
if hard:
- sock.send('lckh %s\0' % path)
+ sock.send(bytearray('lckh %s\0' % path, encoding='utf-8'))
else:
- sock.send('lcks %s\0' % path)
- return sock.recv(20)
+ sock.send(bytearray('lcks %s\0' % path, encoding='utf-8'))
+ return sock.recv(20).decode("utf-8")
for i in range(3):
retcode=dolock()
if retcode=="OK":
return False
def unlock(path):
- sock.send('ulck %s\0' % path)
- ret = sock.recv(20)
+ sock.send(bytearray('ulck %s\0' % path, encoding='utf-8'))
+ ret = sock.recv(20).decode("utf-8")
if ret == "OK":
return True
return False
def log(msg):
- sock.send('log1 %s\0' % msg)
+ sock.send(bytearray('log1 %s\0' % msg, encoding='utf-8'))
def locks_dump():
- sock.send('slck\0')
- ret = sock.recv(4096)
+ sock.send(bytearray('slck\0', encoding='utf-8'))
+ ret = sock.recv(4096).decode("utf-8")
if ret == "NLCK":
return "No locks held"
# nbytes = int(ret.split("BLOB:")[1])
-# ret = sock.recv(nbytes)
+# ret = sock.recv(nbytes).decode("utf-8")
return ret
def gettree():
- sock.send('gett\0')
+ sock.send(bytearray('gett\0', encoding='utf-8'))
pkgs=[]
- len=int(sock.recv(6))
+ len=int(sock.recv(6).decode("utf-8"))
if len:
- for pkg in sock.recv(len).split('\0'):
+ for pkg in sock.recv(len).decode("utf-8").split('\0'):
tmp=pkg.split('\n')
pkgs.append((tmp[0], int(tmp[1]), int(tmp[2])))
return pkgs