@@ -64,9 +64,11 @@ class Report(object):
6464 The full report object
6565 """
6666
67- def __init__ (self , path , config , out_dir , run_uuid , out_filename = 'report.html' ,
67+ def __init__ (self , reportlets_dir , config , out_dir , run_uuid ,
68+ subject_id = None ,
69+ out_filename = 'report.html' ,
6870 sentry_sdk = None ):
69- self .root = path
71+ self .root = reportlets_dir
7072 self .sections = []
7173 self .errors = []
7274 self .out_dir = Path (out_dir )
@@ -75,18 +77,28 @@ def __init__(self, path, config, out_dir, run_uuid, out_filename='report.html',
7577 self .sentry_sdk = sentry_sdk
7678 self .template_path = None
7779 self .packagename = None
80+ self .subject_id = subject_id
81+ if subject_id is not None and subject_id .startswith ('sub-' ):
82+ self .subject_id = self .subject_id [4 :]
83+
84+ if self .subject_id is not None :
85+ self .out_filename = 'sub-{}.html' .format (self .subject_id )
7886
7987 self ._load_config (config )
8088
8189 def _load_config (self , config ):
8290 config = Path (config )
8391 with config .open ('r' ) as configfh :
8492 settings = json .load (configfh )
85-
8693 self .packagename = settings .get ('package' , None )
87- if self .packagename :
94+
95+ if self .packagename is not None :
96+ self .root = self .root / self .packagename
8897 self .out_dir = self .out_dir / self .packagename
8998
99+ if self .subject_id is not None :
100+ self .root = self .root / 'sub-{}' .format (self .subject_id )
101+
90102 template_path = Path (settings .get ('template_path' , 'report.tpl' ))
91103 if not str (template_path ).startswith ('/' ):
92104 template_path = config .parent / template_path
@@ -95,9 +107,8 @@ def _load_config(self, config):
95107
96108 def index (self , config ):
97109 fig_dir = 'figures'
98- subject_dir = self .root .split ('/' )[- 1 ]
99- subject = re .search ('^(?P<subject_id>sub-[a-zA-Z0-9]+)$' , subject_dir ).group ()
100- svg_dir = self .out_dir / self .packagename / subject / fig_dir
110+ subject = 'sub-{}' .format (self .subject_id )
111+ svg_dir = self .out_dir / subject / fig_dir
101112 svg_dir .mkdir (parents = True , exist_ok = True )
102113 reportlet_list = list (sorted ([str (f ) for f in Path (self .root ).glob ('**/*.*' )]))
103114
@@ -350,10 +361,8 @@ def run_reports(reportlets_dir, out_dir, subject_label, run_uuid, config,
350361 >>> tmpdir.cleanup()
351362
352363 """
353- reportlet_path = Path (reportlets_dir )
354- reportlet_path = str (reportlet_path / ("sub-%s" % subject_label ))
355- out_filename = 'sub-{}.html' .format (subject_label )
356- report = Report (reportlet_path , config , out_dir , run_uuid , out_filename ,
364+ report = Report (Path (reportlets_dir ), config , out_dir , run_uuid ,
365+ subject_id = subject_label ,
357366 sentry_sdk = sentry_sdk )
358367 return report .generate_report ()
359368
0 commit comments