<s> """<STR_LIT>""" <EOL> from __future__ import unicode_literals <EOL> import logging <EOL> from . . vendor import click <EOL> from . import callbacks <EOL> log = logging . getLogger ( __name__ ) <EOL> DISPLAY_FIELDS = ( <EOL> ( '<STR_LIT:id>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:name>' , '<STR_LIT:Name>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:description>' , '<STR_LIT>' ) , <EOL> ) <EOL> VERBOSE_FIELDS = ( <EOL> ( '<STR_LIT:id>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:name>' , '<STR_LIT:Name>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:description>' , '<STR_LIT>' ) , <EOL> ) <EOL> CONSTRAINT_FIELDS = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ click . group ( ) <EOL> @ click . pass_context <EOL> def cli ( ctx ) : <EOL> """<STR_LIT>""" <EOL> @ cli . command ( ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> is_flag = True , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> type = click . File ( '<STR_LIT:rb>' ) , <EOL> callback = callbacks . process_bulk_add , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> default = '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> is_flag = True , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> is_flag = True , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> default = None , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> is_flag = True , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> callback = callbacks . transform_resource_name , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' , <EOL> callback = callbacks . process_site_id , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> multiple = True , <EOL> ) <EOL> @ click . pass_context <EOL> def add ( ctx , allow_empty , bulk_add , description , display , multi , name , pattern , <EOL> resource_name , required , valid_values , site_id ) : <EOL> """<STR_LIT>""" <EOL> data = bulk_add or ctx . params <EOL> if bulk_add is None : <EOL> if name is None : <EOL> raise click . UsageError ( '<STR_LIT>' ) <EOL> if resource_name is None : <EOL> raise click . UsageError ( '<STR_LIT>' ) <EOL> data = callbacks . process_constraints ( <EOL> data , constraint_fields = CONSTRAINT_FIELDS <EOL> ) <EOL> ctx . obj . add ( data ) <EOL> @ cli . command ( ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> default = None , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> default = None , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> is_flag = True , <EOL> help = '<STR_LIT>' , <EOL> default = False , <EOL> show_default = True , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> default = None , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> callback = callbacks . transform_resource_name , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' , <EOL> callback = callbacks . process_site_id , <EOL> ) <EOL> @ click . pass_context <EOL> def list ( ctx , id , display , limit , multi , name , natural_key , offset , required , <EOL> resource_name , site_id ) : <EOL> """<STR_LIT>""" <EOL> data = ctx . params <EOL> if id is not None or all ( [ name , resource_name ] ) : <EOL> display_fields = VERBOSE_FIELDS <EOL> else : <EOL> display_fields = DISPLAY_FIELDS <EOL> ctx . obj . list ( <EOL> data , display_fields = display_fields , verbose_fields = VERBOSE_FIELDS <EOL> ) <EOL> @ cli . command ( ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' , <EOL> required = True , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' , <EOL> callback = callbacks . process_site_id , <EOL> ) <EOL> @ click . pass_context <EOL> def remove ( ctx , id , site_id ) : <EOL> """<STR_LIT>""" <EOL> data = ctx . params <EOL> ctx . obj . remove ( ** data ) <EOL> @ cli . command ( ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> default = None , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> default = None , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> default = None , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> default = None , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> default = None , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = '<STR_LIT>' , <EOL> callback = callbacks . transform_resource_name , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> type = int , <EOL> help = '<STR_LIT>' , <EOL> callback = callbacks . process_site_id , <EOL> ) <EOL> @ click . option ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> metavar = '<STR_LIT>' , <EOL> help = ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) , <EOL> multiple = True , <EOL> ) <EOL> @ click . pass_context <EOL> def update ( ctx , allow_empty , description , display , id , multi , name , pattern , <EOL> required , resource_name , site_id , valid_values ) : <EOL> """<STR_LIT>""" <EOL> if ( name and not resource_name ) or ( resource_name and not name ) : <EOL> raise click . UsageError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> elif ( not name and not resource_name ) and not id : <EOL> raise click . UsageError ( '<STR_LIT>' ) <EOL> optional_args = ( '<STR_LIT>' , '<STR_LIT:description>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> provided = [ ] <EOL> for opt in optional_args : <EOL> val = ctx . params [ opt ] <EOL> if any ( [ <EOL> val in ( True , False ) , <EOL> isinstance ( val , basestring ) , <EOL> ( isinstance ( val , tuple ) and len ( val ) > <NUM_LIT:0> ) <EOL> ] ) : <EOL> provided . append ( opt ) <EOL> if not provided : <EOL> raise click . UsageError ( <EOL> '<STR_LIT>' <EOL> ) <EOL> if any ( [ <EOL> allow_empty is not None , <EOL> isinstance ( pattern , basestring ) , <EOL> valid_values <EOL> ] ) : <EOL> log . debug ( '<STR_LIT>' ) <EOL> data = callbacks . process_constraints ( <EOL> ctx . params , constraint_fields = CONSTRAINT_FIELDS <EOL> ) <EOL> else : <EOL> data = ctx . params <EOL> ctx . obj . update ( data ) </s>
