# gather all the meta info from all  the files -  check for errors 
import yaml
from pathlib import Path
def extract_meta_from_qmd(file_path):
    """
    Extracts and returns the YAML front matter (meta information) from a QMD file.
    
    Parameters:
    - file_path: Path to the QMD file.
    
    Returns:
    - A dictionary containing the parsed YAML front matter, or None if not found.
    """
    # Initialize an empty string to hold the YAML content
    yaml_content = ''
    # Flag to indicate if we are within the YAML front matter
    in_yaml = False
    
    with open(file_path, 'r') as f:
        for line in f:
            # Check for the start/end of the YAML front matter
            if line.strip() == '---':
                if in_yaml:
                    # We found the second ---, stop reading further
                    break
                else:
                    # We found the first ---, start collecting lines
                    in_yaml = True
            elif in_yaml:
                # Add the current line to the YAML content
                yaml_content += line
    
    # Parse the YAML content if any was found
    if yaml_content:
        return yaml.safe_load(yaml_content)
    else:
        return None
import os

def list_all_files(root_dir):
    """List all files in a directory and its subdirectories."""
    all_files = []
    for root, dirs, files in os.walk(root_dir):
        for file in files:
            all_files.append(os.path.join(root, file))
    return all_files
base = Path("/home/norm/compiler_course_2024fa/")
from numpy import isin


meta_union = {}
for file in list_all_files(base):
    file_path = Path(file)
    if file_path.suffix in [".pdf", ".jpg", ".png", ".woff", ".eot", ".woff2", ".ttf", ".so", ".pyc"]:
        continue
    if file_path.parent.name == "bin":
        continue 
    if any(parent.name == ".venv" for parent in file_path.parents):
        continue
    if any(parent.name == ".git" for parent in file_path.parents):
        continue
    meta_info = extract_meta_from_qmd(file)
    if meta_info:
        for key, value in meta_info.items():
    
            if isinstance(value, list):
                value = ', '.join(map(str, value))
            elif isinstance(value,dict):
                for sub_key, sub_value in value.items():
                    combined_key = f"{key}.{sub_key}"  # Combine the parent key and sub-key
                    sub_value = str(sub_value)  # Convert sub-value to string
                    if combined_key not in meta_union:
                        meta_union[combined_key] = {sub_value}
                    else:
                        meta_union[combined_key].add(sub_value)
                continue
            
            if key not in meta_union:
                meta_union[key] = {value}
            else:
                meta_union[key].add(value)

for (k,v) in meta_union.items():
    print (k, v )

    
title {'Representation of programs', 'Performance and Measurement', '14_gpu_compilers', '5_hw', 'project', 'EECE7398 Fall 2024', '10 MLIR', '3_hw ', 'Untitled', '_ loop invariant code motion', '9 polyhedral analysis', '11 Whole program', 'EECS7398 Weekly Schedule', 'How to do assignments', 'homework 0', '8 classic loop optimizations', 'Overview of Bril', '_ partial_redundancy elimination', '4_hw', 'EECS7398 Weekly Schedule fa 2024', '_ local value numbering', '4. Data Flow', 'About', 'Schedule', '3 Local Analysis & Optimization', '2.hw', '12_memory.qmd', 'Testing Register allocators', '6- extra credit hw ', '1 Compiler Overview', '1-Homework', 'Static Single Assignment', '13_dynamic_compielrs', '5 Global Analysis'}
format {'html'}
tbl-colwidths {'10, 20, 20, 20, 15, 15'}
format.html {'default'}
format.revealjs {"{'chalkboard': True, 'output-file': 'revealjs-licm', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-rep'}", "{'chalkboard': True, 'output-file': 'revealjs-partial-redun', 'scrollable': True}", "{'chalkboard': True, 'scrollable': True, 'output-location': 'slide', 'code-line-numbers': True, 'output-file': 'revealjs-bril'}", "{'chalkboard': True, 'output-file': 'revealjs-local', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-ssa', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-lvn', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-compiler_overview.html', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-data-flow', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-global-anal', 'scrollable': True}", "{'chalkboard': True, 'output-file': 'revealjs-performance.html', 'scrollable': True}"}
keep-ipynb {True}
python {'kaggle_comp'}
sidebar {False}
execute.echo {'True'}
import os
import yaml

base = Path("/home/norm/compiler_course_2024fa/")

# Step 1: List all .qmd files
qmd_files = []
slide_qmd_files = []

for root, dirs, files in os.walk(base):  # Adjust '.' to your project directory if necessary
    revealjs_
    if "_site" in Path(root).parts:
        continue
    for file in files:
        if file.endswith('.qmd'):
            qmd_files.append(os.path.join(root, file))

# Step 2: Read and parse each .qmd file
for qmd_file in qmd_files:

    with open(qmd_file, 'r') as file:
        content = file.read()
        # Assuming the YAML metadata is at the top of the file, delimited by ---
        if content.startswith('---'):
            end_of_yaml = content.find('---', 3)
            if end_of_yaml != -1:
                yaml_content = content[3:end_of_yaml]
                metadata = yaml.safe_load(yaml_content)  # Parse YAML

                format_data = metadata.get('format')
                if not format_data:
                    print(qmd_file, "no format field")
                    continue
                try:
                    html_meta_data = format_data.get("html")
                except Exception as e:
                    print(qmd_file, e, 'format does not have html')
                    continue

                if html_meta_data != 'default':
                    print(qmd_file, "not html default")
                    continue 
                try:
                    revealjs_meta_data = format_data.get('revealjs')
                except:
                    print("qmd_file", "no revealjs")
                    continue
                if revealjs_meta_data:
                    chalk = revealjs_meta_data.get("chalkboard'")
                    if chalk != 'true':
                        print(qmd_file, "missing chalkboard")
    
                # get the format
                # see if it has a subkey, revealjs
                # if it does check for an deeper subkey of output-file

                # Step 3: Check for format: reveljs
                if metadata.get('format') == 'revealjs':
                    # Step 4: Verify the output file name
                    expected_output = 'reveljs-' + os.path.basename(qmd_file).replace('.qmd', '')
                    if metadata.get('output-file') == expected_output:
                        print(f"{qmd_file}: Success, output file name is correct.")
                    else:
                        print(f"{qmd_file}: Failure, output file name does not match the expected '{expected_output}'.")
/home/norm/compiler_course_2024fa/lectures/02a_representation.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/010_compiler_overview.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/02b_bril.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/05_global.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/01a_performance_measurement.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/06_ssa.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/05b_licm.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/04_data_flow.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/03b_local_value_numbering.qmd missing chalkboard
/home/norm/compiler_course_2024fa/lectures/03_local.qmd missing chalkboard
Back to top