@breakout.html
001| from sys import argv
002| from os import path
003| from files import linefile
004|
005| BasePath = r'C:\CJS\prj\Python\blog\hcc\source'
006| ArchPath = path.join(BasePath, 'archive')
007|
008| FileName = path.join(ArchPath, argv[1] if 1 < len(argv) else 'source.py')
009| FoutName = lambda n:path.join(BasePath, 'example%03d.py' % n)
010|
011|
012| fi = linefile(FileName)
013| fi.load()
014|
015|
016| flag = 0
017| fnbr = 1
018| fout = linefile(FoutName(fnbr))
019|
020| print(f'Scanning: {FileName}')
021|
022| for line in fi:
023|
024| if flag:
025|
026| if line.startswith('#:end:code::'):
027| flag = 0
028|
029| fout.save()
030| print(f'wrote: {fout.fullname}')
031| break
032|
033|
034| if line.startswith('#:code::'):
035|
036| fout.save()
037| print(f'wrote: {fout.fullname}')
038| fnbr += 1
039| fout = linefile(FoutName(fnbr))
040| continue
041|
042|
043| fout.data.append(line)
044| continue
045|
046|
047|
048| if line.startswith('#:code::'):
049| flag = 1
050|
051| print('Done!')
052| print()
053|