initialize the profile dir
(self)
| 382 | self.config_file_name, exc_info=True) |
| 383 | |
| 384 | def init_profile_dir(self): |
| 385 | """initialize the profile dir""" |
| 386 | self._in_init_profile_dir = True |
| 387 | if self.profile_dir is not None: |
| 388 | # already ran |
| 389 | return |
| 390 | if 'ProfileDir.location' not in self.config: |
| 391 | # location not specified, find by profile name |
| 392 | try: |
| 393 | p = ProfileDir.find_profile_dir_by_name(self.ipython_dir, self.profile, self.config) |
| 394 | except ProfileDirError: |
| 395 | # not found, maybe create it (always create default profile) |
| 396 | if self.auto_create or self.profile == 'default': |
| 397 | try: |
| 398 | p = ProfileDir.create_profile_dir_by_name(self.ipython_dir, self.profile, self.config) |
| 399 | except ProfileDirError: |
| 400 | self.log.fatal("Could not create profile: %r"%self.profile) |
| 401 | self.exit(1) |
| 402 | else: |
| 403 | self.log.info("Created profile dir: %r"%p.location) |
| 404 | else: |
| 405 | self.log.fatal("Profile %r not found."%self.profile) |
| 406 | self.exit(1) |
| 407 | else: |
| 408 | self.log.debug("Using existing profile dir: %r", p.location) |
| 409 | else: |
| 410 | location = self.config.ProfileDir.location |
| 411 | # location is fully specified |
| 412 | try: |
| 413 | p = ProfileDir.find_profile_dir(location, self.config) |
| 414 | except ProfileDirError: |
| 415 | # not found, maybe create it |
| 416 | if self.auto_create: |
| 417 | try: |
| 418 | p = ProfileDir.create_profile_dir(location, self.config) |
| 419 | except ProfileDirError: |
| 420 | self.log.fatal("Could not create profile directory: %r"%location) |
| 421 | self.exit(1) |
| 422 | else: |
| 423 | self.log.debug("Creating new profile dir: %r"%location) |
| 424 | else: |
| 425 | self.log.fatal("Profile directory %r not found."%location) |
| 426 | self.exit(1) |
| 427 | else: |
| 428 | self.log.debug("Using existing profile dir: %r", p.location) |
| 429 | # if profile_dir is specified explicitly, set profile name |
| 430 | dir_name = os.path.basename(p.location) |
| 431 | if dir_name.startswith('profile_'): |
| 432 | self.profile = dir_name[8:] |
| 433 | |
| 434 | self.profile_dir = p |
| 435 | self.config_file_paths.append(p.location) |
| 436 | self._in_init_profile_dir = False |
| 437 | |
| 438 | def init_config_files(self): |
| 439 | """[optionally] copy default config files into profile dir.""" |