def _prepare_env(subject, subjects_dir, requires_freesurfer, requires_mne):
 env = os.environ.copy()
 if (requires_freesurfer and (not os.environ.get('FREESURFER_HOME'))):
  raise RuntimeError('I cannot find freesurfer. The FREESURFER_HOME environment variable is not set.')
 if (requires_mne and (not os.environ.get('MNE_ROOT'))):
  raise RuntimeError('I cannot find the MNE command line tools. The MNE_ROOT environment variable is not set.')
 if (not isinstance(subject, string_types)):
  raise TypeError('The subject argument must be set')
 subjects_dir = get_subjects_dir(subjects_dir, raise_error=True)
 if (not op.isdir(subjects_dir)):
  raise RuntimeError(('Could not find the MRI data directory "%s"' % subjects_dir))
 subject_dir = op.join(subjects_dir, subject)
 if (not op.isdir(subject_dir)):
  raise RuntimeError(('Could not find the subject data directory "%s"' % (subject_dir,)))
 env['SUBJECT'] = subject
 env['SUBJECTS_DIR'] = subjects_dir
 mri_dir = op.join(subject_dir, 'mri')
 bem_dir = op.join(subject_dir, 'bem')
 return (env, mri_dir, bem_dir)

def _prepare_env ( subject , subjects_dir , requires_freesurfer , requires_mne ) : env = os . environ . copy ( ) if ( requires_freesurfer and ( not os . environ . get ( 'FREESURFER_HOME' ) ) ) : raise RuntimeError ( 'I cannot find freesurfer. The FREESURFER_HOME environment variable is not set.' ) if ( requires_mne and ( not os . environ . get ( 'MNE_ROOT' ) ) ) : raise RuntimeError ( 'I cannot find the MNE command line tools. The MNE_ROOT environment variable is not set.' ) if ( not isinstance ( subject , string_types ) ) : raise TypeError ( 'The subject argument must be set' ) subjects_dir = get_subjects_dir ( subjects_dir , raise_error = True ) if ( not op . isdir ( subjects_dir ) ) : raise RuntimeError ( ( 'Could not find the MRI data directory "%s"' % subjects_dir ) ) subject_dir = op . join ( subjects_dir , subject ) if ( not op . isdir ( subject_dir ) ) : raise RuntimeError ( ( 'Could not find the subject data directory "%s"' % ( subject_dir , ) ) ) env [ 'SUBJECT' ] = subject env [ 'SUBJECTS_DIR' ] = subjects_dir mri_dir = op . join ( subject_dir , 'mri' ) bem_dir = op . join ( subject_dir , 'bem' ) return ( env , mri_dir , bem_dir )
helper to prepare an env object for subprocess calls .