Created
April 15, 2012 07:59
-
-
Save tochiz/2390822 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
# | |
# POファイルの中の空白2つ開けてコメントしている部分を | |
# # コメント | |
# # > コメント | |
# のように変更し、前後に空白を入れるスクリプト | |
# 翻訳用 | |
# | |
import os.path, sys ,string, re | |
if __name__ == '__main__': | |
prg_name = os.path.basename(sys.argv[0]) | |
usage = """ | |
usage: python %s <ファイル名> | |
""" % (prg_name) | |
if len(sys.argv) < 2: | |
print usage | |
sys.exit(1) | |
else: | |
if not os.path.exists(sys.argv[1]): | |
print('[%s] %sが存在しません。' % (prg_name, sys.argv[1])) | |
text ="" | |
status = 0 | |
for line in open(sys.argv[1]).readlines() : | |
comm = re.match("^# ", line) | |
line = re.sub("^# ", "# > ", line) | |
if (status == 0 or status == 2) and comm: | |
text += "# \n#\n" + line | |
else: | |
text += line | |
if status == 0 and comm: | |
status = 1 | |
elif status == 1 and not comm: | |
if re.match("^#", line): | |
status = 2 | |
else: | |
status = 0 | |
elif status == 2 and comm: | |
status = 1 | |
elif status == 2 and not comm: | |
status = 0 | |
print text |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment