Skip to content

Instantly share code, notes, and snippets.

@berceanu
Created October 15, 2022 20:39
Show Gist options
  • Save berceanu/4f268dfc9e83b2392e85e11f7fe8f12c to your computer and use it in GitHub Desktop.
Save berceanu/4f268dfc9e83b2392e85e11f7fe8f12c to your computer and use it in GitHub Desktop.

Revisions

  1. berceanu created this gist Oct 15, 2022.
    25 changes: 25 additions & 0 deletions print_walker.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    import subprocess
    import os

    START_DIR = '/data/storage/berceanu/Development/signac-driven-fbpic' # replace with your directory
    DEST_DIR = '/data/storage/berceanu/Development' # replace with your directory
    CMD = 'enscript -1rG --line-numbers --highlight=python -p - --color=0 {} | ps2pdf -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:
    print(f)
    if f.endswith('.py'):
    name = os.path.join(dirname, f)
    comm = CMD.format(name, os.path.join(DEST_DIR, '-'.join(name.split('/')[1:])))
    try:
    print(comm)
    subprocess.call(comm, shell=True)
    except Exception as e:
    print(e)
    print('ERROR: ' + comm)
    break