2929# Local imports
3030from ... import logging
3131from ...utils import spm_docs as sd , NUMPY_MMAP
32- from ..base import (BaseInterface , traits , isdefined , InputMultiPath ,
33- BaseInterfaceInputSpec , Directory , Undefined , ImageFile )
32+ from ..base import (
33+ BaseInterface , traits , isdefined , InputMultiPath ,
34+ BaseInterfaceInputSpec , Directory , Undefined ,
35+ ImageFile , PackageInfo
36+ )
3437from ..matlab import MatlabCommand
3538from ...external .due import due , Doi , BibTeX
3639
@@ -123,12 +126,37 @@ def scans_for_fnames(fnames, keep4d=False, separate_sessions=False):
123126 return flist
124127
125128
126- class Info (object ):
129+ class Info (PackageInfo ):
127130 """Handles SPM version information
128131 """
129- @staticmethod
130- def version (matlab_cmd = None , paths = None , use_mcr = None ):
131- """Returns the path to the SPM directory in the Matlab path
132+ _path = None
133+ _name = None
134+
135+ @classmethod
136+ def path (klass , matlab_cmd = None , paths = None , use_mcr = None ):
137+ if klass ._path :
138+ return klass ._path
139+ klass .getinfo (matlab_cmd , paths , use_mcr )
140+ return klass ._path
141+
142+ @classmethod
143+ def version (klass , matlab_cmd = None , paths = None , use_mcr = None ):
144+ if klass ._version :
145+ return klass ._version
146+ klass .getinfo (matlab_cmd , paths , use_mcr )
147+ return klass ._version
148+
149+ @classmethod
150+ def name (klass , matlab_cmd = None , paths = None , use_mcr = None ):
151+ if klass ._name :
152+ return klass ._name
153+ klass .getinfo (matlab_cmd , paths , use_mcr )
154+ return klass ._name
155+
156+ @classmethod
157+ def getinfo (klass , matlab_cmd = None , paths = None , use_mcr = None ):
158+ """
159+ Returns the path to the SPM directory in the Matlab path
132160 If path not found, returns None.
133161
134162 Parameters
@@ -152,10 +180,17 @@ def version(matlab_cmd=None, paths=None, use_mcr=None):
152180 returns None of path not found
153181 """
154182
183+ if klass ._name and klass ._path and klass ._version :
184+ return {
185+ 'name' : klass ._name ,
186+ 'path' : klass ._path ,
187+ 'release' : klass ._version
188+ }
189+
155190 use_mcr = use_mcr or 'FORCE_SPMMCR' in os .environ
156- matlab_cmd = (( use_mcr and os . getenv ( 'SPMMCRCMD' )) or
157- os .getenv ('MATLABCMD' ) or
158- 'matlab -nodesktop -nosplash' )
191+ matlab_cmd = (
192+ ( use_mcr and os .getenv ('SPMMCRCMD' ) ) or
193+ os . getenv ( 'MATLABCMD' , 'matlab -nodesktop -nosplash' ) )
159194
160195 mlab = MatlabCommand (matlab_cmd = matlab_cmd ,
161196 resource_monitor = False )
@@ -184,13 +219,17 @@ def version(matlab_cmd=None, paths=None, use_mcr=None):
184219 # No Matlab -- no spm
185220 logger .debug ('%s' , e )
186221 return None
187- else :
188- out = sd ._strip_header (out .runtime .stdout )
189- out_dict = {}
190- for part in out .split ('|' ):
191- key , val = part .split (':' )
192- out_dict [key ] = val
193- return out_dict
222+
223+ out = sd ._strip_header (out .runtime .stdout )
224+ out_dict = {}
225+ for part in out .split ('|' ):
226+ key , val = part .split (':' )
227+ out_dict [key ] = val
228+
229+ klass ._version = out_dict ['release' ]
230+ klass ._path = out_dict ['path' ]
231+ klass ._name = out_dict ['name' ]
232+ return out_dict
194233
195234
196235def no_spm ():
@@ -288,13 +327,15 @@ def _matlab_cmd_update(self):
288327
289328 @property
290329 def version (self ):
291- version_dict = Info .version (matlab_cmd = self .inputs .matlab_cmd ,
292- paths = self .inputs .paths ,
293- use_mcr = self .inputs .use_mcr )
294- if version_dict :
295- return '.' .join ((version_dict ['name' ].split ('SPM' )[- 1 ],
296- version_dict ['release' ]))
297- return version_dict
330+ info_dict = Info .getinfo (
331+ matlab_cmd = self .inputs .matlab_cmd ,
332+ paths = self .inputs .paths ,
333+ use_mcr = self .inputs .use_mcr
334+ )
335+ if info_dict :
336+ return '%s.%s' % (
337+ info_dict ['name' ].split ('SPM' )[- 1 ],
338+ info_dict ['release' ])
298339
299340 @property
300341 def jobtype (self ):
0 commit comments