コード例 #1
0
    def _load_profile(self):
        if not os.path.exists(self.profile_path):
            self.profile_fail_details = FILE_NOT_FOUND
            self.messages.append(
                MISSING_PROFILE_MESSAGE.format(path=self.profile_path,
                                               url=ProfileConfigDocs))
            return red('ERROR not found')

        try:
            raw_profile_data = load_yaml_text(
                dbt.clients.system.load_file_contents(self.profile_path))
        except Exception:
            pass  # we'll report this when we try to load the profile for real
        else:
            if isinstance(raw_profile_data, dict):
                self.raw_profile_data = raw_profile_data

        self.profile_name = self._choose_profile_name()
        self.target_name = self._choose_target_name()
        try:
            self.profile = Profile.from_args(self.args, self.profile_name)
        except dbt.exceptions.DbtConfigError as exc:
            self.profile_fail_details = str(exc)
            return red('ERROR invalid')

        return green('OK found and valid')
コード例 #2
0
ファイル: debug.py プロジェクト: analyst-collective/dbt
    def _load_profile(self):
        if not os.path.exists(self.profile_path):
            self.profile_fail_details = FILE_NOT_FOUND
            self.messages.append(MISSING_PROFILE_MESSAGE.format(
                path=self.profile_path, url=ProfileConfigDocs
            ))
            return red('ERROR not found')

        try:
            raw_profile_data = load_yaml_text(
                dbt.clients.system.load_file_contents(self.profile_path)
            )
        except Exception:
            pass  # we'll report this when we try to load the profile for real
        else:
            if isinstance(raw_profile_data, dict):
                self.raw_profile_data = raw_profile_data

        self.profile_name = self._choose_profile_name()
        self.target_name = self._choose_target_name()
        try:
            self.profile = Profile.from_args(self.args, self.profile_name,
                                             self.cli_vars)
        except dbt.exceptions.DbtConfigError as exc:
            self.profile_fail_details = str(exc)
            return red('ERROR invalid')

        return green('OK found and valid')
コード例 #3
0
def main():
    args = sys.argv[1:]
    parsed = dbt.parse_args(args)
    project = Project.from_args(parsed)
    profile = Profile.from_args(parsed, project.profile_name)
    """
    due to dbt's usage of popping out values from the profile dictionary we need to parse the yaml again
    popped values include type, threads
    """
    profile_yaml = read_profile(PROFILES_DIR)
    db_type = profile_yaml[profile.profile_name]['outputs'][
        profile.target_name]['type']

    parser = ArgumentParser()
    parser.add_argument('cmd',
                        help="Option to perform (prepare, run, teardown)")
    parser.add_argument('--projdir',
                        help="Project directory path",
                        default=os.path.curdir)
    parser.add_argument(
        '--sqldump',
        help="SQL dump file path to create tables",
        default="{}/db/redshift/00_campaign_r/V1.0__campaign_r.sql".format(
            os.path.curdir))
    parser.add_argument('--dataset',
                        help="Dataset and test directory path",
                        default="{}/unittest/AttributionAssisted".format(
                            os.path.curdir))
    args = parser.parse_args()

    db_schema_r_conn = connect_db(map_db_type(db_type, profile),
                                  '{}_r'.format(profile.credentials['schema']))
    db_schema_conn = connect_db(map_db_type(db_type, profile),
                                profile.credentials['schema'])

    if args.cmd == 'prepare':
        prepare_data(db_schema_r_conn, args.dataset, args.sqldump)
    elif args.cmd == 'run':
        test_exec(db_schema_r_conn, db_schema_conn, args.dataset, args.sqldump,
                  args.projdir)
    elif args.cmd == 'cleanup':
        pass