OSDN Git Service

version 1.0
authorSenju Higurashi <senju@users.sourceforge.jp>
Wed, 29 Jul 2009 08:35:20 +0000 (17:35 +0900)
committerSenju Higurashi <senju@users.sourceforge.jp>
Wed, 29 Jul 2009 08:35:20 +0000 (17:35 +0900)
apl2Head.txt [new file with mode: 0644]
delete.py [new file with mode: 0755]
insert.py [new file with mode: 0755]

diff --git a/apl2Head.txt b/apl2Head.txt
new file mode 100644 (file)
index 0000000..4bc9792
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+   Copyright 2009 senju@users.sourceforge.jp
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
diff --git a/delete.py b/delete.py
new file mode 100755 (executable)
index 0000000..34ce199
--- /dev/null
+++ b/delete.py
@@ -0,0 +1,79 @@
+#! /usr/bin/python
+# coding:utf-8
+
+#   Copyright 2009 senju@users.sourceforge.jp
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+
+# 標準入力からファイルのリストを読み込み、
+# ファイルの先頭のコメントを削除する。
+
+import sys,re
+
+commentStart = re.compile(r"^\s*/\*")
+commentEnd = re.compile(r"\*/\s*$")
+
+def readToCommentStart():
+       """コメント開始まで読み込む。見つからない場合falseを返す。"""
+       for line in file:
+               if line.strip() == "":
+                       # 空行よみとばし
+                       continue
+               if commentStart.search(line):
+                       return True
+               else:
+                       # 空行でもコメントでもない場合、ファイルの処理を終了
+                       return False
+       # すべて空行だった場合
+       return False
+
+
+def readToCommentEnd():
+       """コメント終了まで読み込む。見つからない場合、falseを返す。"""
+       for line in file:
+               if commentEnd.search(line):
+                       return True
+               if commentStart.search(line):
+                       # コメント開始が見つかった場合、多分異常
+                       return False
+
+       # コメントの終了が見つからない場合
+       return False
+
+for path in sys.stdin:
+       path = path.strip()
+       file = open(path)
+
+       # コメント開始まで読み飛ばし
+       if not readToCommentStart():
+               print "%s does not have head comment." % path
+               file.close()
+               continue
+       # コメント終了まで読み飛ばし
+       if not readToCommentEnd():
+               print "%s does not have head comment.(No '*/')" % path
+               file.close()
+               continue
+
+       buf = ""
+       # ソースを読み込む
+       for line in file:
+               buf += line
+       # ソースを書き込む
+       file.close()
+       file = open(path, "w")
+       file.write(buf)
+       file.close()
+
+None
diff --git a/insert.py b/insert.py
new file mode 100755 (executable)
index 0000000..d4a9924
--- /dev/null
+++ b/insert.py
@@ -0,0 +1,40 @@
+#!/usr/bin/python
+# coding:utf8
+
+#   Copyright 2009 senju@users.sourceforge.jp
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+# 標準入力からファイルリストの全てのファイルに、
+# 引数に指定されたライセンスファイルの内容を挿入する。
+
+import sys
+
+# ライセンス読み込み
+licenseFile = open(sys.argv[1])
+license = licenseFile.read()
+
+for path in sys.stdin:
+       path = path.strip()
+       file = open(path)
+
+       # ファイル読み込み
+       source = file.read()
+       file.close()
+
+       # 書き込み
+       file = open(path, "w")
+       file.write(license)
+       file.write(source)
+
+None