def git_status(cfg: Dict[str, str]) -> NoReturn: """ Runs a "git status" against the local Git repository. :param cfg: the loaded config. COURSE_REPO must be set. :return: Nothing """ course_repo = cfg['COURSE_REPO'] print(f'+ cd {course_repo}') with working_directory(course_repo): cmd("git status")
def git_difftool(cfg: Dict[str, str]) -> NoReturn: """ Runs a "git difftool", using "opendiff", against the local Git repository. Does not work inside a Docker container. :param cfg: the loaded config. COURSE_REPO must be set. :return: Nothing """ check_config(cfg, 'COURSE_REPO') course_repo = cfg['COURSE_REPO'] check_for_docker("difftool") with working_directory(course_repo): cmd("git difftool --tool=opendiff --no-prompt")
def git_diff(cfg: Dict[str, str]) -> NoReturn: """ Runs a "git diff" against the local Git repository. :param cfg: the loaded config. COURSE_REPO must be set. PAGER will be used if it is set. :return: Nothing """ check_config(cfg, 'COURSE_REPO') course_repo = cfg['COURSE_REPO'] pager = cfg['PAGER'] with working_directory(course_repo): if not pager: cmd("git diff") else: cmd(f"git diff | {pager}")
def import_dbcs(cfg: Dict[str, str], build_dir: str, build_file: str) -> NoReturn: """ Find all DBC files under the build output directory for the current course, and upload them (import them) into the Databricks instance. :param cfg: The config. COURSE_NAME, COURSE_REMOTE_TARGET, and DB_PROFILE are assumed to be set. :param build_dir: The path to the build directory. :return: NOthing """ check_config(cfg) remote_target = cfg['COURSE_REMOTE_TARGET'] db_profile = cfg['DB_PROFILE'] def import_dbc(dbc: str, build: bdc.BuildData) -> NoReturn: ''' Import a single DBC. Assumes (a) the working directory is the build directory, and (b) that the remote target path has already been created. ''' w = databricks.Workspace(profile=db_profile) if build.has_profiles: parent_subpath = os.path.dirname(dbc) dir_to_make = f'{remote_target}/{os.path.dirname(parent_subpath)}' w.mkdirs(dir_to_make) remote_path = f'{remote_target}/{parent_subpath}' else: remote_path = remote_target info(f'Importing "{dbc}" to "{remote_path}"...') w.import_dbc(dbc, remote_path) # Get the build information. We'll need it later. build = bdc.bdc_load_build(build_file) print( f'Importing all DBCs under "{build_dir}" to remote "{remote_target}"') dbcs = [] with working_directory(build_dir) as pwd: for dirpath, _, filenames in os.walk('.'): for filename in filenames: _, ext = os.path.splitext(filename) if ext != '.dbc': continue dbcs.append(os.path.normpath(os.path.join(dirpath, filename))) if not dbcs: warn('No DBCs found.') else: clean(cfg) w = databricks.Workspace(profile=db_profile) # If we're doing a profile-based build, create the remote target. # The import operations will implicitly create the remote # subfolders. However, if we're not doing profile-based builds, # then creating the remote target ahead of time will cause the # import to fail, so don't do that. if build.has_profiles: w.mkdirs(remote_target) for dbc in dbcs: info(f'\nIn "{pwd}":') import_dbc(dbc, build)