Updated the whole project to be compatible with Python 3.

This commit is contained in:
Adam Waldenberg 2012-05-25 16:42:29 +02:00
parent 22809a3b53
commit 2d48510777
13 changed files with 66 additions and 51 deletions

View File

@ -3,7 +3,7 @@ include-ids=yes
comment=yes comment=yes
[MESSAGES CONTROL] [MESSAGES CONTROL]
disable=C0111,W0232,W0603,W0702 disable=C0111,R0801,W0232,W0603,W0702
[DESIGN] [DESIGN]

View File

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from changes import FileDiff from changes import FileDiff
import comment import comment
import filtering import filtering
@ -100,7 +101,7 @@ class Blame:
def output_progress(pos, length): def output_progress(pos, length):
if sys.stdout.isatty(): if sys.stdout.isatty():
terminal.clear_row() terminal.clear_row()
print "\bChecking how many rows belong to each author (Progress): " + str(100 * pos / length) + "%", print("\bChecking how many rows belong to each author (Progress): {0:.0f}%".format(100 * pos / length), end="")
sys.stdout.flush() sys.stdout.flush()
@staticmethod @staticmethod
@ -138,16 +139,16 @@ def get(hard):
return __blame__ return __blame__
def output(hard): def output(hard):
print "" print("")
get(hard) get(hard)
if hard and sys.stdout.isatty(): if hard and sys.stdout.isatty():
terminal.clear_row() terminal.clear_row()
print "{0}Below is the number of rows from each author that have survived and".format("\b" if sys.stdout.isatty() else "") print("Below are the number of rows from each author that have survived and")
print "are still intact in the current revision:\n" print("are still intact in the current revision:\n")
terminal.printb("Author".ljust(21) + "Rows".rjust(10) + "% in comments".rjust(16)) terminal.printb("Author".ljust(21) + "Rows".rjust(10) + "% in comments".rjust(16))
for i in sorted(__blame__.get_summed_blames().items()): for i in sorted(__blame__.get_summed_blames().items()):
print i[0].ljust(20)[0:20], print(i[0].ljust(20)[0:20], end=" ")
print str(i[1].rows).rjust(10), print(str(i[1].rows).rjust(10), end=" ")
print "{0:.2f}".format(100.0 * i[1].comments / i[1].rows).rjust(15) print("{0:.2f}".format(100.0 * i[1].comments / i[1].rows).rjust(15))

View File

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import extensions import extensions
import filtering import filtering
import os import os
@ -154,18 +155,18 @@ def output(hard):
total_changes += authorinfo_list.get(i).deletions total_changes += authorinfo_list.get(i).deletions
if authorinfo_list: if authorinfo_list:
print "The following historical commit information, by author, was found in the" print("The following historical commit information, by author, was found in")
print "repository:\n" print("the repository:\n")
terminal.printb("Author".ljust(21) + "Commits " + "Insertions " + "Deletions " + "% of changes") terminal.printb("Author".ljust(21) + "Commits " + "Insertions " + "Deletions " + "% of changes")
for i in sorted(authorinfo_list): for i in sorted(authorinfo_list):
authorinfo = authorinfo_list.get(i) authorinfo = authorinfo_list.get(i)
percentage = 0 if total_changes == 0 else (authorinfo.insertions + authorinfo.deletions) / total_changes * 100 percentage = 0 if total_changes == 0 else (authorinfo.insertions + authorinfo.deletions) / total_changes * 100
print i.ljust(20)[0:20], print(i.ljust(20)[0:20], end=" ")
print str(authorinfo.commits).rjust(7), print(str(authorinfo.commits).rjust(7), end=" ")
print str(authorinfo.insertions).rjust(12), print(str(authorinfo.insertions).rjust(12), end=" ")
print str(authorinfo.deletions).rjust(11), print(str(authorinfo.deletions).rjust(11), end=" ")
print "{0:.2f}".format(percentage).rjust(14) print("{0:.2f}".format(percentage).rjust(14))
else: else:
print "No commited files with the specified extensions were found." print("No commited files with the specified extensions were found.")

View File

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import terminal import terminal
__default_extensions__ = ["java", "c", "cpp", "h", "hpp", "py", "glsl", "rb", "js", "sql"] __default_extensions__ = ["java", "c", "cpp", "h", "hpp", "py", "glsl", "rb", "js", "sql"]
@ -36,11 +37,12 @@ def add_located(string):
def output(): def output():
if __located_extensions__: if __located_extensions__:
print "\nThe extensions below were found in the repository history" print("\nThe extensions below were found in the repository history")
print "(extensions used during statistical analysis are marked):" print("(extensions used during statistical analysis are marked):")
for i in __located_extensions__: for i in __located_extensions__:
if i in __extensions__: if i in __extensions__:
print "[" + terminal.__bold__ + i + terminal.__normal__ + "]", print("[" + terminal.__bold__ + i + terminal.__normal__ + "]", end=" ")
else: else:
print i, print (i, end=" ")
print("")

View File

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import terminal import terminal
__filters__ = [] __filters__ = []
@ -43,9 +44,9 @@ def set_filtered(file_name):
def output(): def output():
if __filtered_files__: if __filtered_files__:
print "\nThe following files were excluded from the statistics due to the" print("\nThe following files were excluded from the statistics due to the")
print "specified exclusion patterns:" print("specified exclusion patterns:")
for i in __filtered_files__: for i in __filtered_files__:
(width, _) = terminal.get_size() (width, _) = terminal.get_size()
print "...%s" % i[-width+3:] if len(i) > width else i print("...%s" % i[-width+3:] if len(i) > width else i)

View File

@ -18,6 +18,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import blame import blame
import changes import changes
import extensions import extensions
@ -77,9 +78,9 @@ if __name__ == "__main__":
__opts__, __args__ = getopt.gnu_getopt(sys.argv[1:], "cf:hHlmrTwx:", ["checkout-missing", "exclude=", __opts__, __args__ = getopt.gnu_getopt(sys.argv[1:], "cf:hHlmrTwx:", ["checkout-missing", "exclude=",
"file-types=", "hard", "help", "list-file-types", "metrics", "file-types=", "hard", "help", "list-file-types", "metrics",
"responsibilities", "tda367", "timeline", "version"]) "responsibilities", "tda367", "timeline", "version"])
except getopt.error, msg: except getopt.error as msg:
print sys.argv[0], "\b:", msg print(sys.argv[0], "\b:", msg)
print "Try `", sys.argv[0], "--help' for more information." print("Try `", sys.argv[0], "--help' for more information.")
sys.exit(2) sys.exit(2)
for o, a in __opts__: for o, a in __opts__:
if o in("-c", "--checkout-missing"): if o in("-c", "--checkout-missing"):

View File

@ -55,8 +55,9 @@ more information.
gitinspector requires that the git executable is available in your PATH. gitinspector requires that the git executable is available in your PATH.
Report gitinspector bugs to gitinspector@ejwa.se.""" Report gitinspector bugs to gitinspector@ejwa.se."""
from __future__ import print_function
from extensions import __default_extensions__ from extensions import __default_extensions__
import sys import sys
def output(): def output():
print __doc__.format(sys.argv[0], ",".join(__default_extensions__)) print(__doc__.format(sys.argv[0], ",".join(__default_extensions__)))

View File

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
from changes import FileDiff from changes import FileDiff
import comment import comment
import filtering import filtering
@ -61,8 +62,8 @@ def output():
metrics = Metrics() metrics = Metrics()
if not metrics.eloc: if not metrics.eloc:
print "\nNo metrics violations were found in the repository." print("\nNo metrics violations were found in the repository.")
else: else:
print "\nThe following files are suspiciously big (in order of severity):" print("\nThe following files are suspiciously big (in order of severity):")
for i in sorted(set([(j, i) for (i, j) in metrics.eloc.items()]), reverse = True): for i in sorted(set([(j, i) for (i, j) in metrics.eloc.items()]), reverse = True):
print i[1] + " (" + str(i[0]) + " eloc)" print(i[1] + " (" + str(i[0]) + " eloc)")

View File

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import os import os
import terminal import terminal
@ -38,10 +39,10 @@ def set_checkout_missing(checkout):
def output(): def output():
if __missing_files__: if __missing_files__:
print "\nThe following files were missing in the repository and were therefore not" print("\nThe following files were missing in the repository and were therefore not")
print "completely included in the statistical analysis. To include them, you can" print("completely included in the statistical analysis. To include them, you can")
print "either checkout manually using git or use the -c option in gitinspector:" print("either checkout manually using git or use the -c option in gitinspector:")
for missing in __missing_files__: for missing in __missing_files__:
(width, _) = terminal.get_size() (width, _) = terminal.get_size()
print "...%s" % missing[-width+3:] if len(missing) > width else missing print("...%s" % missing[-width+3:] if len(missing) > width else missing)

View File

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import blame import blame
import terminal import terminal
@ -37,20 +38,20 @@ class Responsibilities:
return sorted(author_blames.items()) return sorted(author_blames.items())
def output(hard): def output(hard):
print "\nThe following repsonsibilties, by author, were found in the current" print("\nThe following repsonsibilties, by author, were found in the current")
print "revision of the repository (comments are exluded from the line count," print("revision of the repository (comments are exluded from the line count,")
print "if possible):" print("if possible):")
for i in sorted(set(i[0] for i in blame.get(hard).blames)): for i in sorted(set(i[0] for i in blame.get(hard).blames)):
print "\n" + i, "is mostly responsible for:" print("\n" + i, "is mostly responsible for:")
responsibilities = sorted(((i[1], i[0]) for i in Responsibilities.get(hard, i)), reverse=True) responsibilities = sorted(((i[1], i[0]) for i in Responsibilities.get(hard, i)), reverse=True)
for j, entry in enumerate(responsibilities): for j, entry in enumerate(responsibilities):
(width, _) = terminal.get_size() (width, _) = terminal.get_size()
width -= 7 width -= 7
print str(entry[0]).rjust(6), print(str(entry[0]).rjust(6), end=" ")
print "...%s" % entry[1][-width+3:] if len(entry[1]) > width else entry[1] print("...%s" % entry[1][-width+3:] if len(entry[1]) > width else entry[1])
if j >= 9: if j >= 9:
break break

View File

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import os import os
import platform import platform
import sys import sys
@ -72,7 +73,7 @@ def __get_size_linux__():
return int(size[1]), int(size[0]) return int(size[1]), int(size[0])
def clear_row(): def clear_row():
print "\b" * 200, print("\b" * 200, end="")
def skip_escapes(skip): def skip_escapes(skip):
if skip: if skip:
@ -82,7 +83,7 @@ def skip_escapes(skip):
__normal__ = "" __normal__ = ""
def printb(string): def printb(string):
print __bold__ + string + __normal__ print(__bold__ + string + __normal__)
def get_size(): def get_size():
if sys.stdout.isatty(): if sys.stdout.isatty():

View File

@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>. # along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from __future__ import print_function
import datetime import datetime
import terminal import terminal
@ -90,31 +91,32 @@ class TimelineData:
return self.entries.get((author, period), None) != None return self.entries.get((author, period), None) != None
def __output_row__(timeline_data, periods, names): def __output_row__(timeline_data, periods, names):
print "\n" + terminal.__bold__ + "Author".ljust(20), print("\n" + terminal.__bold__ + "Author".ljust(20), end=" ")
for period in periods: for period in periods:
print period.rjust(10), print(period.rjust(10), end=" ")
print terminal.__normal__ print(terminal.__normal__)
for name in names: for name in names:
print name.ljust(20)[0:20], print(name.ljust(20)[0:20], end=" ")
for period in periods: for period in periods:
multiplier = timeline_data.get_multiplier(period, 9) multiplier = timeline_data.get_multiplier(period, 9)
signs = timeline_data.get_author_signs_in_period(name, period, multiplier) signs = timeline_data.get_author_signs_in_period(name, period, multiplier)
signs_str = (signs[1] * "-" + signs[0] * "+") signs_str = (signs[1] * "-" + signs[0] * "+")
print ("." if timeline_data.is_author_in_period(period, name) and len(signs_str) == 0 else signs_str).rjust(10), print (("." if timeline_data.is_author_in_period(period, name) and
print "" len(signs_str) == 0 else signs_str).rjust(10), end=" ")
print("")
def output(changes, useweeks): def output(changes, useweeks):
if changes.get_commits(): if changes.get_commits():
print "\nThe following history timeline has been gathered from the repository:" print("\nThe following history timeline has been gathered from the repository:")
timeline_data = TimelineData(changes, useweeks) timeline_data = TimelineData(changes, useweeks)
periods = timeline_data.get_periods() periods = timeline_data.get_periods()
names = timeline_data.get_authors() names = timeline_data.get_authors()
(width, _) = terminal.get_size() (width, _) = terminal.get_size()
max_periods_per_row = (width - 21) / 11 max_periods_per_row = int((width - 21) / 11)
for i in range(0, len(periods), max_periods_per_row): for i in range(0, len(periods), max_periods_per_row):
__output_row__(timeline_data, periods[i:i+max_periods_per_row], names) __output_row__(timeline_data, periods[i:i+max_periods_per_row], names)

View File

@ -25,7 +25,9 @@ There is NO WARRANTY, to the extent permitted by law.
Written by Adam Waldenberg.""" Written by Adam Waldenberg."""
from __future__ import print_function
__version__ = "0.0.1" __version__ = "0.0.1"
def output(): def output():
print __doc__.format(__version__) print(__doc__.format(__version__))