Skip to content

Commit b30de1e

Browse files
author
Cristhian Garcia
authored
Merge pull request #726 from openedx/cag/refactor
chore: refactor process_asset logic
2 parents 28f21eb + 0eb078a commit b30de1e

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

tutoraspects/templates/aspects/apps/superset/pythonpath/create_assets.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,15 @@ def create_assets():
5757
path = os.path.join(root, file)
5858
with open(path, "r") as file:
5959
asset = yaml.safe_load(file)
60-
if not asset:
61-
continue
62-
63-
# Process the asset directly
64-
if FILE_NAME_ATTRIBUTE not in asset:
65-
raise Exception(f"Asset {asset} has no {FILE_NAME_ATTRIBUTE}")
66-
file_name = asset.pop(FILE_NAME_ATTRIBUTE)
67-
68-
# Find the right folder to create the asset in
69-
for asset_name, folder in ASSET_FOLDER_MAPPING.items():
70-
if asset_name in asset:
71-
write_asset_to_file(asset, asset_name, folder, file_name, roles)
72-
break
60+
process_asset(asset, roles)
7361

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

7765
if extra_assets:
7866
# For each asset, create a file in the right folder
7967
for asset in extra_assets:
80-
if FILE_NAME_ATTRIBUTE not in asset:
81-
raise Exception(f"Asset {asset} has no {FILE_NAME_ATTRIBUTE}")
82-
file_name = asset.pop(FILE_NAME_ATTRIBUTE)
83-
84-
# Find the right folder to create the asset in
85-
for asset_name, folder in ASSET_FOLDER_MAPPING.items():
86-
if not asset_name in asset:
87-
continue
88-
89-
write_asset_to_file(asset, asset_name, folder, file_name, roles)
90-
break
68+
process_asset(asset, roles)
9169

9270
import_databases()
9371
import_assets()
@@ -97,6 +75,18 @@ def create_assets():
9775
create_rls_filters()
9876

9977

78+
def process_asset(asset, roles):
79+
if FILE_NAME_ATTRIBUTE not in asset:
80+
raise Exception(f"Asset {asset} has no {FILE_NAME_ATTRIBUTE}")
81+
file_name = asset.pop(FILE_NAME_ATTRIBUTE)
82+
83+
# Find the right folder to create the asset in
84+
for asset_name, folder in ASSET_FOLDER_MAPPING.items():
85+
if asset_name in asset:
86+
write_asset_to_file(asset, asset_name, folder, file_name, roles)
87+
return
88+
89+
10090
def import_databases():
10191
"""Import databases from settings"""
10292
databases = {{SUPERSET_DATABASES}}

0 commit comments

Comments
 (0)