|
| 1 | +#!/usr/bin/env python2 |
| 2 | +# -*- coding: utf-8 -*- |
| 3 | +""" |
| 4 | +Created on Tue Jun 25 21:36:04 2019 |
| 5 | +
|
| 6 | +
|
| 7 | +break down layers_cn to its sub categories |
| 8 | +
|
| 9 | +@author: haowang101779990 |
| 10 | +""" |
| 11 | + |
| 12 | +import sys |
| 13 | +import os |
| 14 | +import re |
| 15 | + |
| 16 | +stdi,stdo,stde=sys.stdin,sys.stdout,sys.stderr |
| 17 | +reload(sys) |
| 18 | +sys.stdin,sys.stdout,sys.stderr=stdi,stdo,stde |
| 19 | +sys.setdefaultencoding('utf-8') |
| 20 | + |
| 21 | +srcfile=open("layers_cn.rst",'r') |
| 22 | +srclines=srcfile.readlines() |
| 23 | +srcfile.close() |
| 24 | + |
| 25 | +titles={} |
| 26 | + |
| 27 | +i=0 |
| 28 | +while i <len(srclines): |
| 29 | + |
| 30 | + if re.match(r'^=+$', srclines[i])!=None: |
| 31 | + |
| 32 | + title="" |
| 33 | + base_idx=i+1 |
| 34 | + |
| 35 | + for j in range(base_idx,len(srclines)): |
| 36 | + |
| 37 | + if re.match(r'^=+$', srclines[j])!=None: |
| 38 | + title="".join(srclines[base_idx:j]) |
| 39 | + title=title.strip().replace('\n','') |
| 40 | + titles[title]=(i,j) |
| 41 | + i=j+1 |
| 42 | + break |
| 43 | + |
| 44 | + else: |
| 45 | + i+=1 |
| 46 | + |
| 47 | +titlines=titles.values() |
| 48 | +titlines.sort() |
| 49 | + |
| 50 | +if not os.path.isdir("./layers_cn"): |
| 51 | + os.mkdir("layers_cn") |
| 52 | + |
| 53 | +for i in range(0,len(titlines)): |
| 54 | + for key in titles.keys(): |
| 55 | + if(titles[key]==titlines[i]): |
| 56 | + |
| 57 | + keyf=open("layers_cn/"+key+"_cn.rst",'w') |
| 58 | + |
| 59 | + #title for this file |
| 60 | + for _ in range(0,len(key)+5): |
| 61 | + keyf.write("=") |
| 62 | + keyf.write("\n"+key+"\n") |
| 63 | + for _ in range(0,len(key)+5): |
| 64 | + keyf.write("=") |
| 65 | + keyf.write("\n") |
| 66 | + |
| 67 | + #write into file |
| 68 | + if i==len(titlines)-1: |
| 69 | + keyf.write("".join(srclines[titlines[i][1]+1:])) |
| 70 | + else: |
| 71 | + keyf.write("".join(srclines[titlines[i][1]+1:titlines[i+1][0]])) |
| 72 | + |
| 73 | + keyf.close() |
0 commit comments