def outline_content(files=None): def outline_write_content(depth, files, content_file=None): '''Write the outline for this chapter''' if content_file: open(content_file, 'w').close() for topic in files: filename = join(environ['book'], 'content', '%s.outline' % topic) if exists(filename): text = open(filename).read().split('\n') text = [ t for t in text if not t.startswith(' ' * (1 + depth)) and t.strip() ] text = '\n'.join(text) if content_file: with open(content_file, 'a') as f: f.write(heading_string(topic) + text + '\n') else: print(heading_string(topic) + text) if not files: files = book_read_index() outline_write_content(1, files, content_filename(1)) outline_write_content(2, files, content_filename(2)) outline_write_content(3, files, content_filename(3)) outline_write_content(4, files, content_filename(4)) else: outline_write_content(4, files)
def assemble_files(input_path, output_path): '''Create an agregate file by concatenating other files''' with open(output_path, 'w') as f: for topic in book_read_index(): if exists(input_path % topic): text = open(input_path % topic).read() if text: text = heading_string(topic) + text f.write(text + '\n')
def outline_diff(files): '''Show the differences between the written outline and book chapters''' update_outline_files() if files: topic = files[0] diff_outline(topic) else: for topic in book_read_index(): diff_outline(topic) path1 = join(environ['book'], 'outline', '%s.diff') path2 = join(environ['book'], 'outline', 'Outline.diff') join_files(path1, path2) system('rm $book/outline/*.diff')
def update_outline_files(): '''Build a new outline from the book text''' results = "Outline of this book\n" for topic in book_read_index(): text = extract_headings(read_chapter(topic)) if text: save_headings('outline', topic, text) save_outline('outline', topic, text) text = convert_to_headings(read_outline(topic)) if text: save_headings('content', topic, text) path1 = join(environ['book'], 'outline', '%s.md') path2 = join(environ['book'], 'outline', 'Outline.md') assemble_files(path1, path2) outline_content()
def outline_size(): '''Show the lines in each outline file''' files = [i + '.outline' for i in book_read_index('Chapters')] chdir(join(environ['book'], 'content')) text = [shell('wc -l ' + topic).replace('.outline', '') for topic in files] print(''.join(text))