<s> import libinit <EOL> import probedb . standalone <EOL> import probedb . cluster . models as Cluster <EOL> import probedb . scanner . models as Scanner <EOL> import os , time , subprocess , datetime <EOL> from optparse import OptionParser <EOL> from django . db import connection , transaction <EOL> @ transaction . commit_manually <EOL> def main ( ) : <EOL> """<STR_LIT>""" <EOL> computername = os . environ . get ( '<STR_LIT>' , "<STR_LIT>" ) . lower ( ) <EOL> if computername == "<STR_LIT>" : <EOL> computername = os . environ . get ( '<STR_LIT>' , "<STR_LIT>" ) . lower ( ) <EOL> if computername == "<STR_LIT>" : <EOL> raise Exception ( "<STR_LIT>" ) <EOL> computername = computername . partition ( '<STR_LIT:.>' ) [ <NUM_LIT:0> ] <EOL> options_config = OptionParser ( ) <EOL> options_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> options_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> options_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> options_config . add_option ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , dest = "<STR_LIT>" ) <EOL> ( options , args ) = options_config . parse_args ( ) <EOL> while True : <EOL> master_configuration , created = Cluster . ClusterNode . objects . get_or_create ( hostname = "<STR_LIT>" , defaults = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> configuration , created = Cluster . ClusterNode . objects . get_or_create ( hostname = computername , defaults = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> configuration . save ( ) <EOL> transaction . commit ( ) <EOL> done_something = False <EOL> if Cluster . ClusterRun . objects . filter ( enabled = True ) . count ( ) > <NUM_LIT:0> : <EOL> """<STR_LIT>""" <EOL> done_something = True <EOL> if master_configuration . active_node and configuration . active_node : <EOL> if not options . nogit : <EOL> """<STR_LIT>""" <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , ] ) <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> master_branch = "<STR_LIT>" if options . use_testbase2 else "<STR_LIT>" <EOL> run = Cluster . ClusterRun . objects . filter ( enabled = True ) . order_by ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> branch = run . perform_run . branch <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , branch if branch else master_branch ] ) <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> try : <EOL> connection . close ( ) <EOL> except : <EOL> pass <EOL> """<STR_LIT>""" <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> + ( [ "<STR_LIT>" ] if options . use_testbase2 else [ ] ) <EOL> + ( [ "<STR_LIT>" ] if options . verbose else [ ] ) <EOL> , shell = False ) <EOL> else : <EOL> try : <EOL> connection . close ( ) <EOL> except : <EOL> pass <EOL> time . sleep ( <NUM_LIT:30> ) <EOL> else : <EOL> master_configuration , created = Scanner . ScannerNode . objects . get_or_create ( hostname = "<STR_LIT>" , defaults = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> configuration , created = Scanner . ScannerNode . objects . get_or_create ( hostname = computername , defaults = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : True , <EOL> } ) <EOL> configuration . save ( ) <EOL> transaction . commit ( ) <EOL> if ( master_configuration . active_node and configuration . active_node and <EOL> Scanner . ScannerRun . objects . filter ( enabled = True ) . count ( ) > <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> done_something = True <EOL> if master_configuration . active_node and configuration . active_node : <EOL> if not options . nogit : <EOL> """<STR_LIT>""" <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , ] ) <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> master_branch = "<STR_LIT>" if options . use_testbase2 else "<STR_LIT>" <EOL> run = Scanner . ScannerRun . objects . filter ( enabled = True ) . order_by ( "<STR_LIT>" , "<STR_LIT>" ) [ <NUM_LIT:0> ] <EOL> branch = run . branch <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , branch if branch else master_branch ] ) <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> try : <EOL> connection . close ( ) <EOL> except : <EOL> pass <EOL> """<STR_LIT>""" <EOL> subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ] <EOL> + ( [ "<STR_LIT>" ] if options . use_testbase2 else [ ] ) <EOL> + ( [ "<STR_LIT>" ] if options . verbose else [ ] ) <EOL> , cwd = "<STR_LIT>" <EOL> , shell = False ) <EOL> else : <EOL> try : <EOL> connection . close ( ) <EOL> except : <EOL> pass <EOL> time . sleep ( <NUM_LIT:30> ) <EOL> if not done_something : <EOL> if not options . persistent : <EOL> break ; <EOL> try : <EOL> connection . close ( ) <EOL> except : <EOL> pass <EOL> time . sleep ( <NUM_LIT:10> * <NUM_LIT> ) <EOL> main ( ) </s>
