diff --git a/doc/conf.py b/doc/conf.py
index 6a8ca612..3e6c3e19 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -3,6 +3,8 @@
# Copyright 2012 Vincent Jacques vincent@vincent-jacques.net
# Copyright 2013 Vincent Jacques vincent@vincent-jacques.net
+################################################################################
+
# PyGithub documentation build configuration file, created by
# sphinx-quickstart on Thu Sep 13 22:51:42 2012.
#
diff --git a/manage.sh b/manage.sh
index 295021f8..e730c2a5 100755
--- a/manage.sh
+++ b/manage.sh
@@ -14,21 +14,22 @@ function check {
pep8 --ignore=E501 github setup.py || exit
}
-function check_copyright {
- for file in $(git ls-files | grep "py$")
- do
- git log "--format=format:# Copyright %ad %an %ae" --date=short -- $file |
- sed "s/\([0-9][0-9][0-9][0-9]\)-[0-9][0-9]-[0-9][0-9]/\1/g" | sort -u |
- while read copyright
- do
- if grep -n $file -e "^$copyright$" > /dev/null
- then
- echo > /dev/null
- else
- echo "$file should contain '$copyright'"
- fi
- done
- done
+function fix_headers {
+ python scripts/fix_headers.py
+ # for file in $(git ls-files | grep "py$")
+ # do
+ # git log "--format=format:# Copyright %ad %an %ae" --date=short -- $file |
+ # sed "s/\([0-9][0-9][0-9][0-9]\)-[0-9][0-9]-[0-9][0-9]/\1/g" | sort -u |
+ # while read copyright
+ # do
+ # if grep -n $file -e "^$copyright$" > /dev/null
+ # then
+ # echo > /dev/null
+ # else
+ # echo "$file should contain '$copyright'"
+ # fi
+ # done
+ # done
}
function test {
diff --git a/scripts/fix_headers.py b/scripts/fix_headers.py
new file mode 100755
index 00000000..b2f263e6
--- /dev/null
+++ b/scripts/fix_headers.py
@@ -0,0 +1,137 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+# Copyright
+
+# This file is part of PyGithub. http://jacquev6.github.com/PyGithub/
+
+# PyGithub is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License
+# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+
+# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+
+# You should have received a copy of the GNU Lesser General Public License along with PyGithub. If not, see .
+
+import fnmatch
+import os
+import subprocess
+import itertools
+
+
+license = [
+ "# This file is part of PyGithub. http://jacquev6.github.com/PyGithub/",
+ "",
+ "# PyGithub is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License",
+ "# as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.",
+ "",
+ "# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of",
+ "# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.",
+ "",
+ "# You should have received a copy of the GNU Lesser General Public License along with PyGithub. If not, see .",
+]
+
+
+class PythonHeader:
+ def fix(self, filename, lines):
+ isExecutable = lines[0].startswith("#!")
+ newLines = []
+
+ if isExecutable:
+ newLines.append("#!/usr/bin/env python")
+ newLines.append("# -*- coding: utf-8 -*-")
+ newLines.append("")
+
+ # @todo add <> around mails
+ # @todo add ############## Copyrights and license (add sections to the header)
+
+ for year, name in sorted(listContributors(filename)):
+ newLines.append("# Copyright " + year + " " + name)
+ newLines.append("")
+
+ for line in license:
+ newLines.append(line)
+
+ bodyLines = list(itertools.dropwhile(self.lineCanBeHeader, lines))
+
+ if len(bodyLines) > 0:
+ newLines.append("")
+ if "import " not in bodyLines[0] and bodyLines[0] != '"""' and not bodyLines[0].startswith("##########"):
+ newLines.append("")
+
+ newLines += bodyLines
+
+ return newLines
+
+ def lineCanBeHeader(self, line):
+ return (len(line) == 0 or line[0] == "#") and not line.startswith("##########")
+
+
+class StandardHeader:
+ def fix(self, filename, lines):
+ newLines = []
+
+ for year, name in sorted(listContributors(filename)):
+ newLines.append("# Copyright " + year + " " + name)
+ newLines.append("")
+
+ for line in license:
+ newLines.append(line)
+
+ bodyLines = list(itertools.dropwhile(self.lineCanBeHeader, lines))
+
+ if len(bodyLines) > 0:
+ newLines.append("")
+ newLines += bodyLines
+
+ return newLines
+
+ def lineCanBeHeader(self, line):
+ return (len(line) == 0 or line[0] == "#") and not line.startswith("##########")
+
+
+def listContributors(filename):
+ contributors = set()
+ for line in subprocess.check_output(["git", "log", "--format=format:%ad %an %ae", "--date=short", "--", filename]).split("\n"):
+ year = line[0:4]
+ name = line[11:]
+ contributors.add((year, name))
+ return contributors
+
+
+def findHeadersAndFiles():
+ for root, dirs, files in os.walk('.', topdown=True):
+ if ".git" in dirs:
+ dirs.remove(".git")
+
+ for filename in files:
+ fullname = os.path.join(root, filename)
+ if filename.endswith(".py"):
+ yield (PythonHeader(), fullname)
+ elif filename in ["COPYING", "COPYING.LESSER"]:
+ pass
+ elif filename.endswith(".rst") or filename.endswith(".md"):
+ pass
+ elif filename == ".gitignore":
+ yield (StandardHeader(), fullname)
+ elif "ReplayData" in fullname:
+ pass
+ else:
+ print "Don't know what to do with", filename
+
+
+def main():
+ for header, filename in findHeadersAndFiles():
+ print "Analyzing", filename
+ with open(filename) as f:
+ lines = list(line.rstrip() for line in f)
+ newLines = header.fix(filename, lines)
+ if newLines != lines:
+ print " => actually modifying", filename
+ with open(filename, "w") as f:
+ for line in newLines:
+ f.write(line + "\n")
+
+
+if __name__ == "__main__":
+ main()