This commit is contained in:
antifaz 2013-09-15 16:13:06 +02:00
parent a3b85772a4
commit 0c4bd5344b
3 changed files with 4 additions and 170 deletions

View file

@ -25,59 +25,14 @@ var srvaddr = "http://127.0.1.1:8000/";
var almostone = false;
var noplusbotton = true;
var maxrec = 0 ;
var maxrec = 0 ; // Number of Active Record
var rec_name_default = "";
/**
* Perform Ajax async loading
**/
function DELETEasync_load( destdiv, uri, postdata) {
postdata = postdata || '';
console.log("[ASYNC] " + destdiv + " <- " + uri)
console.log( postdata );
$(destdiv).html("\<div class=\"imageloader\"\> \<img src=\"img/ajax-loader.gif\" /\> \</div\>");
console.log("Tolta uri" + uri + "NOW -> http://127.0.1.1:8000/sampleJSON");
var request = $.ajax( { url: "http://127.0.0.1:8000/create",
type:"GET",
//data: postdata,
//dataType: 'json',
success : function( msg ) {
$(".imageloader").remove();
resmsg = "["+jqXHR.status+"]";
alert("Ma ci sei ?");
$(destdiv).append( resmsg );
},
error: function(xhr) {
var errmsg = "";
console.log("Errore async ajax: " + xhr.status );
switch( xhr.status )
{
case 0: errmsg="[0] Network Problem."; break;
case 404: errmsg="[404] Requested page not found."; break;
case 500: errmsg="[500] Internal Server Error."; break;
default: errmsg="[ErrCode: "+xhr.status+"] Error uncatched!"; break;
}
console.log("ErrMSG" + errmsg);
$(".imageloader").remove();
//$(destdiv).html("Err: "+ errmsg);
alert("Err: "+ errmsg);
}
}
).always(function( jqXHR ) {
$(".imageloader").remove();
resmsg = "ALSWAST["+jqXHR.status+"]";
$(destdiv).append( resmsg );
}
).complete(
function (jqXHR, msgstatus) {
alert("Comlpete " +jqXHR + " - " + msgstatus);
}
);
return false;
}
/**
@ -85,7 +40,7 @@ function DELETEasync_load( destdiv, uri, postdata) {
**/
function rec_new( ) {
var recid = "rec-"+maxrec;
maxrec += 1; // increment number of active record
maxrec += 1;
console.log("[rec_new] New Rec " + recid);

View file

@ -1,111 +0,0 @@
import SocketServer
import sys,os
import logging
logging.basicConfig(level=logging.INFO)
"""
RESPONSE HTML
http://stackoverflow.com/questions/6391280/simplehttprequesthandler-override-do-get
"""
import ast
# include data object
from techrec import *
import SimpleHTTPServer
""" CONNECTION HANDLER """
# class ConnHandler(SocketServer.BaseRequestHandler):
class ConnHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def __init__(self, *args, **keys):
self.db = RecDB()
# logging.info("Connected from: %s" % self.client_address[0] )
SocketServer.BaseRequestHandler.__init__(self, *args, **keys)
# SimpleHTTPServer.SimpleHTTPRequestHandler.__init__(self, *args, **keys)
def strip_http_headers(self,http_reply):
p = http_reply.find('\r\n\r\n')
if p >= 0:
return http_reply[p+4:]
return http_reply
def handle(self):
self.data = self.request.recv(1024).strip()
body = [ ast.literal_eval( self.strip_http_headers( self.data ) ) ]
print("DATA:", self.data)
logging.debug("Received from %s:\n%s\n%s" % (self.client_address[0], self.data, body) )
try:
tmp = Rec(asjson=body)
except:
self.request.send( "ERORE" )
return
if tmp.err():
respmsg = "Data ERROR"
else:
respmsg = "OK"
logging.debug("Created REC %s" % tmp)
self.db.add( tmp )
self.db.printall()
_responsemsg = "{}"
responsemsg = formatresponse( _responsemsg )
# print "SEND RESPONSE:", responsemsg
# self.request.sendall( responsemsg )
# self.request.send( responsemsg )
_resmsg = json.dumps({'return':'ok'})
print "SEnd BACK:" , _resmsg
#TODO: check response
#if True:
#else:
self.request.sendall( _resmsg )
return
def formatresponse( data ):
return "HTTP/1.0 200 OK\r\nContent-Type:application/json\r\nConnection:close\r\n\r\n{0}\r\n".format( data )
class MyTCPServer(SocketServer.ThreadingTCPServer):
allow_reuse_address = True
"""def handler_factory(db):
def createHandler(*args, **keys):
return ConnHandler(db, *args, **keys)
return createHandler
"""
""" MAIN SERVER """
class recserver:
def __init__(self, host="localhost", port=9999):
self.host = host
self.port = port
def start(self):
self.server = SocketServer.TCPServer((self.host, self.port), ConnHandler)
self.server = MyTCPServer((self.host, self.port), ConnHandler)
# self.server = SocketServer.TCPServer((self.host, self.port), handler_factory( self.db ) )
logging.info("Server ready to serve forever.")
try:
self.server.serve_forever()
except KeyboardInterrupt:
logging.debug("Closing Socket")
self.server.socket.close()
def testdb():
db = RecDB()
a = Rec(name="Mimmo1",starttime="ora",endtime="fine")
db.add( a )
db.printall()
db.search( Rec(name="Mimmo1") )
def loadall():
# TODO: make thread
r = recserver()
r.start()
# Loading Server
if __name__ == "__main__":
loadall()

View file

@ -180,17 +180,7 @@ class RecJob():
if self.starttime >= self.endtime:
logging.info("Starttime > Endtime (%s > %s)" % (self.starttime,self.endtime) )
return
"""print self.starttime
print self.starttime + datetime.timedelta(minutes=10)
print self.starttime.year
print self._truncate(self.starttime)
self.starttimetrunc = self._truncate(self.starttime)
print self.starttime - self.starttimetrunc
print "preleva da file "
print "Opt: %s => %s" % ( self.starttime, self.endtime )
print self._get_recfile(self.starttime)
"""
start = self.starttime
end = self.endtime
app = self.starttime