6363from capsul .api import Pipeline
6464from capsul .attributes .completion_engine import ProcessCompletionEngine
6565import os
66+ import os .path as osp
6667import logging
67- import sys , re
68+ import sys
69+ import re
6870from optparse import OptionParser , OptionGroup
6971from traits .api import Undefined , List
72+ import tempfile
73+ import subprocess
7074try :
7175 import yaml
7276except ImportError :
@@ -285,6 +289,7 @@ def main():
285289 axon-runprocess capsul://capsul.engine.write_engine_config engine.json
286290
287291 Then the file ``engine.json`` will be OK.
292+ Alternatively, using "--config axon" will do this for you internally.
288293 '''
289294
290295 # Set up logging on stderr. This must be called before any logging takes
@@ -298,9 +303,12 @@ def main():
298303 description = 'Processing configuration, database options' )
299304 group1 .add_option ('--studyconfig' , dest = 'studyconfig' ,
300305 help = 'load StudyConfig configuration from the given file (JSON)' )
301- group1 .add_option ('--config' , dest = 'config' ,
306+ group1 .add_option (
307+ '--config' , dest = 'config' ,
302308 help = 'load Capsul engine configuration from the given file (JSON) '
303- '(CapsulEngine shape, not Studyconfig -- use --studyconfig otherwise)' )
309+ '(CapsulEngine shape, not Studyconfig -- use --studyconfig '
310+ 'otherwise). Using "--config axon" will run the conversion process in '
311+ 'Axon and import the config.' )
304312 group1 .add_option ('-i' , '--input' , dest = 'input_directory' ,
305313 help = 'input data directory (if not specified in '
306314 'studyconfig file). If not specified neither on the '
@@ -311,6 +319,20 @@ def main():
311319 'studyconfig file). If not specified neither on the '
312320 'commandline nor study configfile, taken as the same as '
313321 'input.' )
322+ group1 .add_option ('--if' , '--input-fom' , dest = 'input_fom' ,
323+ default = 'morphologist-bids-1.0' ,
324+ help = 'input FOM (File Organization Model). Decides '
325+ 'which files and direrctories layout for the input '
326+ 'data. Generally "morphologist-bids-1.0" or '
327+ '"morphologist-auto-nonoverlap-1.0". Default: '
328+ '"morphologist-bids-1.0"' )
329+ group1 .add_option ('--of' , '--output-fom' , dest = 'output_fom' ,
330+ default = 'morphologist-bids-1.0' ,
331+ help = 'input FOM (File Organization Model). Decides '
332+ 'which files and direrctories layout for the output '
333+ 'data. Generally "morphologist-bids-1.0" or '
334+ '"morphologist-auto-nonoverlap-1.0". Default: '
335+ '"morphologist-bids-1.0"' )
314336 group1 .add_option ('--params' , dest = 'paramsfile' , default = None ,
315337 help = 'specify a file containing commandline parameters. '
316338 'The file will contain arguments for this commandline '
@@ -420,31 +442,44 @@ def main():
420442 setattr (options , k , v )
421443 args += new_args
422444
445+ engine = capsul_engine ()
446+ engine .load_modules (['fom' , 'axon' ])
447+ study_config = engine .study_config
448+
423449 if options .config :
424- engine = capsul_engine ()
425- with open (options .config ) as f :
450+ config_file = options .config
451+ tmp = None
452+ if not osp .exists (options .config ) and options .config == 'axon' :
453+ tmp = tempfile .mkstemp (prefix = 'capsul_conf' , suffix = '.json' )
454+ os .close (tmp [0 ])
455+ cmd = ['axon-runprocess' ,
456+ 'capsul://capsul.engine.write_engine_config' ,
457+ tmp [1 ]]
458+ subprocess .check_call (cmd )
459+ config_file = tmp [1 ]
460+ with open (config_file ) as f :
426461 if yaml :
427462 conf = yaml .load (f , Loader = yaml .SafeLoader )
428463 else :
429464 conf = json .load (f )
465+ if tmp :
466+ os .unlink (tmp [1 ])
430467 for env , c in conf .items ():
431468 engine .import_configs (env , c )
432- study_config = engine .study_config
433469 elif options .studyconfig :
434- study_config = StudyConfig (
435- modules = StudyConfig .default_modules
436- + ['FomConfig' , 'BrainVISAConfig' ])
437470 with open (options .studyconfig ) as f :
438471 if yaml :
439472 scdict = yaml .load (f , Loader = yaml .SafeLoader )
440473 else :
441474 scdict = json .load (f )
442475 study_config .set_study_configuration (scdict )
476+ engine = study_config .engine
443477 else :
444478 study_config = StudyConfig (
445479 modules = StudyConfig .default_modules + ['FomConfig' ])
446480 study_config .read_configuration ()
447481 study_config .use_fom = True
482+ engine = study_config .engine
448483
449484 if options .input_directory :
450485 study_config .input_directory = options .input_directory
@@ -461,6 +496,13 @@ def main():
461496 study_config .somaworkflow_keep_failed_workflows \
462497 = not options .delete_failed_workflow
463498
499+ with engine .settings as session :
500+ config = session .config ('fom' , 'global' )
501+ if options .input_fom is not None :
502+ config .input_fom = options .input_fom
503+ if options .output_fom is not None :
504+ config .output_fom = options .output_fom
505+
464506 kwre = re .compile (r'([a-zA-Z_](\.?[a-zA-Z0-9_])*)\s*=\s*(.*)$' )
465507
466508 attributes = {}
0 commit comments