Fwd: Incorrect comparison of datetime remote and local objects

43 views
Skip to first unread message

Tomer Filiba

unread,
Aug 20, 2013, 7:55:27 AM8/20/13
to rpyc
it's a "known limitation" of rpyc, as __cmp__ isn't handled correctly.
a simple solution is converting both datetime objects into timetuples or timestamps, e.g.

ts1 = time.mktime(d1.timetuple())
ts2 = time.mktime(d2.timetuple())

if ts1 < ts2:
    ...


-tomer

-----------------------------------------------------------------
    
Tomer Filiba 
tomerfiliba.com        


On Tue, Aug 20, 2013 at 2:50 PM, <magid...@gmail.com> wrote:
Hi,
I am new user of RPyC. Recently, while writing my first script with RPyC I've figured out that
RPyC incorrectly compares local datetime and remote date time objects.
No exceptions or error shown.
Output example:
  Last modification of /tmp/.X11-unix was at 2013-07-31 17:30:34.708240
  Current remote time on server is: 2013-08-20 14:23:06.957131
  Checking if 2013-07-31 17:30:34.708240+7 days, 0:00:00 < 2013-08-20 14:23:06.957131
After that the script should print "Removing << /tmp/.X11-unix >>, but nothing printed.

Using:
RPyC 3.3.0
Python 2.6
Ubuntu 10.04 LTS 2.6.32-24-generic

Please advise.
Thanks,
Bentsi.

Script:

import rpyc.version as version
from rpyc.utils.zerodeploy import DeployedServer
from plumbum import SshMachine
from datetime import timedelta, datetime
import os

print "RPyC version: %s "%str(version.version)
dt = timedelta(days=7)
print "Connecting to server n2..."
sshSrv = SshMachine("n2")
deployedSrv = DeployedServer(sshSrv)
print "Remote date and time: [ %s ]"%( sshSrv["date"]().strip() )
conn1 = deployedSrv.classic_connect()
print "RPyC connected!"
listOfFiles = conn1.modules.os.listdir("/tmp")
for fn in listOfFiles:
  fPath = os.path.join("/tmp", fn)
  fStat = conn1.modules.os.lstat(fPath) #does not follow symbolic links
  lastModification = datetime.fromtimestamp(fStat.st_mtime)
  print "Last modification of %s was at %s"%(fPath, lastModification)
  currentRemoteTime =  conn1.modules.datetime.datetime.now()
  print "Current remote time on server is: %s"%currentRemoteTime
  print "Checking if %s+%s < %s"%(lastModification, dt, currentRemoteTime)
  if lastModification+dt < currentRemoteTime:
    print  "Removing<< %s >>"%fPath



Reply all
Reply to author
Forward
0 new messages