示例#1
0
文件: pkg.py 项目: p2l1pfp/cmssw
 def write(self, fname, tmpl_name, kwds):
     "Create new file from given template name and set of arguments"
     code = ""
     read_code = False
     if os.path.exists(fname):
         return
     with open(fname, 'w') as stream:
         for line in open(tmpl_name, 'r').readlines():
             line = self.parse_etags(line)
             if not line:
                 continue
             if line.find('#python_begin') != -1:
                 read_code = True
                 continue
             if line.find('#python_end') != -1:
                 read_code = False
             if read_code:
                 code += line
             if code and not read_code:
                 res = functor(code, kwds, self.debug)
                 stream.write(res)
                 code = ""
                 continue
             if not read_code:
                 for key, val in kwds.items():
                     if isinstance(val, str):
                         line = line.replace(key, val)
                 stream.write(line)
示例#2
0
文件: pkg.py 项目: Andrej-CMS/cmssw
 def write(self, fname, tmpl_name, kwds):
     "Create new file from given template name and set of arguments"
     code = ""
     read_code = False
     with open(fname, 'w') as stream:
         for line in open(tmpl_name, 'r').readlines():
             line = self.parse_etags(line)
             if  not line:
                 continue
             if  line.find('#python_begin') != -1:
                 read_code = True
                 continue
             if  line.find('#python_end') != -1:
                 read_code = False
             if  read_code:
                 code += line
             if  code and not read_code:
                 res   = functor(code, kwds, self.debug)
                 stream.write(res)
                 code  = ""
                 continue
             if  not read_code:
                 for key, val in kwds.items():
                     if  isinstance(val, basestring):
                         line = line.replace(key, val)
                 stream.write(line)