#NEWLINE# @ argh_named ( 'set' ) #NEWLINE# @ arg_full_match #NEWLINE# @ argh . arg ( 'pattern' , type = str , help = 'search pattern' ) #NEWLINE# @ argh . arg ( 'setting' , type = str , nargs = '+' , help = "'name=[type:]value'" ) #NEWLINE# @ expects_obj #NEWLINE# def handle_settings_set( self , arg ) : #NEWLINE# #INDENT# 'override settings values' #NEWLINE# pattern = ( arg . pattern or '.' ) #NEWLINE# confman = self . get_confman ( arg . root_dir ) #NEWLINE# configs = list ( confman . find_config ( arg . pattern , all_configs = True , full_match = arg . full_match ) ) #NEWLINE# if ( not configs ) : #NEWLINE# #INDENT# raise errors . UserError ( ( 'no config matching %r found' % arg . pattern ) ) #NEWLINE# #UNINDENT# updates = [ ] #NEWLINE# for ( conf_node , conf ) in configs : #NEWLINE# #INDENT# if ( conf_node != conf . node ) : #NEWLINE# #INDENT# raise errors . UserError ( 'changing settings in a node-inherited config is not supported yet' ) #NEWLINE# #UNINDENT# set_list = [ ] #NEWLINE# converters = { #NEWLINE# #INDENT# 'prop' : ( ( lambda x : util . get_dict_prop ( dict ( node = conf_node , config = conf ) , x . split ( '.' ) , verify = True ) [ 1 ] ) , None ) , #NEWLINE# #UNINDENT# } #NEWLINE# props = dict ( ( util . parse_prop ( p , converters = converters ) for p in arg . setting ) ) #NEWLINE# for ( key_path , value ) in props . items ( ) : #NEWLINE# #INDENT# addr = key_path . split ( '.' ) #NEWLINE# old = util . set_dict_prop ( conf . settings , addr , value , verify = True ) #NEWLINE# if ( old != value ) : #NEWLINE# #INDENT# set_list . append ( ( addr , value ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . log . info ( '%s/%s: %r: no change' , conf_node . name , conf . name , '.' . join ( addr ) ) #NEWLINE# #UNINDENT# #UNINDENT# if set_list : #NEWLINE# #INDENT# updates . append ( ( conf , set_list ) ) #NEWLINE# #UNINDENT# #UNINDENT# layer_file = '50-user.json' #NEWLINE# for ( conf , update ) in updates : #NEWLINE# #INDENT# layer = conf . load_settings_layer ( layer_file ) #NEWLINE# for ( addr , value ) in update : #NEWLINE# #INDENT# self . log . info ( '%s: set %s to %r' , conf . full_name , '.' . join ( addr ) , value ) #NEWLINE# addr [ ( - 1 ) ] = ( '!%s' % addr [ ( - 1 ) ] ) #NEWLINE# util . set_dict_prop ( layer , addr , value , schema = conf . settings ) #NEWLINE# #UNINDENT# conf . save_settings_layer ( layer_file , layer )