enrich-glypnames.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:inter 作者: rsms 项目源码 文件源码
def renameConfigFile(config, filename, newNames, dryRun=False, print=print):
  wrapper = TextWrapper()
  wrapper.width = 80
  wrapper.break_long_words = False
  wrapper.break_on_hyphens = False

  wrap = lambda names: '\n'.join(wrapper.wrap(' '.join(names)))

  didRename = False
  for propertyName, values in config.items('glyphs'):
    glyphNames = values.split()
    # print(propertyName, glyphNames)
    propChanged = False
    for name in glyphNames:
      if name in newNames:
        sectionChanged = True
    if sectionChanged:
      config.set('glyphs', propertyName, wrap(glyphNames)+'\n')
      didRename = True

    # config.set(section, option, value)
  if didRename:
    s = StringIO()
    config.write(s)
    s = s.getvalue()
    s = re.sub(r'\n(\w+)\s+=\s*', '\n\\1: ', s, flags=re.M)
    s = re.sub(r'((?:^|\n)\[[^\]]*\])', '\\1\n', s, flags=re.M)
    s = re.sub(r'\n\t\n', '\n\n', s, flags=re.M)
    s = s.strip() + '\n'
    print('Writing', filename)
    if not dryRun:
      with open(filename, 'w') as f:
        f.write(s)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号