Ejemplo n.º 1
0
def do_showplot(environ,start_response):
    import config
    d = cgi.parse_qs(environ['QUERY_STRING'])
    
    if 'id' in d:
        from mod_flow import filedb
        import postgresops
        try :
            filedb.connect();
            postgresops.check_evil(d['id'][0])
            files = filedb.get_files(where = 'id = %s'%d['id'][0])
            if ( len(files) != 1): 
                raise Exception("Error 0 or >1 files matched!")
            else:
                f = tempfile.NamedTemporaryFile(delete = False)
                fname = f.name
                f.close();
                cmdline = str(config.map['web']['plotcsvcmd'] + "-csvin %s -pngout %s -title \"Source:%s ID:%s Filters:%s\"" %(files[0].file_name,fname,files[0].source_name,files[0].source_id,files[0].steps))
                cmds = shlex.split(cmdline)
                subprocess.call(cmds)
                if os.path.getsize(fname) == 0:
                    raise Exception("Plot file not created. Error plotting?")
                
                start_response('200 OK',[('Content-Type','image/png')])
                return TempFileWrapper(fname);
        except Exception,exp:
            import traceback
            start_response('500 ERROR',[('Content-Type','text/plain')])
            return ["Exception "+str(exp)+" occured\n",traceback.format_exc()]
Ejemplo n.º 2
0
def flush_files():
    scheduledb.connect()
    filedb.connect()
    
    idstokill = []
    postgresops.dbcur.execute("select id from flows.files where status=%s",(filedb.FAIL,))
    idstokill.extend([i[0] for i in postgresops.dbcur])
    
    postgresops.dbcur.execute("select id,task_id from flows.files where status=%s",(filedb.INVALID,))
    rows = postgresops.dbcur.fetchall()
    for id,task_id in rows:
        postgresops.dbcur.execute("select status from schedule.tasks where id=%s",(task_id,))
        if ( postgresops.dbcur.rowcount <= 0 or postgresops.dbcur.fetchone()[0] >= scheduledb.ERROR_CRASH ):
            idstokill.append(id)
            
    if len(idstokill)==0: return
    
    if not autoconfirm:
        print "The following files will be removed from the cache: ",idstokill
        conf = raw_input("Confirm [y|n]? ")
        if ( conf != 'y' and conf != 'yes'):
            print "Cancelled by user"
            sys.exit(10)
            
    for id in idstokill:
        str = postgresops.dbcur.mogrify("DELETE FROM flows.files WHERE id=%s",(id,))
        print str
        postgresops.dbcur.execute(str)
        
    postgresops.dbcon.commit()
    print "";
Ejemplo n.º 3
0
def flush_flows():
    scheduledb.connect()
    filedb.connect()
    flowdb.connect()
    
    postgresops.dbcur.execute("select flowdef,time_from,time_to,source_name,source_id from flows.curflows where status=%s",(flowdb.ERROR,))
    idstokill = []
    idstokill.extend(postgresops.dbcur.fetchall())
    
    postgresops.dbcur.execute("select flowdef,time_from,time_to,source_name,source_id,task_ids,file_ids from flows.curflows where status!=%s",(flowdb.DONE,))
    rows = postgresops.dbcur.fetchall()
    for flowdef,time_from,time_to,source_name,source_id,task_ids,file_ids in rows:
        found_death= False
        for task_id in task_ids:
            postgresops.dbcur.execute("select status from schedule.tasks where id=%s",(task_id,))
            if ( postgresops.dbcur.rowcount <= 0 or postgresops.dbcur.fetchone()[0] >= scheduledb.ERROR_CRASH ):
                idstokill.append((flowdef,time_from,time_to,source_name,source_id))
                found_death = True
                break
        
        if found_death:
            continue
        
        for file_id in file_ids:
            postgresops.dbcur.execute("select status from flows.files where id=%s",(file_id,))
            if ( postgresops.dbcur.rowcount <= 0 or postgresops.dbcur.fetchone()[0] == filedb.FAIL ):
                idstokill.append((flowdef,time_from,time_to,source_name,source_id))
                found_death = True
                break
            
    if len(idstokill)==0: return

    if not autoconfirm:
        print "The following flows will be removed from the database:\n"+"\n\t".join([i.__str__() for i in idstokill])
        conf = raw_input("Confirm [y|n]? ")
        if ( conf != 'y' and conf != 'yes'):
            print "Cancelled by user"
            sys.exit(10)
            
    for flowdef,time_from,time_to,source_name,source_id in idstokill:
        str = postgresops.dbcur.mogrify("DELETE FROM flows.curflows WHERE flowdef=%s and time_from=%s and time_to=%s and source_name=%s and source_id=%s",
                                        (flowdef,time_from,time_to,source_name,source_id))
        print str
        postgresops.dbcur.execute(str)
        
    postgresops.dbcon.commit()
    print "";