saturn_notebook/__main__.py
def clean(infn: "input notebook",
          outfn: "output notebook (if empty, input modified in place)",
          strip_output: "also strip all output" = False):
    """Remove all binary data from the notebook."""
    if not outfn:
        outfn = infn

    if os.path.exists(infn):
        with atomic_write(outfn, mode='w', overwrite=True) as of:
            with open(infn) as f:
                pf = peekable(f)
                for line in pf:
                    if strip_output and line.startswith('#o>'): continue
                    if line.startswith('#o> png'): continue
                    if line.startswith('#chk>') and line.strip() != '#chk>':
                        of.write('#chk>\n')
                        while pf and pf.peek().startswith('#chk>'):
                            next(pf)
                        continue
                    if line.startswith('#var>'):
                        # Keep the first line, but skip all subsequent lines
                        while pf and pf.peek().startswith('#var>'):
                            next(pf)
                    of.write(line)
Remove all binary data from the notebook.
Remove all binary data from the notebook.
Remove all binary data from the notebook .
def clean(infn: "input notebook",
          outfn: "output notebook (if empty, input modified in place)",
          strip_output: "also strip all output" = False):
    if not outfn:
        outfn = infn
    if os.path.exists(infn):
        with atomic_write(outfn, mode='w', overwrite=True) as of:
            with open(infn) as f:
                pf = peekable(f)
                for line in pf:
                    if strip_output and line.startswith('#o>'): continue
                    if line.startswith('#o> png'): continue
                    if line.startswith('#chk>') and line.strip() != '#chk>':
                        of.write('#chk>\n')
                        while pf and pf.peek().startswith('#chk>'):
                            next(pf)
                        continue
                    if line.startswith('#var>'):
                        while pf and pf.peek().startswith('#var>'):
                            next(pf)
                    of.write(line)
def clean ( infn : "input notebook" , outfn : "output notebook (if empty, input modified in place)" , strip_output : "also strip all output" = False ) : if not outfn : outfn = infn if os . path . exists ( infn ) : with atomic_write ( outfn , mode = 'w' , overwrite = True ) as of : with open ( infn ) as f : pf = peekable ( f ) for line in pf : if strip_output and line . startswith ( '#o>' ) : continue if line . startswith ( '#o> png' ) : continue if line . startswith ( '#chk>' ) and line . strip ( ) != '#chk>' : of . write ( '#chk>\n' ) while pf and pf . peek ( ) . startswith ( '#chk>' ) : next ( pf ) continue if line . startswith ( '#var>' ) : while pf and pf . peek ( ) . startswith ( '#var>' ) : next ( pf ) of . write ( line )
Remove all binary data from the notebook.
Remove all binary data from the notebook .
"""Remove all binary data from the notebook.""" # Keep the first line, but skip all subsequent lines
infn
"input notebook"
outfn
"output notebook (if empty, input modified in place)"
strip_output
"also strip all output"