Esempio n. 1
0
    def _choose_profile_name(self):
        assert self.project or self.project_fail_details, \
            '_load_project() required'

        project_profile = None
        if self.project:
            project_profile = self.project.profile_name

        args_profile = getattr(self.args, 'profile', None)

        try:
            return Profile.pick_profile_name(args_profile, project_profile)
        except dbt.exceptions.DbtConfigError:
            pass
        # try to guess

        if self.raw_profile_data:
            profiles = [k for k in self.raw_profile_data if k != 'config']
            if len(profiles) == 0:
                self.messages.append('The profiles.yml has no profiles')
            elif len(profiles) == 1:
                self.messages.append(ONLY_PROFILE_MESSAGE.format(profiles[0]))
                return profiles[0]
            else:
                self.messages.append(MULTIPLE_PROFILE_MESSAGE.format(
                    '\n'.join(' - {}'.format(o) for o in profiles)
                ))
        return None
Esempio n. 2
0
    def _choose_profile_name(self):
        assert self.project or self.project_fail_details, \
            '_load_project() required'

        project_profile = None
        if self.project:
            project_profile = self.project.profile_name

        args_profile = getattr(self.args, 'profile', None)

        try:
            return Profile.pick_profile_name(args_profile, project_profile)
        except dbt.exceptions.DbtConfigError:
            pass
        # try to guess

        if self.raw_profile_data:
            profiles = [k for k in self.raw_profile_data if k != 'config']
            if len(profiles) == 0:
                self.messages.append('The profiles.yml has no profiles')
            elif len(profiles) == 1:
                self.messages.append(ONLY_PROFILE_MESSAGE.format(profiles[0]))
                return profiles[0]
            else:
                self.messages.append(
                    MULTIPLE_PROFILE_MESSAGE.format('\n'.join(
                        ' - {}'.format(o) for o in profiles)))
        return None
Esempio n. 3
0
    def _choose_profile_names(self) -> Optional[List[str]]:
        project_profile: Optional[str] = None
        if os.path.exists(self.project_path):
            try:
                partial = Project.partial_load(
                    os.path.dirname(self.project_path),
                    verify_version=getattr(self.args, 'version_check', False),
                )
                renderer = DbtProjectYamlRenderer(
                    generate_base_context(self.cli_vars)
                )
                project_profile = partial.render_profile_name(renderer)
            except dbt.exceptions.DbtProjectError:
                pass

        args_profile: Optional[str] = getattr(self.args, 'profile', None)

        try:
            return [Profile.pick_profile_name(args_profile, project_profile)]
        except dbt.exceptions.DbtConfigError:
            pass
        # try to guess

        profiles = []
        if self.raw_profile_data:
            profiles = [k for k in self.raw_profile_data if k != 'config']
            if project_profile is None:
                self.messages.append('Could not load dbt_project.yml')
            elif len(profiles) == 0:
                self.messages.append('The profiles.yml has no profiles')
            elif len(profiles) == 1:
                self.messages.append(ONLY_PROFILE_MESSAGE.format(profiles[0]))
            else:
                self.messages.append(MULTIPLE_PROFILE_MESSAGE.format(
                    '\n'.join(' - {}'.format(o) for o in profiles)
                ))
        return profiles