Created
September 14, 2022 16:20
-
-
Save berceanu/e788262c529430a3eda0cdff4792668e to your computer and use it in GitHub Desktop.
Recursively convert all source code files in current folder to PDF
This file contains 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
import subprocess | |
import os | |
START_DIR = '/Users/berceanu/Development/signac-driven-fbpic' # replace with your directory | |
DEST_DIR = '.' # replace with your directory | |
CMD = 'enscript -1rG --line-numbers --highlight=python -p - --color=0 {} | pstopdf -i -o {}.pdf' | |
def print_source_code(): | |
for dirname, subdirs, filenames in os.walk(START_DIR): | |
if 'env' in subdirs: | |
del subdirs[subdirs.index('env')] | |
if '.git' in subdirs: | |
del subdirs[subdirs.index('.git')] | |
for f in filenames: | |
if f.endswith('.py'): | |
name = os.path.join(dirname, f) | |
comm = CMD.format(name, os.path.join(DEST_DIR, '-'.join(name.split('/')[1:]))) | |
try: | |
subprocess.call(comm, shell=True) | |
except Exception as e: | |
print(e) | |
print('ERROR: ' + comm) | |
break | |
if __name__ == "__main__": | |
print_source_code() | |
# pdfunit *.pdf all.pdf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment