initialize the profile dir
(self)
| 351 | self.config_file_name, exc_info=True) |
| 352 | |
| 353 | def init_profile_dir(self): |
| 354 | """initialize the profile dir""" |
| 355 | self._in_init_profile_dir = True |
| 356 | if self.profile_dir is not None: |
| 357 | # already ran |
| 358 | return |
| 359 | if 'ProfileDir.location' not in self.config: |
| 360 | # location not specified, find by profile name |
| 361 | try: |
| 362 | p = ProfileDir.find_profile_dir_by_name(self.ipython_dir, self.profile, self.config) |
| 363 | except ProfileDirError: |
| 364 | # not found, maybe create it (always create default profile) |
| 365 | if self.auto_create or self.profile == 'default': |
| 366 | try: |
| 367 | p = ProfileDir.create_profile_dir_by_name(self.ipython_dir, self.profile, self.config) |
| 368 | except ProfileDirError: |
| 369 | self.log.fatal("Could not create profile: %r"%self.profile) |
| 370 | self.exit(1) |
| 371 | else: |
| 372 | self.log.info("Created profile dir: %r"%p.location) |
| 373 | else: |
| 374 | self.log.fatal("Profile %r not found."%self.profile) |
| 375 | self.exit(1) |
| 376 | else: |
| 377 | self.log.debug("Using existing profile dir: %r"%p.location) |
| 378 | else: |
| 379 | location = self.config.ProfileDir.location |
| 380 | # location is fully specified |
| 381 | try: |
| 382 | p = ProfileDir.find_profile_dir(location, self.config) |
| 383 | except ProfileDirError: |
| 384 | # not found, maybe create it |
| 385 | if self.auto_create: |
| 386 | try: |
| 387 | p = ProfileDir.create_profile_dir(location, self.config) |
| 388 | except ProfileDirError: |
| 389 | self.log.fatal("Could not create profile directory: %r"%location) |
| 390 | self.exit(1) |
| 391 | else: |
| 392 | self.log.debug("Creating new profile dir: %r"%location) |
| 393 | else: |
| 394 | self.log.fatal("Profile directory %r not found."%location) |
| 395 | self.exit(1) |
| 396 | else: |
| 397 | self.log.info("Using existing profile dir: %r"%location) |
| 398 | # if profile_dir is specified explicitly, set profile name |
| 399 | dir_name = os.path.basename(p.location) |
| 400 | if dir_name.startswith('profile_'): |
| 401 | self.profile = dir_name[8:] |
| 402 | |
| 403 | self.profile_dir = p |
| 404 | self.config_file_paths.append(p.location) |
| 405 | self._in_init_profile_dir = False |
| 406 | |
| 407 | def init_config_files(self): |
| 408 | """[optionally] copy default config files into profile dir.""" |