<s> import argparse <EOL> import sys <EOL> import re <EOL> import json <EOL> import requests <EOL> from models import auth <EOL> import pprint <EOL> def create ( config , args ) : <EOL> pp = pprint . PrettyPrinter ( ) <EOL> url = config [ '<STR_LIT:url>' ] + "<STR_LIT>" <EOL> data = { <EOL> "<STR_LIT:name>" : args [ '<STR_LIT:name>' ] , <EOL> "<STR_LIT:description>" : args [ '<STR_LIT:description>' ] , <EOL> } <EOL> token = auth . get_token ( config ) <EOL> r = requests . post ( url , data = json . dumps ( data ) , headers = { "<STR_LIT>" : token } ) <EOL> if r . status_code != <NUM_LIT:200> : <EOL> print ( "<STR_LIT>" % ( r . status_code ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> pp . pprint ( json . loads ( r . content ) ) <EOL> def read ( config , args ) : <EOL> pp = pprint . PrettyPrinter ( ) <EOL> url = config [ '<STR_LIT:url>' ] + "<STR_LIT>" <EOL> if ( args [ '<STR_LIT:all>' ] is False ) and ( args [ '<STR_LIT>' ] is None ) : <EOL> print ( "<STR_LIT>" ) <EOL> return <EOL> elif args [ '<STR_LIT>' ] is not None : <EOL> url += args [ '<STR_LIT>' ] + "<STR_LIT:/>" <EOL> token = auth . get_token ( config ) <EOL> r = requests . get ( url , headers = { "<STR_LIT>" : token } ) <EOL> if r . status_code != <NUM_LIT:200> : <EOL> print ( "<STR_LIT>" % ( r . status_code ) ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> else : <EOL> testplans = json . loads ( r . content ) <EOL> pp . pprint ( testplans ) <EOL> def update ( config , args ) : <EOL> url = config [ '<STR_LIT:url>' ] + "<STR_LIT>" + args [ '<STR_LIT>' ] + "<STR_LIT:/>" <EOL> data = { } <EOL> if args [ '<STR_LIT:name>' ] is not None : <EOL> data [ '<STR_LIT:name>' ] = args [ '<STR_LIT:name>' ] <EOL> if args [ '<STR_LIT:description>' ] is not None : <EOL> data [ '<STR_LIT:description>' ] = args [ '<STR_LIT:description>' ] <EOL> token = auth . get_token ( config ) <EOL> r = requests . put ( url , data = json . dumps ( data ) , headers = { "<STR_LIT>" : token } ) <EOL> print ( "<STR_LIT>" % ( r . status_code ) ) <EOL> def delete ( config , args ) : <EOL> url = config [ '<STR_LIT:url>' ] + "<STR_LIT>" + args [ '<STR_LIT>' ] + "<STR_LIT:/>" <EOL> token = auth . get_token ( config ) <EOL> r = requests . delete ( url , headers = { "<STR_LIT>" : token } ) <EOL> print ( "<STR_LIT>" % ( r . status_code ) ) <EOL> def main ( config , args ) : <EOL> description = "<STR_LIT>" <EOL> m = re . match ( r'<STR_LIT>' , __name__ ) <EOL> controller_name = m . groups ( ) [ <NUM_LIT:0> ] <EOL> del sys . argv [ <NUM_LIT:1> ] <EOL> parser = argparse . ArgumentParser ( prog = "<STR_LIT>" % ( sys . argv [ <NUM_LIT:0> ] , controller_name ) , description = description ) <EOL> subparsers = parser . add_subparsers ( dest = "<STR_LIT:action>" ) <EOL> create_parser = subparsers . add_parser ( "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> create_parser_required = create_parser . add_argument_group ( "<STR_LIT>" ) <EOL> create_parser_required . add_argument ( "<STR_LIT>" , type = str , required = True ) <EOL> create_parser . add_argument ( "<STR_LIT>" , type = str ) <EOL> read_parser = subparsers . add_parser ( "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> read_parser . add_argument ( "<STR_LIT>" , action = "<STR_LIT>" , const = True , default = False , help = "<STR_LIT>" ) <EOL> read_parser . add_argument ( "<STR_LIT>" , type = str , help = "<STR_LIT>" ) <EOL> update_parser = subparsers . add_parser ( "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> update_parser_required = update_parser . add_argument_group ( "<STR_LIT>" ) <EOL> update_parser_required . add_argument ( "<STR_LIT>" , type = str , required = True , help = "<STR_LIT>" ) <EOL> update_parser . add_argument ( "<STR_LIT>" , type = str ) <EOL> update_parser . add_argument ( "<STR_LIT>" , type = str ) <EOL> delete_parser = subparsers . add_parser ( "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> delete_parser_required = delete_parser . add_argument_group ( "<STR_LIT>" ) <EOL> delete_parser_required . add_argument ( "<STR_LIT>" , type = str , required = True , help = "<STR_LIT>" ) <EOL> args = vars ( parser . parse_args ( ) ) <EOL> action_map = { <EOL> "<STR_LIT>" : create , <EOL> "<STR_LIT>" : read , <EOL> "<STR_LIT>" : update , <EOL> "<STR_LIT>" : delete , <EOL> } <EOL> action_map [ args [ '<STR_LIT:action>' ] ] ( config , args ) </s>
