topic.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. #coding=utf-8
  2. import re
  3. import sys
  4. reload(sys)
  5. sys.setdefaultencoding('utf8')
  6. profile_name = 'BYHTopicStringKeyProfile'
  7. profile_h = '/Topic/' + profile_name + '.h'
  8. profile_m = '/Topic/' + profile_name + '.m'
  9. en_strings = '/Topic/en.lproj/Topic.strings'
  10. zh_strings = '/Topic/zh-Hans.lproj/Topic.strings'
  11. table_key = 'BYHTopicTable'
  12. table_value = 'Topic'
  13. host = sys.path[0] + '/BuYao/BuYao'
  14. f=open(host + profile_h, "r+")
  15. f.truncate()
  16. f.write('#import <UIKit/UIKit.h>\n#import <JXHMacro.h>\n#import "BYHLocalizationManager.h"\n\n' + 'CONST_STRING_INTERFACE ' + table_key + ';\n')
  17. f.close()
  18. f=open(host + profile_m, "r+")
  19. f.truncate()
  20. f.write('#import "' + profile_name + '.h"\n\n' + 'CONST_STRING ' + table_key + ' = @"' + table_value + '";\n')
  21. f.close()
  22. f=open(host + en_strings, "r+")
  23. f.truncate()
  24. f.close()
  25. f = open(host + zh_strings, 'r')
  26. lines = f.readlines()
  27. for line in lines:
  28. if line == "\n":
  29. print "换行"
  30. f = open(host + profile_h, 'a')
  31. f.write('\n')
  32. f.close()
  33. f = open(host + profile_m, 'a')
  34. f.write('\n')
  35. f.close()
  36. f = open(host + en_strings, 'a')
  37. f.write('\n')
  38. f.close()
  39. continue
  40. if line.startswith('///'):
  41. print "小注释"
  42. f = open(host + profile_h, 'a')
  43. f.write(line[1:len(line)])
  44. f.close()
  45. f = open(host + profile_m, 'a')
  46. f.write(line[1:len(line)])
  47. f.close()
  48. f = open(host + en_strings, 'a')
  49. f.write(line)
  50. f.close()
  51. continue
  52. if line.startswith('//'):
  53. print "大注释"
  54. f = open(host + profile_h, 'a')
  55. f.write('#pragma mark - ' + line[2:len(line)])
  56. f.close()
  57. f = open(host + profile_m, 'a')
  58. f.write('#pragma mark - ' + line[2:len(line)])
  59. f.close()
  60. f = open(host + en_strings, 'a')
  61. f.write(line)
  62. f.close()
  63. continue
  64. matchObj = re.match('\"([^\"]*)\"', line, flags=0)
  65. if matchObj:
  66. f = open(host + profile_h, 'a')
  67. f.write('CONST_STRING_INTERFACE ' + matchObj.group(1) + 'StringKey;\n')
  68. f.close()
  69. f = open(host + profile_m, 'a')
  70. f.write('CONST_STRING ' + matchObj.group(1) + 'StringKey' + ' = @"' + matchObj.group(1) + '";\n')
  71. f.close()
  72. f = open(host + en_strings, 'a')
  73. # f.write(matchObj.group() + ' = "";\n')
  74. f.write(line)
  75. f.close()
  76. print "matchObj.group(1) : ", matchObj.group(1)
  77. else:
  78. print "No match!!"