server/sources/pyrorql.py
branchtls-sprint
changeset 1016 26387b836099
parent 520 29342c0cf55f
child 1138 22f634977c95
equal deleted inserted replaced
1014:4792a1bb72a9 1016:26387b836099
     1 """Source to query another RQL repository using pyro
     1 """Source to query another RQL repository using pyro
     2 
     2 
     3 :organization: Logilab
     3 :organization: Logilab
     4 :copyright: 2007-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     4 :copyright: 2007-2009 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     5 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 """
     6 """
     7 __docformat__ = "restructuredtext en"
     7 __docformat__ = "restructuredtext en"
     8 
     8 
     9 import threading
     9 import threading
    10 from os.path import join
    10 from os.path import join
    11 
    11 
    12 from mx.DateTime import DateTimeFromTicks
    12 from time import mktime
       
    13 from datetime import datetime
    13 
    14 
    14 from Pyro.errors import PyroError, ConnectionClosedError
    15 from Pyro.errors import PyroError, ConnectionClosedError
    15 
    16 
    16 from logilab.common.configuration import REQUIRED
    17 from logilab.common.configuration import REQUIRED
    17 
    18 
   143                 session.commit()
   144                 session.commit()
   144                 timestamp = 0
   145                 timestamp = 0
   145             else:
   146             else:
   146                 assert len(rset) == 1
   147                 assert len(rset) == 1
   147                 timestamp = int(rset[0][0])
   148                 timestamp = int(rset[0][0])
   148             return DateTimeFromTicks(timestamp)
   149             return datetime.fromtimestamp(timestamp)
   149         finally:
   150         finally:
   150             session.close()
   151             session.close()
   151 
   152 
   152     def init(self):
   153     def init(self):
   153         """method called by the repository once ready to handle request"""
   154         """method called by the repository once ready to handle request"""
   192                     self.exception('while updating %s with external id %s of source %s',
   193                     self.exception('while updating %s with external id %s of source %s',
   193                                    etype, extid, self.uri)
   194                                    etype, extid, self.uri)
   194                     continue
   195                     continue
   195             session.execute('SET X value %(v)s WHERE X pkey %(k)s',
   196             session.execute('SET X value %(v)s WHERE X pkey %(k)s',
   196                             {'k': u'sources.%s.latest-update-time' % self.uri,
   197                             {'k': u'sources.%s.latest-update-time' % self.uri,
   197                              'v': unicode(int(updatetime.ticks()))})
   198                              'v': unicode(int(mktime(updatetime.timetuple())))})
   198             session.commit()
   199             session.commit()
   199         finally:
   200         finally:
   200             session.close()
   201             session.close()
   201                 
   202                 
   202     def _get_connection(self):
   203     def _get_connection(self):