コード例 #1
0
def format_files(skip_up_to_date, one_file=None):
    '''Process each markdown file.'''

    code_mod = max(latest_mod("c/*.c"), latest_mod("c/*.h"),
                   latest_mod("java/com/craftinginterpreters/tool/*.java"),
                   latest_mod("java/com/craftinginterpreters/lox/*.java"))

    # Reload the source snippets if the code was changed.
    global source_code
    global last_code_load_time
    if not last_code_load_time or code_mod > last_code_load_time:
        source_code = code_snippets.load()
        last_code_load_time = time.time()

    # See if any of the templates were modified. If so, all pages will be rebuilt.
    templates_mod = latest_mod("asset/template/*.html")

    for page in book.PAGES:
        page_file = book.get_file_name(page)
        if one_file == None or page_file == one_file:
            file = book.get_markdown_path(page)
            format_file(file, skip_up_to_date, max(code_mod, templates_mod))
コード例 #2
0
#!./util/env/bin/python3
# -*- coding: utf-8 -*-

import codecs
import glob
import os
import re
import sys

import book
import code_snippets


source_code = code_snippets.load()


def split_file(chapter_name, path, snippet=None, index=None):
  chapter_number = book.chapter_number(chapter_name)

  source_dir = book.get_language(chapter_name)
  relative = os.path.relpath(path, source_dir)
  directory = os.path.dirname(relative)

  # Don't split the generated files.
  if relative == "com/craftinginterpreters/lox/Expr.java": return
  if relative == "com/craftinginterpreters/lox/Stmt.java": return

  package = book.get_short_name(chapter_name)
  if snippet:
    package = os.path.join("snippets", package, "{:02}-{}".format(index, snippet))
  output_path = os.path.join("gen", package, relative)