il server deve eseguire start()

implementare start()
ri-organizzare log()
debug()
This commit is contained in:
antifaz 2013-09-11 00:05:31 +02:00
parent 0caf73a929
commit a3086b4a63
3 changed files with 105 additions and 58 deletions

View file

@ -108,6 +108,10 @@ function rec_new( ) {
str = str + "<input type=\"submit\" name=\""+trx_downbut(recid)+"\" id=\""+trx_downbut(recid)+"\" ";
str = str + " class=\"recbutton\" value=\"Scarica\" />";
str = str + "<input type=\"text\" id=\""+rs_inputstart(recid)+"\" name=\""+rs_inputstart(recid)+"\"/>";
str = str + "<input type=\"text\" id=\""+rs_inputend(recid)+"\" name=\""+rs_inputend(recid)+"\"/> ";
str = str + "</form>";
@ -188,15 +192,15 @@ function ChangeState(eid, from, to) {
var logdiv = trx_logarea( eid );
if ( from == trx_startbut(eid) ) {
var str = "<input type=\"text\" id=\""+rs_inputstart(eid)+"\" name=\""+rs_inputstart(eid)+"\" value=\""+displayDate+"\" />";
$("#"+formid).append( str );
$("#"+logdiv).append("<br/>Inizio: "+ displayDate);
$("#"+rs_inputstart(eid)).val( displayDate);
console.log("set "+rs_inputstart(eid)+ " to "+ displayDate )
}
if ( from == trx_stopbut(eid) ) {
var str = "\<input type=\"text\" id=\""+rs_inputend(eid)+"\" name=\""+rs_inputend(eid)+"\" value=\""+displayDate+"\" /\>";
$("#"+formid).append( str );
$("#"+logdiv).append("<br/>Fine: "+ displayDate);
$("#"+rs_inputend(eid)).val( displayDate);
console.log("set "+rs_inputend(eid)+ " to "+ displayDate )
}
} // End function ChangeState

Binary file not shown.

View file

@ -1,7 +1,11 @@
import logging
logging.basicConfig(level=logging.DEBUG)
import sys
import datetime
import json
import yaml
try:
from sqlalchemy import create_engine, Column, Integer, String, DateTime
from sqlalchemy.orm import sessionmaker
@ -10,9 +14,8 @@ except:
sys.exit("No SQLAlchemy.")
import json
logging.basicConfig(level=logging.INFO)
import yaml
"""
This class describe a single Record (Rec() class) and the
@ -22,25 +25,34 @@ records manager (RecDB() class)
Base = declarative_base()
""" ************
RECORD ABSTRACTION
RECORD STATE FLAGS
************ """
QUEUE = 0
RUN = 2
DONE = 4
PAGESIZE = 10
# Job in thread
class RecJob():
def __init__(self, rec):
print "Estraggo %s Start:%s, End:%s" % (rec.name, rec.starttime, rec.endtime)
def run(self):
pass
class Rec(Base):
__tablename__ = 'rec'
id = Column(Integer, primary_key=True)
name = Column(String)
# TODO: timestamp
endtime = Column(DateTime)
starttime = Column(DateTime)
state = Column(Integer)
def __init__(self, name="", starttime=None, endtime=None, asjson=""):
self.error = 0
self.values = {"name":"","starttime":"", "endtime":""}
self.job = None
if len(asjson) == 0:
self.name = name
@ -61,18 +73,19 @@ class Rec(Base):
selfendtime = asjson[0]['endtime']
self.state = QUEUE
logging.info("New REC: ", self.values)
# launch the job for processing files
def start(self):
# calcola file da splittare
pass
self.job = RecJob( self )
def getvalue(self,val=None):
if val != None:
if self.values.has_key(val):
return self.values[val]
return self.values
def getvalues(self,val=None):
return { "id":self.id,
"name":self.name,
"starttime":self.starttime,
"endtime":self.endtime,
"state": self.state
}
def err(self):
return self.error
@ -93,9 +106,15 @@ RecDB
class RecDB:
def __init__(self):
self.engine = create_engine('sqlite:///techrec.db', echo=True)
self.engine = create_engine('sqlite:///techrec.db', echo=False)
self.conn = self.engine.connect()
logging.getLogger('sqlalchemy.engine').setLevel(logging.FATAL)
logging.getLogger('sqlalchemy.engine.base.Engine').setLevel(logging.FATAL)
logging.getLogger('sqlalchemy.dialects').setLevel(logging.FATAL)
logging.getLogger('sqlalchemy.pool').setLevel(logging.FATAL)
logging.getLogger('sqlalchemy.orm').setLevel(logging.FATAL)
Base.metadata.create_all(self.engine) # create Database
Session = sessionmaker(bind=self.engine)
@ -104,42 +123,66 @@ class RecDB:
def add(self, simplerecord):
logging.debug("New Record: %s" % simplerecord)
self.session.add( simplerecord )
self.commit()
return ( simplerecord )
def delete(self,id):
_r = self.get_by_id(id)
if _r:
self.session.delete( _r )
self.commit()
return
logging.info("Delete error: ID %s not found!", id)
def commit(self):
self.session.commit()
# print all records
def printall(self):
print(" ---- DB ---- ")
allrecords = self.session.query(Rec).all()
def get_all(self,page=0, page_size=PAGESIZE):
return self._search(page=page, page_size=page_size)
print [ "R: %s" % record for record in allrecords ]
def _search(self, _id=None, name=None, starttime=None, endtime=None, page=0, page_size=PAGESIZE):
query = self.session.query(Rec)
if _id: query = query.filter_by(id=_id)
if name: query = query.filter_by(name=name)
if starttime: query = query.filter(Rec.starttime>starttime)
if endtime: query = query.filter(Rec.endtime<endtime)
if page_size: query = query.limit(page_size)
if page: query = query.offset(page*page_size)
return query.all()
def execsql(self,sql):
records = self.conn.execute( sql )
def get_by_id(self,id):
try:
return self._search( _id=id )[0]
except:
return None
def search(self, name="", starttime="", endtime=""):
logging.debug("Looking for %s - %s - %s" % (name, starttime, endtime) )
ret = self.session.query(Rec).filter_by(name='Mimmo1').all()
print "[SEARCH] RET (",type(ret),")" , ret
for row in ret:
print "[SEARCH] Found:", row
# Just for debug
def printall( queryres ):
for record in queryres:
print "R: %s" % record
"""
TEST
"""
if __name__ == "__main__":
# text
db = RecDB()
_mytime = datetime.datetime(2014,05,24,15,16,17)
a = Rec(name="Mimmo1", starttime=_mytime, endtime=None)
print "Aggiunto", db.add( a )
printall( db.get_all(page_size=5,page=0) )
db.add( a )
raw_input()
db.printall()
raw_input()
# db.search( Rec(name="Mimmo1") )
db.search( name="Mimmo1" )
print "Mimmo "
printall( db._search(name="Mimmo1"))
print "Search"
printall( db._search(name="Mimmo1",starttime=datetime.datetime(2014,05,24,15,16,1) ))
a = db.get_by_id(5)
a.start()
db.delete(1)
db.delete(2)
db.delete(4)
db.delete(1)
printall( db._search() )