'initialize the profile dir'

def init_profile_dir(self):

    self._in_init_profile_dir = True
    if (self.profile_dir is not None):
        return
    if ('ProfileDir.location' not in self.config):
        try:
            p = ProfileDir.find_profile_dir_by_name(self.ipython_dir, self.profile, self.config)
        except ProfileDirError:
            if (self.auto_create or (self.profile == 'default')):
                try:
                    p = ProfileDir.create_profile_dir_by_name(self.ipython_dir, self.profile, self.config)
                except ProfileDirError:
                    self.log.fatal(('Could    not    create    profile:    %r' % self.profile))
                    self.exit(1)
                else:
                    self.log.info(('Created    profile    dir:    %r' % p.location))
            else:
                self.log.fatal(('Profile    %r    not    found.' % self.profile))
                self.exit(1)
        else:
            self.log.debug(('Using    existing    profile    dir:    %r' % p.location))
    else:
        location = self.config.ProfileDir.location
        try:
            p = ProfileDir.find_profile_dir(location, self.config)
        except ProfileDirError:
            if self.auto_create:
                try:
                    p = ProfileDir.create_profile_dir(location, self.config)
                except ProfileDirError:
                    self.log.fatal(('Could    not    create    profile    directory:    %r' % location))
                    self.exit(1)
                else:
                    self.log.debug(('Creating    new    profile    dir:    %r' % location))
            else:
                self.log.fatal(('Profile    directory    %r    not    found.' % location))
                self.exit(1)
        else:
            self.log.info(('Using    existing    profile    dir:    %r' % location))
        dir_name = os.path.basename(p.location)
        if dir_name.startswith('profile_'):
            self.profile = dir_name[8:]
    self.profile_dir = p
    self.config_file_paths.append(p.location)
    self._in_init_profile_dir = False
