* Remove namespaces from spoke that no longer exist

* Remove spoke folders for namespaces that have been removed
This commit is contained in:
Anna Scholtz 2024-03-28 12:07:49 -07:00 коммит произвёл GitHub
Родитель fdf36bb0e1
Коммит e1988d8890
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 41 добавлений и 0 удалений

Просмотреть файл

@ -1611,3 +1611,24 @@ telemetry_dev_cycle:
type: table_view
tables:
- table: mozdata.telemetry_dev_cycle.telemetry_probes_stats
growth:
pretty_name: Growth
owners:
- fbertsch@mozilla.com
- kik@mozilla.com
glean_app: false
mr_2022:
pretty_name: MR 2022
owners:
- loines@mozilla.com
glean_app: false
user_journey:
pretty_name: User Journey
owners:
- fbertsch@mozilla.com
glean_app: false
pocket_snowflake:
pretty_name: Pocket Snowflake
owners:
- mhirose@mozilla.com
glean_app: false

Просмотреть файл

@ -2,6 +2,8 @@
import logging
import os
import shutil
from collections import defaultdict
from pathlib import Path
from typing import Dict, List, TypedDict
@ -148,8 +150,11 @@ def generate_directories(
namespaces: Dict[str, NamespaceDict], base_dir: Path, sdk_setup=False
):
"""Generate directories and model for a namespace, if it doesn't exist."""
seen_spoke_namespaces = defaultdict(list)
for namespace, defn in namespaces.items():
spoke = defn["spoke"]
seen_spoke_namespaces[spoke].append(namespace)
spoke_dir = base_dir / spoke
spoke_dir.mkdir(parents=True, exist_ok=True)
print(f"Writing {namespace} to {spoke_dir}")
@ -172,6 +177,19 @@ def generate_directories(
logging.info("Looker SDK 4.0 initialized successfully.")
configure_model(sdk, namespace, db_connection, spoke_project)
# remove directories for namespaces that got removed
for spoke in seen_spoke_namespaces.keys():
spoke_dir = base_dir / spoke
existing_dirs = {p.name for p in spoke_dir.iterdir()}
for existing_dir in existing_dirs:
# make sure the directory belongs to a namespace by checking if a model file exists
if (spoke_dir / existing_dir / f"{existing_dir}.model.lkml").is_file():
if existing_dir not in seen_spoke_namespaces[spoke]:
# namespace does not exists anymore, remove directory
print(f"Removing {existing_dir} from {spoke_dir}")
shutil.rmtree(spoke_dir / existing_dir)
@click.command(help=__doc__)
@click.option(

Просмотреть файл

@ -14,3 +14,5 @@
- tiktokreporter_*
- org_mozilla_ios_tiktok_reporter*
- org_mozilla_tiktokreporter
- moso_*
- regrets_reporter