<s> import argparse <EOL> import datetime <EOL> import httplib <EOL> import json <EOL> import random <EOL> import sys <EOL> from lib . texttable import texttable <EOL> def main ( args = None ) : <EOL> parser = argparse . ArgumentParser ( prog = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , default = "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , default = False , <EOL> help = "<STR_LIT>" ) <EOL> group = parser . add_mutually_exclusive_group ( required = True ) <EOL> group . add_argument ( "<STR_LIT>" , const = <NUM_LIT:1> , metavar = "<STR_LIT>" , nargs = "<STR_LIT:?>" , type = int , <EOL> help = "<STR_LIT>" ) <EOL> group . add_argument ( "<STR_LIT>" , const = <NUM_LIT:1> , metavar = "<STR_LIT>" , nargs = "<STR_LIT:?>" , type = int , <EOL> help = "<STR_LIT>" ) <EOL> group . add_argument ( "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> group . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> group . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , help = "<STR_LIT>" ) <EOL> group . add_argument ( "<STR_LIT>" , metavar = "<STR_LIT>" , <EOL> help = "<STR_LIT>" ) <EOL> group . add_argument ( "<STR_LIT>" , action = "<STR_LIT:store_true>" , <EOL> help = "<STR_LIT>" ) <EOL> args = parser . parse_args ( args ) <EOL> if args . create != None : <EOL> payload = { <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> headers = { "<STR_LIT>" : "<STR_LIT:application/json>" } <EOL> connection = httplib . HTTPConnection ( args . hostname ) <EOL> for i in range ( args . create ) : <EOL> now = datetime . datetime . utcnow ( ) <EOL> payload [ "<STR_LIT:name>" ] = "<STR_LIT>" % ( ( now - datetime . datetime . utcfromtimestamp ( <NUM_LIT:0> ) ) . total_seconds ( ) * <NUM_LIT:1000> ) <EOL> payload [ "<STR_LIT>" ] = "<STR_LIT>" % now . isoformat ( ) <EOL> connection . request ( "<STR_LIT:POST>" , "<STR_LIT>" , json . dumps ( payload ) , headers ) <EOL> connection . getresponse ( ) . read ( ) <EOL> connection . close ( ) <EOL> print "<STR_LIT>" % args . create <EOL> elif args . createforest != None : <EOL> p1 = <NUM_LIT> <EOL> p2 = <NUM_LIT> <EOL> available_parents = <NUM_LIT:0> <EOL> static_payload = { <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" <EOL> } <EOL> headers = { "<STR_LIT>" : "<STR_LIT:application/json>" } <EOL> connection = httplib . HTTPConnection ( args . hostname ) <EOL> payloads = [ ] <EOL> for i in range ( args . createforest ) : <EOL> now = datetime . datetime . utcnow ( ) <EOL> payload = dict ( static_payload ) <EOL> payload [ "<STR_LIT:name>" ] = "<STR_LIT>" % ( ( now - datetime . datetime . utcfromtimestamp ( <NUM_LIT:0> ) ) . total_seconds ( ) * <NUM_LIT:1000> ) <EOL> if random . random ( ) < p2 and available_parents > <NUM_LIT:2> : <EOL> payload [ "<STR_LIT>" ] = [ obj [ '<STR_LIT:name>' ] for obj in random . sample ( payloads , <NUM_LIT:2> ) ] <EOL> available_parents += <NUM_LIT:1> <EOL> url = "<STR_LIT>" <EOL> elif random . random ( ) < p1 and available_parents > <NUM_LIT:1> : <EOL> payload [ "<STR_LIT>" ] = [ obj [ '<STR_LIT:name>' ] for obj in random . sample ( payloads , <NUM_LIT:1> ) ] <EOL> available_parents += <NUM_LIT:1> <EOL> url = "<STR_LIT>" <EOL> else : <EOL> available_parents += <NUM_LIT:1> <EOL> payload [ "<STR_LIT>" ] = "<STR_LIT>" % now . isoformat ( ) <EOL> url = "<STR_LIT>" <EOL> payloads . append ( payload ) <EOL> connection . request ( "<STR_LIT:POST>" , url , json . dumps ( payload ) , headers ) <EOL> connection . getresponse ( ) . read ( ) <EOL> connection . close ( ) <EOL> print "<STR_LIT>" % args . createforest <EOL> elif args . delete != None : <EOL> connection = httplib . HTTPConnection ( args . hostname ) <EOL> connection . request ( "<STR_LIT>" , "<STR_LIT>" % args . delete ) <EOL> response = connection . getresponse ( ) <EOL> connection . close ( ) <EOL> if <NUM_LIT:200> <= response . status < <NUM_LIT> : <EOL> print "<STR_LIT>" % args . delete <EOL> else : <EOL> print "<STR_LIT>" % args . delete <EOL> elif args . deleteall : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> choice = raw_input ( ) <EOL> if choice == "<STR_LIT:yes>" : <EOL> connection = httplib . HTTPConnection ( args . hostname ) <EOL> connection . request ( "<STR_LIT:GET>" , "<STR_LIT>" ) <EOL> response = connection . getresponse ( ) . read ( ) <EOL> jobs = json . loads ( response ) <EOL> for job in jobs : <EOL> connection . request ( "<STR_LIT>" , "<STR_LIT>" % job [ "<STR_LIT:name>" ] ) <EOL> connection . getresponse ( ) . read ( ) <EOL> connection . close ( ) <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" <EOL> elif args . list : <EOL> connection = httplib . HTTPConnection ( args . hostname ) <EOL> connection . request ( "<STR_LIT:GET>" , "<STR_LIT>" ) <EOL> response = connection . getresponse ( ) . read ( ) <EOL> connection . close ( ) <EOL> jobs = json . loads ( response ) <EOL> table = texttable . Texttable ( max_width = False ) <EOL> if args . v : <EOL> headers = [ "<STR_LIT:Name>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> else : <EOL> headers = [ "<STR_LIT:Name>" , "<STR_LIT>" , "<STR_LIT>" ] <EOL> rows = [ headers ] <EOL> for job in jobs : <EOL> if args . v : <EOL> values = [ job [ "<STR_LIT:name>" ] , job [ "<STR_LIT>" ] , job [ "<STR_LIT>" ] , job [ "<STR_LIT>" ] , <EOL> job [ "<STR_LIT>" ] , job [ "<STR_LIT>" ] ] <EOL> else : <EOL> values = [ job [ "<STR_LIT:name>" ] , job [ "<STR_LIT>" ] , job [ "<STR_LIT>" ] ] <EOL> rows . append ( values ) <EOL> table . add_rows ( rows ) <EOL> print table . draw ( ) <EOL> jobs_length = len ( jobs ) <EOL> if jobs_length == <NUM_LIT:0> : <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" % len ( jobs ) <EOL> elif args . run != None : <EOL> connection = httplib . HTTPConnection ( args . hostname ) <EOL> connection . request ( "<STR_LIT>" , "<STR_LIT>" % args . run ) <EOL> response = connection . getresponse ( ) <EOL> connection . close ( ) <EOL> if <NUM_LIT:200> <= response . status < <NUM_LIT> : <EOL> print "<STR_LIT>" % args . run <EOL> else : <EOL> print "<STR_LIT>" % args . run <EOL> elif args . runall : <EOL> sys . stdout . write ( "<STR_LIT>" ) <EOL> choice = raw_input ( ) <EOL> if choice == "<STR_LIT:yes>" : <EOL> connection = httplib . HTTPConnection ( args . hostname ) <EOL> connection . request ( "<STR_LIT:GET>" , "<STR_LIT>" ) <EOL> response = connection . getresponse ( ) . read ( ) <EOL> jobs = json . loads ( response ) <EOL> for job in jobs : <EOL> connection . request ( "<STR_LIT>" , "<STR_LIT>" % job [ "<STR_LIT:name>" ] ) <EOL> connection . getresponse ( ) . read ( ) <EOL> connection . close ( ) <EOL> print "<STR_LIT>" <EOL> else : <EOL> print "<STR_LIT>" <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
