Cosmetic changes in RecDB
This commit is contained in:
parent
a17868cd31
commit
3b8c12f3b2
1 changed files with 23 additions and 11 deletions
|
@ -64,7 +64,7 @@ class RecDB:
|
||||||
logging.getLogger('sqlalchemy.pool').setLevel(logging.FATAL)
|
logging.getLogger('sqlalchemy.pool').setLevel(logging.FATAL)
|
||||||
logging.getLogger('sqlalchemy.orm').setLevel(logging.FATAL)
|
logging.getLogger('sqlalchemy.orm').setLevel(logging.FATAL)
|
||||||
|
|
||||||
Base.metadata.create_all(self.engine) # create Database
|
Base.metadata.create_all(self.engine) # create Database
|
||||||
|
|
||||||
Session = sessionmaker(bind=self.engine)
|
Session = sessionmaker(bind=self.engine)
|
||||||
self.session = Session()
|
self.session = Session()
|
||||||
|
@ -80,7 +80,7 @@ class RecDB:
|
||||||
|
|
||||||
def update(self, id, rec):
|
def update(self, id, rec):
|
||||||
|
|
||||||
## TODO: rlist = results list
|
# TODO: rlist = results list
|
||||||
_rlist = self._search(_id=id)
|
_rlist = self._search(_id=id)
|
||||||
if not len(_rlist) == 1:
|
if not len(_rlist) == 1:
|
||||||
raise ValueError('Too many recs with id=%s' % id)
|
raise ValueError('Too many recs with id=%s' % id)
|
||||||
|
@ -149,8 +149,7 @@ class RecDB:
|
||||||
The meaning is "a query that makes sense to stop"
|
The meaning is "a query that makes sense to stop"
|
||||||
'''
|
'''
|
||||||
delta = timedelta(seconds=get_config()['FORGE_MAX_DURATION'])
|
delta = timedelta(seconds=get_config()['FORGE_MAX_DURATION'])
|
||||||
return self._query_not_saved(query).filter(Rec.starttime >
|
return self._query_newer(delta, self._query_not_saved(query))
|
||||||
datetime.now() - delta)
|
|
||||||
|
|
||||||
def _query_not_saved(self, query=None):
|
def _query_not_saved(self, query=None):
|
||||||
'''Still not saved'''
|
'''Still not saved'''
|
||||||
|
@ -158,6 +157,18 @@ class RecDB:
|
||||||
query = self.get_session().query(Rec)
|
query = self.get_session().query(Rec)
|
||||||
return query.filter(Rec.filename == None)
|
return query.filter(Rec.filename == None)
|
||||||
|
|
||||||
|
def _query_saved(self, query=None):
|
||||||
|
'''Still not saved'''
|
||||||
|
if query is None:
|
||||||
|
query = self.get_session().query(Rec)
|
||||||
|
return query.filter(Rec.filename != None)
|
||||||
|
|
||||||
|
def _query_newer(self, delta, query=None):
|
||||||
|
'''Get Rec older than delta seconds'''
|
||||||
|
if query is None:
|
||||||
|
query = self.get_session().query(Rec)
|
||||||
|
return query.filter(Rec.starttime > datetime.now() - delta)
|
||||||
|
|
||||||
def _query_older(self, delta, query=None):
|
def _query_older(self, delta, query=None):
|
||||||
'''Get Rec older than delta seconds'''
|
'''Get Rec older than delta seconds'''
|
||||||
if query is None:
|
if query is None:
|
||||||
|
@ -213,21 +224,22 @@ if __name__ == "__main__":
|
||||||
print "Record: %s" % record
|
print "Record: %s" % record
|
||||||
|
|
||||||
db = RecDB()
|
db = RecDB()
|
||||||
_mytime = datetime(2014,05,23,15,12,17)
|
_mytime = datetime(2014, 05, 23, 15, 12, 17)
|
||||||
_endtime = datetime(2014,05,24,17,45,17)
|
_endtime = datetime(2014, 05, 24, 17, 45, 17)
|
||||||
|
|
||||||
a = Rec(name="Mimmo1", starttime=_mytime, endtime=_endtime)
|
a = Rec(name="Mimmo1", starttime=_mytime, endtime=_endtime)
|
||||||
printall( db._search() )
|
printall(db._search())
|
||||||
sys.exit("End test job")
|
sys.exit("End test job")
|
||||||
|
|
||||||
# a = Rec(name="Mimmo1", starttime=_mytime, endtime=None)
|
# a = Rec(name="Mimmo1", starttime=_mytime, endtime=None)
|
||||||
print "Aggiunto", db.add( a )
|
print "Aggiunto", db.add(a)
|
||||||
printall( db.get_all(page_size=5,page=0) )
|
printall(db.get_all(page_size=5, page=0))
|
||||||
|
|
||||||
print "Mimmo "
|
print "Mimmo "
|
||||||
printall( db._search(name="Mimmo1"))
|
printall(db._search(name="Mimmo1"))
|
||||||
print "Search"
|
print "Search"
|
||||||
printall( db._search(name="Mimmo1",starttime=datetime(2014,05,24,15,16,1) ))
|
printall(db._search(name="Mimmo1",
|
||||||
|
starttime=datetime(2014, 05, 24, 15, 16, 1) ))
|
||||||
a = db.get_by_id(5)
|
a = db.get_by_id(5)
|
||||||
a.start()
|
a.start()
|
||||||
db.delete(1)
|
db.delete(1)
|
||||||
|
|
Loading…
Reference in a new issue