Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: refactor process_asset logic #726

Merged
merged 1 commit into from
Apr 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,37 +57,15 @@ def create_assets():
path = os.path.join(root, file)
with open(path, "r") as file:
asset = yaml.safe_load(file)
if not asset:
continue

# Process the asset directly
if FILE_NAME_ATTRIBUTE not in asset:
raise Exception(f"Asset {asset} has no {FILE_NAME_ATTRIBUTE}")
file_name = asset.pop(FILE_NAME_ATTRIBUTE)

# Find the right folder to create the asset in
for asset_name, folder in ASSET_FOLDER_MAPPING.items():
if asset_name in asset:
write_asset_to_file(asset, asset_name, folder, file_name, roles)
break
process_asset(asset, roles)

with open(ASSETS_FILE_PATH, "r") as file:
extra_assets = yaml.safe_load(file)

if extra_assets:
# For each asset, create a file in the right folder
for asset in extra_assets:
if FILE_NAME_ATTRIBUTE not in asset:
raise Exception(f"Asset {asset} has no {FILE_NAME_ATTRIBUTE}")
file_name = asset.pop(FILE_NAME_ATTRIBUTE)

# Find the right folder to create the asset in
for asset_name, folder in ASSET_FOLDER_MAPPING.items():
if not asset_name in asset:
continue

write_asset_to_file(asset, asset_name, folder, file_name, roles)
break
process_asset(asset, roles)

import_databases()
import_assets()
Expand All @@ -97,6 +75,18 @@ def create_assets():
create_rls_filters()


def process_asset(asset, roles):
if FILE_NAME_ATTRIBUTE not in asset:
raise Exception(f"Asset {asset} has no {FILE_NAME_ATTRIBUTE}")
file_name = asset.pop(FILE_NAME_ATTRIBUTE)

# Find the right folder to create the asset in
for asset_name, folder in ASSET_FOLDER_MAPPING.items():
if asset_name in asset:
write_asset_to_file(asset, asset_name, folder, file_name, roles)
return


def import_databases():
"""Import databases from settings"""
databases = {{SUPERSET_DATABASES}}
Expand Down