"""Pipelines. Contains "one button" high-level functions for syncing things over. """ from looker_updater import github_tools from looker_updater import look_tools from looker_updater import model_tools from looker_updater import query_tools def sync_look(main_look_id): """Syncs over a look. Get's original look id and performs all the necessary operations (by calling other functions) for look to go to client instance, given that look with such id exists. Finally, it checks by title if such look already exists on client instance or not. If not - it just creates a new look on client instance; otherwise - it updates already existing look. Update will also sync over the query, creating a new one (which is likely to result in a duplicate query). Args: main_look_id (int): id of a look on main looker instance to sync over. Found in looks URL after .com/looks/ Returns: bool: result of an action or False if look wasn't found. """ main_look_json = look_tools.get_look_json(main_look_id) if main_look_json: client_query_id = query_tools.sync_query(main_look_json) client_look_json = look_tools.adjust_look_data(main_look_json, client_query_id) client_check_id = look_tools.check_look_on_client_instance(main_look_json) if client_check_id: return look_tools.update_look(client_check_id, client_look_json) else: return look_tools.post_look_to_client_instance(client_look_json) return False def git_files_model_sync(model_name, model_json): """Syncs all the git-related files for a given model. First it syncs over .model.lkml file, then it syncs all the joined view files for all the explores of a given model and creates a pull request. Args: model_name (str): name of the model in snake_case without file extension. model_json (dict): json representation of a model. Returns: bool: True if sync was successful, False otherwise. """ model_file_name = f'{model_name}.model.lkml' model_file_synced = github_tools.sync_git_model(model_file_name) if model_file_synced: set_of_explore_names = model_tools.get_set_of_explore_names(model_json) for explore_name in set_of_explore_names: list_of_view_files = model_tools.get_list_of_views_for_explore(model_name, explore_name) github_tools.complete_views_sync(list_of_view_files) github_tools.create_pull_request() return True return False def full_sync_model(model_name): """Complete model sync including looker instance and github files. Args: model_name (str): name of the model in snake_case without file extension. Returns: bool: True if sync was successful, False otherwise. """ model_json = model_tools.get_main_instance_model_json(model_name) if model_json: files_synced = git_files_model_sync(model_name, model_json) if files_synced: lookml_synced = model_tools.sync_lookml_model(model_name, model_json) return lookml_synced return False return False