Last active
August 2, 2018 05:56
-
-
Save PogiNate/f13f88ed4d5cdf1af1f3ff295fe54d32 to your computer and use it in GitHub Desktop.
A pre-commit hook for generating a leanpub book.txt file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Prep output from Scrivener for publication by Leanpub. | |
# By Nate Dickson <[email protected]> | |
# 1 August 2018 | |
import os, shutil, errno | |
# Remove the manuscript images folder before creating book.txt | |
# Scrivener will probably have wiped it out already, but let's make sure. | |
shutil.rmtree("manuscript/images",True) | |
# Get a sorted list of all files in the manuscript and add them to book.txt. | |
os.chdir("./manuscript") | |
file_list = [] | |
for root, dirs, files in os.walk("./"): | |
if '.git' in dirs: | |
dirs.remove('.git') | |
for name in sorted(files): | |
if name != ".DS_Store" and name !="book.txt": | |
full_path_string = os.path.join(root,name)[2:]+"\n" | |
file_list.append(full_path_string) | |
book_file = open("./book.txt","w") | |
book_file.writelines(sorted(file_list)) | |
book_file.close() | |
# Copy the images directory into the manuscript | |
# Because Scrivener wipes it out on export. | |
shutil.copytree("../images","images") | |
os.system("git add --all") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Some notes:
./
because Leanpub doesn't need it.