<s> """<STR_LIT>""" <EOL> import functools <EOL> import hashlib <EOL> import httplib2 <EOL> import os . path <EOL> import uuid <EOL> import socket <EOL> from collections import OrderedDict <EOL> import time <EOL> from datetime import datetime <EOL> from functools import partial <EOL> import zmq <EOL> import json <EOL> import ConfigParser <EOL> from flask import ( Flask , render_template , request , redirect , abort , Response , <EOL> jsonify , make_response , session , url_for ) <EOL> from flask . ext . scrypt import generate_random_salt , generate_password_hash , check_password_hash <EOL> from apiclient . discovery import build <EOL> from oauth2client . client import ( AccessTokenRefreshError , <EOL> AccessTokenCredentials , <EOL> flow_from_clientsecrets , <EOL> FlowExchangeError ) <EOL> from app import app , app_config , db , sockets <EOL> from model import Model , UnknownUserError , UnknownTestError <EOL> from notifications import console_subscribe <EOL> from cstar_perf . frontend . lib . util import random_token <EOL> from cstar_perf . frontend . lib import screenshot , stupid_cache <EOL> from cstar_perf . frontend import SERVER_KEY_PATH <EOL> from cstar_perf . frontend . lib . crypto import APIKey <EOL> import logging <EOL> log = logging . getLogger ( '<STR_LIT>' ) <EOL> try : <EOL> authentication_type = app_config . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> except ConfigParser . NoOptionError : <EOL> authentication_type = '<STR_LIT>' <EOL> if authentication_type == '<STR_LIT>' : <EOL> pass <EOL> elif authentication_type == '<STR_LIT>' : <EOL> gplus = build ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> google_client_secrets = os . path . join ( os . path . expanduser ( "<STR_LIT>" ) , '<STR_LIT>' , '<STR_LIT>' ) <EOL> with open ( google_client_secrets ) as f : <EOL> google_client_id = json . load ( f ) [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> else : <EOL> raise AssertionError ( '<STR_LIT>' . format ( authentication_type ) ) <EOL> server_key = APIKey . load ( SERVER_KEY_PATH ) <EOL> def get_user_id ( ) : <EOL> return session . get ( '<STR_LIT>' , None ) <EOL> app . jinja_env . globals [ '<STR_LIT>' ] = get_user_id <EOL> def user_is_authenticated ( ) : <EOL> return session . get ( '<STR_LIT>' , False ) <EOL> app . jinja_env . globals [ '<STR_LIT>' ] = user_is_authenticated <EOL> def user_in_role ( role , user = None ) : <EOL> """<STR_LIT>""" <EOL> if user is None : <EOL> user = get_user_id ( ) <EOL> try : <EOL> user_roles = db . get_user_roles ( get_user_id ( ) ) <EOL> if role in user_roles : <EOL> return True <EOL> except UnknownUserError : <EOL> pass <EOL> return False <EOL> def requires_auth ( role ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( function ) : <EOL> @ functools . wraps ( function ) <EOL> def wrapper ( * args , ** kw ) : <EOL> if user_is_authenticated ( ) : <EOL> if user_in_role ( role ) : <EOL> return function ( * args , ** kw ) <EOL> return make_response ( render_template ( '<STR_LIT>' ) , <NUM_LIT> ) <EOL> return wrapper <EOL> return decorator <EOL> @ app . context_processor <EOL> def inject_template_variables ( ) : <EOL> """<STR_LIT>""" <EOL> d = { '<STR_LIT>' : db . get_cluster_names ( ) , <EOL> '<STR_LIT>' : authentication_type , <EOL> '<STR_LIT>' : None } <EOL> if authentication_type == '<STR_LIT>' : <EOL> d [ '<STR_LIT>' ] = google_client_id <EOL> return d <EOL> @ app . route ( '<STR_LIT:/>' ) <EOL> def index ( ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> def login_with_google ( ) : <EOL> """<STR_LIT>""" <EOL> log . info ( "<STR_LIT>" ) <EOL> code = request . data <EOL> try : <EOL> oauth_flow = flow_from_clientsecrets ( google_client_secrets , scope = '<STR_LIT>' ) <EOL> oauth_flow . redirect_uri = '<STR_LIT>' <EOL> credentials = oauth_flow . step2_exchange ( code ) <EOL> except FlowExchangeError : <EOL> return make_response ( <EOL> jsonify ( { '<STR_LIT:error>' : '<STR_LIT>' } ) , <NUM_LIT> ) <EOL> gplus_id = credentials . id_token [ '<STR_LIT>' ] <EOL> stored_credentials = AccessTokenCredentials ( session . get ( '<STR_LIT>' ) , <EOL> request . user_agent ) <EOL> stored_gplus_id = session . get ( '<STR_LIT>' ) <EOL> if stored_credentials is not None and gplus_id == stored_gplus_id : <EOL> return make_response ( jsonify ( <EOL> { '<STR_LIT:success>' : '<STR_LIT>' } ) , <NUM_LIT:200> ) <EOL> http = httplib2 . Http ( ) <EOL> http = credentials . authorize ( http ) <EOL> google_request = gplus . people ( ) . get ( userId = '<STR_LIT>' ) <EOL> user_obj = google_request . execute ( http = http ) <EOL> email = None <EOL> for e in user_obj [ '<STR_LIT>' ] : <EOL> if e [ '<STR_LIT:type>' ] == '<STR_LIT>' : <EOL> email = e [ '<STR_LIT:value>' ] <EOL> break <EOL> else : <EOL> return make_response ( <EOL> jsonify ( { '<STR_LIT:error>' : '<STR_LIT>' } ) , <NUM_LIT> ) <EOL> session [ '<STR_LIT>' ] = credentials . access_token <EOL> session [ '<STR_LIT>' ] = gplus_id <EOL> session [ '<STR_LIT>' ] = True <EOL> session [ '<STR_LIT>' ] = email <EOL> return make_response ( jsonify ( { '<STR_LIT:success>' : '<STR_LIT>' } ) , <EOL> <NUM_LIT:200> ) <EOL> def login_with_passphrase ( ) : <EOL> data = request . get_json ( force = True ) <EOL> log . info ( "<STR_LIT>" ) <EOL> try : <EOL> if db . validate_user_passphrase ( data [ '<STR_LIT:email>' ] , data [ '<STR_LIT>' ] ) : <EOL> session [ '<STR_LIT>' ] = True <EOL> session [ '<STR_LIT>' ] = data [ '<STR_LIT:email>' ] <EOL> return make_response ( jsonify ( { '<STR_LIT:success>' : '<STR_LIT>' } ) , <EOL> <NUM_LIT:200> ) <EOL> except UnknownUserError : <EOL> pass <EOL> return make_response ( jsonify ( { '<STR_LIT:error>' : '<STR_LIT>' } ) , <NUM_LIT> ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> def login ( ) : <EOL> """<STR_LIT>""" <EOL> if authentication_type == '<STR_LIT>' : <EOL> return login_with_passphrase ( ) <EOL> elif authentication_type == '<STR_LIT>' : <EOL> return login_with_google ( ) <EOL> else : <EOL> raise AssertionError ( '<STR_LIT>' . format ( authentication_type ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def logout ( ) : <EOL> for i in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> try : <EOL> session . pop ( i ) <EOL> except KeyError : <EOL> pass <EOL> if request . method == "<STR_LIT:POST>" : <EOL> return make_response ( jsonify ( { '<STR_LIT:success>' : '<STR_LIT>' } ) , <NUM_LIT:200> ) <EOL> else : <EOL> return redirect ( "<STR_LIT:/>" ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def tests ( ) : <EOL> clusters = db . get_cluster_names ( ) <EOL> cluster_scheduled_tests = { } <EOL> cluster_in_progress_tests = { } <EOL> for c in clusters : <EOL> scheduled_tests = db . get_scheduled_tests ( c ) <EOL> if len ( scheduled_tests ) > <NUM_LIT:0> : <EOL> cluster_scheduled_tests [ c ] = scheduled_tests <EOL> in_progress_tests = db . get_in_progress_tests ( c ) <EOL> if len ( in_progress_tests ) > <NUM_LIT:0> : <EOL> cluster_in_progress_tests [ c ] = in_progress_tests <EOL> completed_tests = db . get_completed_tests ( ) <EOL> return render_template ( '<STR_LIT>' , clusters = clusters , <EOL> cluster_scheduled_tests = cluster_scheduled_tests , <EOL> cluster_in_progress_tests = cluster_in_progress_tests , <EOL> completed_tests = completed_tests ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> def my_tests ( ) : <EOL> queued_tests = db . get_user_scheduled_tests ( get_user_id ( ) ) <EOL> in_progress_tests = db . get_user_in_progress_tests ( get_user_id ( ) ) <EOL> completed_tests = db . get_user_completed_tests ( get_user_id ( ) ) <EOL> failed_tests = db . get_user_failed_tests ( get_user_id ( ) , <NUM_LIT:10> ) <EOL> return render_template ( '<STR_LIT>' , queued_tests = queued_tests , <EOL> in_progress_tests = in_progress_tests , <EOL> completed_tests = completed_tests , <EOL> failed_tests = failed_tests ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def view_test ( test_id ) : <EOL> try : <EOL> test = db . get_test ( test_id ) <EOL> except UnknownTestError : <EOL> return make_response ( '<STR_LIT>' . format ( test_id = test_id ) , <NUM_LIT> ) <EOL> artifacts = db . get_test_artifacts ( test_id ) <EOL> has_chart = False <EOL> for a in artifacts : <EOL> if a [ '<STR_LIT>' ] in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> a [ '<STR_LIT>' ] = db . get_test_artifact_data ( test_id , a [ '<STR_LIT>' ] , a [ '<STR_LIT:name>' ] ) <EOL> if a [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> has_chart = True <EOL> return render_template ( '<STR_LIT>' , test = test , artifacts = artifacts , has_chart = has_chart ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_artifact ( test_id , artifact_type , artifact_name = None ) : <EOL> if artifact_type == '<STR_LIT>' : <EOL> return redirect ( "<STR_LIT>" . format ( test_id = test_id ) ) <EOL> elif artifact_type == '<STR_LIT>' and not artifact_name : <EOL> artifacts = db . get_test_artifacts ( test_id , artifact_type ) <EOL> for artifact in artifacts : <EOL> artifact [ '<STR_LIT:data>' ] = db . get_test_artifact_data ( test_id , artifact_type , artifact [ '<STR_LIT:name>' ] ) <EOL> return render_template ( '<STR_LIT>' , test_id = test_id , artifacts = artifacts ) <EOL> if not artifact_name : <EOL> return make_response ( jsonify ( { '<STR_LIT:error>' : '<STR_LIT>' } ) , <NUM_LIT> ) <EOL> artifact , object_id , artifact_available = db . get_test_artifact_data ( test_id , artifact_type , artifact_name ) <EOL> if artifact_name . endswith ( "<STR_LIT>" ) : <EOL> mimetype = '<STR_LIT>' <EOL> elif artifact_name . endswith ( "<STR_LIT>" ) : <EOL> mimetype = '<STR_LIT:application/json>' <EOL> elif artifact_name . endswith ( "<STR_LIT>" ) : <EOL> mimetype = '<STR_LIT>' <EOL> else : <EOL> mimetype = '<STR_LIT>' <EOL> if artifact is None and object_id is not None and artifact_available : <EOL> artifact = db . generate_object_by_chunks ( object_id ) <EOL> return Response ( response = artifact , <EOL> status = <NUM_LIT:200> , <EOL> mimetype = mimetype , <EOL> headers = { "<STR_LIT>" : "<STR_LIT>" . format ( name = artifact_name ) } ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def graph ( ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> def schedule ( ) : <EOL> """<STR_LIT>""" <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> def cluster ( cluster_name ) : <EOL> return render_template ( '<STR_LIT>' , <EOL> cluster_name = cluster_name ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' ] ) <EOL> def cluster_specs ( ) : <EOL> return render_template ( '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:GET>' , '<STR_LIT:POST>' ] ) <EOL> def login_for_apps ( ) : <EOL> """<STR_LIT>""" <EOL> if request . method == "<STR_LIT:GET>" : <EOL> session [ '<STR_LIT>' ] = random_token ( ) <EOL> session [ '<STR_LIT>' ] = False <EOL> return jsonify ( { "<STR_LIT>" : session [ '<STR_LIT>' ] , <EOL> "<STR_LIT>" : server_key . sign_message ( session [ '<STR_LIT>' ] ) } ) <EOL> elif request . method == "<STR_LIT:POST>" : <EOL> data = request . get_json ( ) <EOL> pubkey = APIKey ( db . get_pub_key ( data [ '<STR_LIT>' ] ) [ '<STR_LIT>' ] ) <EOL> try : <EOL> pubkey . verify_message ( session [ '<STR_LIT>' ] , data [ '<STR_LIT>' ] ) <EOL> except Exception , e : <EOL> session [ '<STR_LIT>' ] = False <EOL> del session [ '<STR_LIT>' ] <EOL> return make_response ( jsonify ( { '<STR_LIT:error>' : '<STR_LIT>' } ) , <NUM_LIT> ) <EOL> session [ '<STR_LIT>' ] = data [ '<STR_LIT>' ] <EOL> session [ '<STR_LIT>' ] = True <EOL> session [ '<STR_LIT>' ] = True <EOL> return jsonify ( { '<STR_LIT:success>' : '<STR_LIT>' } ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> def schedule_test ( ) : <EOL> """<STR_LIT>""" <EOL> job = request . get_json ( ) <EOL> job_id = uuid . uuid1 ( ) <EOL> job [ '<STR_LIT>' ] = str ( job_id ) <EOL> job [ '<STR_LIT:user>' ] = get_user_id ( ) <EOL> test_series = job . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> if not test_series : <EOL> test_series = '<STR_LIT>' <EOL> db . schedule_test ( test_id = job_id , test_series = test_series , user = job [ '<STR_LIT:user>' ] , <EOL> cluster = job [ '<STR_LIT>' ] , test_definition = job ) <EOL> return jsonify ( { '<STR_LIT:success>' : True , '<STR_LIT:url>' : '<STR_LIT>' . format ( test_id = job [ '<STR_LIT>' ] ) } ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> def cancel_test ( ) : <EOL> """<STR_LIT>""" <EOL> test_id = request . form [ '<STR_LIT>' ] <EOL> test = db . get_test ( test_id ) <EOL> new_status = '<STR_LIT>' <EOL> if test [ '<STR_LIT:status>' ] == '<STR_LIT>' or test [ '<STR_LIT:status>' ] == '<STR_LIT>' : <EOL> new_status = '<STR_LIT>' <EOL> if user_in_role ( '<STR_LIT>' ) : <EOL> db . update_test_status ( test_id , new_status ) <EOL> else : <EOL> if test [ '<STR_LIT:user>' ] == get_user_id ( ) : <EOL> db . update_test_status ( test_id , new_status ) <EOL> else : <EOL> return make_response ( jsonify ( { '<STR_LIT:error>' : '<STR_LIT>' <EOL> . format ( test_id = test_id ) } ) , <NUM_LIT> ) <EOL> return jsonify ( { '<STR_LIT:success>' : '<STR_LIT>' } ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_tests ( ) : <EOL> """<STR_LIT>""" <EOL> completed_tests = db . get_completed_tests ( ) <EOL> try : <EOL> param_from = request . args . get ( '<STR_LIT>' , None ) <EOL> param_to = request . args . get ( '<STR_LIT>' , None ) <EOL> date_from = datetime . fromtimestamp ( float ( param_from ) ) if param_from else None <EOL> date_to = datetime . fromtimestamp ( float ( param_to ) ) if param_to else None <EOL> except : <EOL> return make_response ( jsonify ( { '<STR_LIT:error>' : '<STR_LIT>' } ) , <NUM_LIT> ) <EOL> if date_from : <EOL> completed_tests = [ t for t in completed_tests if t [ '<STR_LIT>' ] >= date_from ] <EOL> if date_to : <EOL> completed_tests = [ t for t in completed_tests if t [ '<STR_LIT>' ] <= date_to ] <EOL> tests = map ( lambda t : { <EOL> '<STR_LIT>' : t [ '<STR_LIT>' ] , <EOL> '<STR_LIT>' : url_for ( '<STR_LIT>' , test_id = t [ '<STR_LIT>' ] ) <EOL> } , completed_tests ) <EOL> response = json . dumps ( obj = tests ) <EOL> return Response ( response = response , <EOL> status = <NUM_LIT:200> , <EOL> mimetype = '<STR_LIT:application/json>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> def get_test ( test_id ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> test = db . get_test ( test_id ) <EOL> return jsonify ( test ) <EOL> except UnknownTestError : <EOL> return make_response ( jsonify ( { '<STR_LIT:error>' : '<STR_LIT>' . format ( test_id = test_id ) } ) , <NUM_LIT> ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_series_list ( ) : <EOL> series = db . get_series_list ( ) <EOL> if '<STR_LIT:true>' == request . args . get ( '<STR_LIT>' , '<STR_LIT:True>' ) . lower ( ) : <EOL> response = json . dumps ( obj = series , sort_keys = True , indent = <NUM_LIT:4> , separators = ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) ) <EOL> else : <EOL> response = json . dumps ( obj = series ) <EOL> return Response ( response = response , <EOL> status = <NUM_LIT:200> , <EOL> mimetype = '<STR_LIT:application/json>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_series ( series , start_timestamp , end_timestamp ) : <EOL> series = db . get_series ( series , start_timestamp , end_timestamp ) <EOL> valid_jobs = [ job_id for job_id in series if db . get_test_status ( job_id ) == '<STR_LIT>' ] <EOL> jsobj = { '<STR_LIT>' : valid_jobs } <EOL> if '<STR_LIT:true>' == request . args . get ( '<STR_LIT>' , '<STR_LIT:True>' ) . lower ( ) : <EOL> response = json . dumps ( obj = jsobj , sort_keys = True , indent = <NUM_LIT:4> , separators = ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) ) <EOL> else : <EOL> response = json . dumps ( obj = jsobj ) <EOL> return Response ( response = response , <EOL> status = <NUM_LIT:200> , <EOL> mimetype = '<STR_LIT:application/json>' ) <EOL> def get_series_summaries_impl ( series , start_timestamp , end_timestamp ) : <EOL> series = db . get_series ( series , start_timestamp , end_timestamp ) <EOL> summaries = [ ] <EOL> for test_id in series : <EOL> status = db . get_test_status ( test_id ) <EOL> if status == '<STR_LIT>' : <EOL> artifact = db . get_test_artifact_data ( test_id , '<STR_LIT>' , '<STR_LIT>' . format ( test_id ) ) <EOL> if artifact and artifact [ <NUM_LIT:0> ] : <EOL> summaries . append ( json . loads ( artifact [ <NUM_LIT:0> ] ) ) <EOL> return summaries <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_series_summaries ( series , start_timestamp , end_timestamp ) : <EOL> summaries = get_series_summaries_impl ( series , start_timestamp , end_timestamp ) <EOL> byOperation = { } <EOL> for summary in summaries : <EOL> for stat in summary [ '<STR_LIT>' ] : <EOL> if '<STR_LIT:test>' not in stat : <EOL> log . error ( "<STR_LIT>" . format ( stat [ '<STR_LIT:id>' ] ) ) <EOL> continue <EOL> operationStats = byOperation . setdefault ( stat [ '<STR_LIT:test>' ] , { } ) <EOL> revisionStats = operationStats . setdefault ( stat [ '<STR_LIT:label>' ] , OrderedDict ( ) ) <EOL> revisionStats [ uuid . UUID ( stat [ '<STR_LIT:id>' ] ) ] = stat <EOL> del stat [ '<STR_LIT:test>' ] <EOL> del stat [ '<STR_LIT:label>' ] <EOL> summaries = { } <EOL> for operation in byOperation : <EOL> newOperation = summaries . setdefault ( operation , { } ) <EOL> for revision in byOperation [ operation ] : <EOL> newRevision = newOperation . setdefault ( revision , { } ) <EOL> for stats in byOperation [ operation ] [ revision ] . itervalues ( ) : <EOL> for key , value in stats . iteritems ( ) : <EOL> statsArray = newRevision . setdefault ( key , [ ] ) <EOL> if isinstance ( value , basestring ) : <EOL> statsArray . append ( value . split ( ) [ <NUM_LIT:0> ] ) <EOL> else : <EOL> statsArray . append ( value ) <EOL> jsobj = { '<STR_LIT>' : summaries } <EOL> if '<STR_LIT:true>' == request . args . get ( '<STR_LIT>' , '<STR_LIT:True>' ) . lower ( ) : <EOL> response = json . dumps ( obj = jsobj , sort_keys = True , indent = <NUM_LIT:4> , separators = ( '<STR_LIT:U+002C>' , '<STR_LIT>' ) ) <EOL> else : <EOL> response = json . dumps ( obj = jsobj ) <EOL> return Response ( response = response , <EOL> status = <NUM_LIT:200> , <EOL> mimetype = '<STR_LIT:application/json>' ) <EOL> def construct_series_graph_url ( series , start_timestamp , end_timestamp , operation , metric ) : <EOL> redirectURL = "<STR_LIT>" <EOL> redirectURL += "<STR_LIT>" <EOL> redirectURL += "<STR_LIT>" <EOL> redirectURL += "<STR_LIT>" <EOL> redirectURL += "<STR_LIT>" <EOL> redirectURL += "<STR_LIT>" <EOL> redirectURL += "<STR_LIT>" <EOL> redirectURL += "<STR_LIT>" <EOL> return redirectURL . format ( series = series , start_timestamp = start_timestamp , end_timestamp = end_timestamp , <EOL> operation = operation , metric = metric ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_series_graph ( series , start_timestamp , end_timestamp , operation , metric ) : <EOL> redirectURL = construct_series_graph_url ( series , start_timestamp , end_timestamp , operation , metric ) <EOL> return redirect ( redirectURL ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_series_graph_png ( series , start_timestamp , end_timestamp , operation , metric ) : <EOL> host = socket . gethostname ( ) <EOL> graphURL = "<STR_LIT>" + host + construct_series_graph_url ( series , start_timestamp , end_timestamp , operation , metric ) <EOL> return Response ( response = screenshot . get_graph_png ( graphURL , x_crop = <NUM_LIT> , y_crop = <NUM_LIT> ) , <EOL> status = <NUM_LIT:200> , <EOL> mimetype = '<STR_LIT>' ) <EOL> def get_series_graph_png_cached ( series , age , operation , metric , expires , invalidate ) : <EOL> host = socket . gethostname ( ) <EOL> end_timestamp = int ( time . time ( ) ) <EOL> start_timestamp = max ( <NUM_LIT:0> , end_timestamp - int ( age ) ) <EOL> graphURL = "<STR_LIT>" + host + construct_series_graph_url ( series , start_timestamp , end_timestamp , operation , metric ) <EOL> def loader ( ) : <EOL> return screenshot . get_graph_png ( graphURL , x_crop = <NUM_LIT> , y_crop = <NUM_LIT> ) <EOL> cache_key = series + "<STR_LIT:/>" + age + "<STR_LIT:/>" + operation + "<STR_LIT:/>" + metric <EOL> return stupid_cache . stupid_cache_get ( "<STR_LIT>" , cache_key , loader , expires , invalidate ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_series_graph_png_cached_caching ( series , age , operation , metric ) : <EOL> return Response ( response = get_series_graph_png_cached ( series , age , operation , metric , <NUM_LIT:0> , False ) , <EOL> status = <NUM_LIT:200> , <EOL> mimetype = '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> def get_series_graph_png_cached_invalidating ( series , age , operation , metric ) : <EOL> return Response ( response = get_series_graph_png_cached ( series , age , operation , metric , <NUM_LIT:0> , True ) , <EOL> status = <NUM_LIT:200> , <EOL> mimetype = '<STR_LIT>' ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> def get_test_status ( test_id ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> status = db . get_test_status ( test_id ) <EOL> return jsonify ( { '<STR_LIT:status>' : status } ) <EOL> except UnknownTestError : <EOL> return make_response ( jsonify ( { '<STR_LIT:error>' : '<STR_LIT>' . format ( test_id = test_id ) } ) , <NUM_LIT> ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> def get_clusters ( ) : <EOL> """<STR_LIT>""" <EOL> clusters = db . get_clusters ( ) <EOL> return make_response ( jsonify ( { '<STR_LIT>' : clusters } ) ) <EOL> @ app . route ( '<STR_LIT>' ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> def get_clusters_by_name ( cluster_name ) : <EOL> """<STR_LIT>""" <EOL> clusters = db . get_clusters ( ) <EOL> return make_response ( jsonify ( clusters [ cluster_name ] ) ) <EOL> @ app . route ( '<STR_LIT>' , methods = [ '<STR_LIT:POST>' ] ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> def set_progress_message_on_test ( test_id ) : <EOL> msg = request . get_json ( ) [ '<STR_LIT>' ] <EOL> db . update_test_progress_msg ( test_id , msg ) <EOL> return jsonify ( { '<STR_LIT:status>' : '<STR_LIT>' } ) <EOL> @ requires_auth ( '<STR_LIT:user>' ) <EOL> @ sockets . route ( '<STR_LIT>' ) <EOL> def console_messages ( ws ) : <EOL> """<STR_LIT>""" <EOL> cluster_name = ws . receive ( ) <EOL> console_socket = console_subscribe ( cluster_name ) <EOL> try : <EOL> while True : <EOL> try : <EOL> data = console_socket . recv_string ( ) <EOL> data = data . lstrip ( "<STR_LIT>" . format ( cluster_name = cluster_name ) ) <EOL> ws . send ( data ) <EOL> except zmq . error . Again : <EOL> ws . send ( '<STR_LIT>' ) <EOL> ws . receive ( ) <EOL> except zmq . error . ZMQError , e : <EOL> if e . errno == zmq . POLLERR : <EOL> log . error ( e ) <EOL> console_socket = setup_zmq ( ) <EOL> finally : <EOL> log . error ( "<STR_LIT>" ) <EOL> console_socket . setsockopt_string ( zmq . UNSUBSCRIBE , u'<STR_LIT>' ) </s>
