示例#1
0
 def addFile(name,fileName,description):
     '''Called through a command called by pipeline scripts. This will add a file
     path to the database that can then be served to the client.'''
     dba = DbAccess(DB_FILE)
     sql = "INSERT INTO " + FileChecker.__DB_TABLE_PIPELINEFILES \
         + "(name,path,description) VALUES (:name,:fileName,:description)"
     params = {"name":name,"fileName":"output/" + fileName,"description":description}
     
     try:
         dba.execute(sql,True,params)
     except OperationalError:
         cprint("[ERROR] A process has the database locked.")
     
     dba.closeConn()
示例#2
0
 def wrap(self,*args,**kwargs):
     try:
        return f(self,*args,**kwargs)
     except:
        ex = sys.exc_info()
        trace = "".join(traceback.format_exception(ex[0],
                                                   ex[1],
                                                   ex[2]))
        cprint(trace)
        StatusIO.write(trace)
        errf = open(ERRORS_FILE,"w")
        errf.write(trace)
        errf.close()
        return None
示例#3
0
 def read(response,lastLine):
     '''Return, as json, all lines since lastLine. 
     
         response - the http response object passed in from quixote. 
         lastLine - the last line the client has, a value of -1 means that 
             this is the first request and the entire file contents should 
             be sent.
             
         The json returned has the following variables:
         
         error: this will be present only if an error has occured, the json
             message will contain only this variable and it will have the
             error message
         lastLine: the number of the current last line
         lines: all of the requested lines'''
     response.set_content_type("application/json")
     try:
         lastLine = int(lastLine)
     except ValueError:
         return StatusIOResponse(error="lastLine must be int\n").serialize()
     
     lines = ""
     dba = DbAccess(DB_FILE)
     sql = "SELECT id,value FROM " + StatusIO.__DB_TABLE_STATUS \
         + " WHERE id > :lastLine LIMIT " + str(StatusIO.__MAX_LINE_OUTPUT)
     params = {"lastLine":lastLine}
         
     try:
         c = dba.execute(sql,False,params)
     except OperationalError:
         cprint("[DB_READ] [ERROR] a process has the database locked.")
         dba.closeConn()
         return StatusIOResponse(error="A process has the database locked.\n").serialize()
         
     for r in c:
         lastLine = r["id"]
         lines += r["value"]
 
     dba.closeConn()
     cprint("[DB_READ] {{ %s }}" % lines)
     
     return StatusIOResponse(lastLine=lastLine,lines=lines).serialize()
示例#4
0
 def write(text):
     '''Writes specified text to db.
         
         dbPath = path to database file
         text = text to write'''
     dba = DbAccess(DB_FILE)
     
     vals = text.split("\n")
     pcount = 0
     for s in vals:
         sql = "INSERT INTO " + StatusIO.__DB_TABLE_STATUS + "(value)"
         key = "line%i" % pcount
         sql += " VALUES (:%s)" % key
         
         try:
             dba.execute(sql,True,{key:"%s\n" % s})
         except OperationalError:
             cprint("[DB_WRITE] [ERROR] a process has the database locked.")
             dba.closeConn()
             return
     
     dba.closeConn()
     cprint("[DB_WRITE] {{ %s }}" % text)
示例#5
0
    def getFiles(response,lastFileId):
        '''Return JSON with any files in the output directory.
        
            response   - the http response object pass in from quixote.
            lastFileId - id of the last file the client has
            
            JSON returned has the following values:
            
            error    - populated only if an error has occured.
            files - a dictionary of files the client should display. The
                dictionary key is the name of the file to display, the value is
                a tuple = (fileId,filePath,fileDescription)'''
        response.set_content_type("application/json")
        try:
            lastFileId = int(lastFileId)
        except ValueError:
            return fileCheckResponse(error="lastFileId must be int\n").serialize()
        
        dba = DbAccess(DB_FILE)
        sql = "SELECT * FROM " + FileChecker.__DB_TABLE_PIPELINEFILES \
            + " WHERE id > :lastFileId"
        params = {"lastFileId":lastFileId}
        
        try:
            c = dba.execute(sql,False,params)
        except OperationalError:
            cprint("[ERROR] A process has the database locked.")
        
        files = []
        
        for r in c:
            files.append({"id":r["id"],"name":r["name"],"path":r["path"],"desc":r["description"]})
        
        dba.closeConn()
        return FileCheckResponse(files=files).serialize()