def update_if_outdated(folder):
    """Check if the currently watched instance (model, feature or
        preprocessing) is outdated and update it eventually.
    """

    folders = []
    while os.path.isdir(folder):
        folders.append(folder)
        # Get info.yml
        with open(os.path.join(folder, "info.yml")) as ymlfile:
            content = yaml.load(ymlfile)
        folder = os.path.join(utils.get_project_root(), content['data-source'])
    raw_source_file = folder
    if not os.path.isfile(raw_source_file):
        logging.error("File '%s' was not found.", raw_source_file)
        logging.error("You should eventually execute 'hwrt download'.")
        sys.exit(-1)
    dt = os.path.getmtime(raw_source_file)
    source_mtime = datetime.datetime.utcfromtimestamp(dt)
    folders = folders[::-1]  # Reverse order to get the most "basic one first"

    for target_folder in folders:
        target_mtime = utils.get_latest_successful_run(target_folder)
        if target_mtime is None or source_mtime > target_mtime:
            # The source is later than the target. That means we need to
            # refresh the target
            if "preprocessed" in target_folder:
                logging.info("Preprocessed file was outdated. Update...")
                preprocess_dataset.main(os.path.join(utils.get_project_root(),
                                                     target_folder))
            elif "feature-files" in target_folder:
                logging.info("Feature file was outdated. Update...")
                create_ffiles.main(target_folder)
            elif "model" in target_folder:
                logging.info("Model file was outdated. Update...")
                create_model.main(target_folder, True)
            target_mtime = datetime.datetime.utcnow()
        else:
            logging.info("'%s' is up-to-date.", target_folder)
        source_mtime = target_mtime
def update_if_outdated ( folder ) : folders = [ ] while os . path . isdir ( folder ) : folders . append ( folder ) with open ( os . path . join ( folder , "info.yml" ) ) as ymlfile : content = yaml . load ( ymlfile ) folder = os . path . join ( utils . get_project_root ( ) , content [ 'data-source' ] ) raw_source_file = folder if not os . path . isfile ( raw_source_file ) : logging . error ( "File '%s' was not found." , raw_source_file ) logging . error ( "You should eventually execute 'hwrt download'." ) sys . exit ( - 1 ) dt = os . path . getmtime ( raw_source_file ) source_mtime = datetime . datetime . utcfromtimestamp ( dt ) folders = folders [ : : - 1 ] for target_folder in folders : target_mtime = utils . get_latest_successful_run ( target_folder ) if target_mtime is None or source_mtime > target_mtime : if "preprocessed" in target_folder : logging . info ( "Preprocessed file was outdated. Update..." ) preprocess_dataset . main ( os . path . join ( utils . get_project_root ( ) , target_folder ) ) elif "feature-files" in target_folder : logging . info ( "Feature file was outdated. Update..." ) create_ffiles . main ( target_folder ) elif "model" in target_folder : logging . info ( "Model file was outdated. Update..." ) create_model . main ( target_folder , True ) target_mtime = datetime . datetime . utcnow ( ) else : logging . info ( "'%s' is up-to-date." , target_folder ) source_mtime = target_mtime
Check if the currently watched instance (model, feature or
        preprocessing) is outdated and update it eventually.