@@ -131,11 +131,18 @@ def formatter(prog):
131131 " --create-folders=ON CONFIG ADD --config-name=/detectors/imaging/eiger_config \\ \n "
132132 " --file-name=eiger_pvs.sav --file-format=autosave\n "
133133 "\n "
134- " Update an existing configuration node named 'eiger_config'. Load the list of PVs\n "
134+ " Update the existing configuration node named 'eiger_config'. Load the list of PVs\n "
135135 " from the file ``eiger_pvs.sav``:\n "
136136 "\n "
137137 " save-and-restore --base-url http://localhost:8080/save-restore --user-name=user \\ \n "
138138 " CONFIG UPDATE --config-name /detectors/imaging/eiger_config \\ \n "
139+ " --file-name eiger_pvs.sav --file-format autosave\n "
140+ "\n "
141+ " Add new or update the existing configuration node named 'eiger_config'. Load the list of PVs\n "
142+ " from the file ``eiger_pvs.sav``:\n "
143+ "\n "
144+ " save-and-restore --base-url http://localhost:8080/save-restore --user-name=user \\ \n "
145+ " CONFIG ADD-OR-UPDATE --config-name /detectors/imaging/eiger_config \\ \n "
139146 " --file-name eiger_pvs.sav --file-format autosave\n " ,
140147 formatter_class = formatter ,
141148 )
@@ -301,6 +308,46 @@ def formatter(prog):
301308 "Default: '%(default)s'." ,
302309 )
303310
311+ parser_config_add_or_update = subparser_config_operation .add_parser (
312+ "ADD-OR-UPDATE" , help = "Add a new or update the existing configuration node."
313+ )
314+
315+ parser_config_add_or_update .add_argument (
316+ "--config-name" ,
317+ dest = "config_name" ,
318+ type = str ,
319+ default = None ,
320+ help = "Configuration name including folders, e.g. /detectors/imaging/eiger_config" ,
321+ )
322+
323+ parser_config_add_or_update .add_argument (
324+ "--file-name" ,
325+ "-f" ,
326+ dest = "file_name" ,
327+ type = str ,
328+ default = None ,
329+ help = "Name of the file used as a source of PV names." ,
330+ )
331+
332+ parser_config_add_or_update .add_argument (
333+ "--file-format" ,
334+ dest = "file_format" ,
335+ type = str ,
336+ choices = ["autosave" ],
337+ default = "autosave" ,
338+ help = "Format of the file specified by '--file-name'. Default: '%(default)s'" ,
339+ )
340+
341+ parser_config_add_or_update .add_argument (
342+ "--show-data" ,
343+ dest = "show_data" ,
344+ type = str ,
345+ choices = ["ON" , "OFF" ],
346+ default = "OFF" ,
347+ help = "Print the loaded config data. The config node information is always printed. "
348+ "Default: '%(default)s'." ,
349+ )
350+
304351 class ExitOnError (Exception ):
305352 pass
306353
@@ -333,23 +380,7 @@ class ExitOnError(Exception):
333380 parser_config_get .print_help ()
334381 raise ExitOnError ()
335382
336- elif args .operation == "ADD" :
337- settings .operation = args .operation
338- settings .config_name = args .config_name
339- settings .file_name = args .file_name
340- settings .file_format = args .file_format
341- settings .show_data = args .show_data == "ON"
342- success = True
343- if not settings .config_name :
344- logger .error ("Required '--config-name' parameter is not specified" )
345- success = False
346- if not settings .file_name :
347- logger .error ("Required '--file-name' ('-f') parameter is not specified" )
348- success = False
349- if not success :
350- parser_config_add .print_help ()
351- raise ExitOnError ()
352- elif args .operation == "UPDATE" :
383+ elif args .operation in ("ADD" , "UPDATE" , "ADD-OR-UPDATE" ):
353384 settings .operation = args .operation
354385 settings .config_name = args .config_name
355386 settings .file_name = args .file_name
@@ -653,7 +684,7 @@ def process_config_command(settings):
653684 if settings .show_data :
654685 print (f"Config data:\n { pprint .pformat (config_data )} " )
655686
656- elif settings .operation == "ADD" :
687+ elif settings .operation == "ADD" or ( settings . operation == "ADD-OR-UPDATE" and not node_uid ) :
657688 logger .debug ("Executing 'CONFIG ADD' operation ..." )
658689 if node_uid :
659690 raise RuntimeError (f"Config node { settings .config_name !r} already exists." )
@@ -686,8 +717,8 @@ def process_config_command(settings):
686717 if settings .show_data :
687718 print (f"Config data:\n { pprint .pformat (response ['configurationData' ])} " )
688719
689- elif settings .operation == "UPDATE" :
690- logger .debug ("Executing 'CONFIG UPDATE ' operation ..." )
720+ elif settings .operation == "UPDATE" or ( settings . operation == "ADD-OR-UPDATE" and node_uid ) :
721+ logger .debug (f "Executing 'CONFIG { settings . operation } ' operation ..." )
691722 if not node_uid :
692723 raise RuntimeError (f"Config node { settings .config_name !r} does not exist." )
693724
0 commit comments