zoukankan      html  css  js  c++  java
  • 增加layer---待完成

     
     1 #! /usr/bin/env python
     2 # -*- coding:utf-8 -*-
     3 # Author Ian Ying
     4 # mail: kongqing.ying@yitu-inc.com
     5 
     6 import fileinput,sys,os,re
     7 
     8 def input_file_count(filename):
     9     '''fix last line is empty by checking last 4 lines'''
    10     count_line = open("streamlayer.ev", "r")
    11     #line_count = len(['' for line in count_line.readlines()])
    12     line_count_arr = count_line.readlines()
    13     total = len(line_count_arr)
    14     for i in range(1,5):
    15         print line_count_arr[-i].strip()
    16         re_match = re.compile(r'^)')
    17         if re_match.search(line_count_arr[-i]):
    18             line_count = total-i+1
    19             print line_count_arr[-i].strip(),'in'
    20             break
    21         else:
    22             line_count = total
    23     print line_count
    24     count_line.close()
    25     # filename_bak = filename+'bak'
    26     # filename_bak = str(filename_bak)
    27     # os.rename(filename, filename_bak)
    28     # old_file = open(filename_bak, 'r')
    29     # with open(filename, 'w') as file_modify:
    30     #     for line in old_file.readlines():
    31     #         print line
    32     #         file_modify.write(line)
    33     return line_count
    34 
    35 def add_layer_streamLayer(layer,datatype,layer_num,layer_type):
    36     line_count = input_file_count('streamlayer.ev')
    37     print line_count
    38     z = 0
    39     for line in fileinput.input('streamlayer.ev',inplace=1):
    40         if fileinput.lineno() == line_count and (')' in line):
    41             z = 'right',fileinput.lineno()
    42             print '('+ layer + ' '+datatype +' )'+ layer_num +' '+ layer_type
    43             print ')'
    44         elif fileinput.lineno() != line_count:
    45             print line.strip()
    46         else:
    47             z =  'Wrong! And the total line is',fileinput.lineno()
    48             print line.strip()
    49             fileinput.close()
    50             print " The input file structure is wrong!"
    51     fileinput.close()
    52     print z
    53 
    54 
    55 if __name__ == "__main__":
    56     add_layer_streamLayer('M1','drawing','3','0')

    真实使用的时候

    1.需要考虑判断添加layer的位置条件。

    2.需要加入读取标准文件,可以方便一次性多加数个layer。

    3. streamlayer,techdisplay等等其他的文件需要另外加入。

    4.最好加入一个备份模块,防止出现意外情况;

    5.加入使用说明;

    6.display 文件是需要加入格式的,四种格式,需要全部拷贝出来,然后随机分配;

    7.map.ev尾部是没有)作为结尾的,所以只需要添加就好了;

    8.techlayer/techpurpose这两个需要查找是否有涵盖到。

  • 相关阅读:
    Python元组、列表、字典
    测试通过Word直接发布博文
    Python环境搭建(windows)
    hdu 4003 Find Metal Mineral 树形DP
    poj 1986 Distance Queries LCA
    poj 1470 Closest Common Ancestors LCA
    poj 1330 Nearest Common Ancestors LCA
    hdu 3046 Pleasant sheep and big big wolf 最小割
    poj 3281 Dining 最大流
    zoj 2760 How Many Shortest Path 最大流
  • 原文地址:https://www.cnblogs.com/Ian-learning/p/9314189.html
Copyright © 2011-2022 走看看