Massive Linting and clean up

This commit is contained in:
JP White 2021-02-27 22:39:08 -05:00
parent 2dd72c1d96
commit c17c5795ad
31 changed files with 2233 additions and 1822 deletions

View File

@ -26,14 +26,11 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
make requirements
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
make test-coverage
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
make lint
- name: Test with pytest
run: |
pytest
make test-coverage

View File

@ -35,9 +35,13 @@ clean-test: ## remove test and coverage artifacts
rm -fr .pytest_cache
lint: ## check style with flake8
black gitinspector --line-length 120
find . -name '*.py' -exec autopep8 -i {} --max-line-length=120 \;
flake8 gitinspector tests --max-line-length=120
# stop the build if there are Python syntax errors or undefined names
flake8 gitinspector tests --count --select=E9,F63,F7,F82 --show-source --statistics --builtins="_"
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 gitinspector tests --count --ignore=E722,W503,E401,C901 --exit-zero --max-complexity=10 --max-line-length=127 --statistics --builtins="_"
format: ## auto format all the code with black
black gitinspector --line-length 127
test: ## run tests quickly with the default Python
pytest

View File

@ -21,43 +21,45 @@ import os
import subprocess
import sys
def get_basedir():
if hasattr(sys, "frozen"): # exists when running via py2exe
return sys.prefix
else:
return os.path.dirname(os.path.realpath(__file__))
def get_basedir_git(path=None):
previous_directory = None
if path != None:
if path is not None:
previous_directory = os.getcwd()
os.chdir(path)
bare_command = subprocess.Popen(["git", "rev-parse", "--is-bare-repository"],
stdout=subprocess.PIPE, stderr=open(os.devnull, "w"))
bare_command = subprocess.Popen(
["git", "rev-parse", "--is-bare-repository"], stdout=subprocess.PIPE, stderr=open(os.devnull, "w")
)
isbare = bare_command.stdout.readlines()
bare_command.wait()
if bare_command.returncode != 0:
sys.exit(_("Error processing git repository at \"%s\"." % os.getcwd()))
sys.exit(_('Error processing git repository at "%s".' % os.getcwd()))
isbare = (isbare[0].decode("utf-8", "replace").strip() == "true")
isbare = isbare[0].decode("utf-8", "replace").strip() == "true"
absolute_path = None
if isbare:
absolute_path = subprocess.Popen(["git", "rev-parse", "--git-dir"], stdout=subprocess.PIPE).stdout
else:
absolute_path = subprocess.Popen(["git", "rev-parse", "--show-toplevel"],
stdout=subprocess.PIPE).stdout
absolute_path = subprocess.Popen(["git", "rev-parse", "--show-toplevel"], stdout=subprocess.PIPE).stdout
absolute_path = absolute_path.readlines()
if len(absolute_path) == 0:
sys.exit(_("Unable to determine absolute path of git repository."))
if path != None:
if path is not None:
os.chdir(previous_directory)
return absolute_path[0].decode("utf-8", "replace").strip()

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import datetime
import multiprocessing
import re
@ -30,16 +29,19 @@ from . import comment, extensions, filtering, format, interval, terminal
NUM_THREADS = multiprocessing.cpu_count()
class BlameEntry(object):
rows = 0
skew = 0 # Used when calculating average code age.
comments = 0
__thread_lock__ = threading.BoundedSemaphore(NUM_THREADS)
__blame_lock__ = threading.Lock()
AVG_DAYS_PER_MONTH = 30.4167
class BlameThread(threading.Thread):
def __init__(self, useweeks, changes, blame_command, extension, blames, filename):
__thread_lock__.acquire() # Lock controlling the number of threads running
@ -72,21 +74,24 @@ class BlameThread(threading.Thread):
except KeyError:
return
if not filtering.set_filtered(author, "author") and not \
filtering.set_filtered(self.blamechunk_email, "email") and not \
filtering.set_filtered(self.blamechunk_revision, "revision"):
if (
not filtering.set_filtered(author, "author")
and not filtering.set_filtered(self.blamechunk_email, "email")
and not filtering.set_filtered(self.blamechunk_revision, "revision")
):
__blame_lock__.acquire() # Global lock used to protect calls from here...
if self.blames.get((author, self.filename), None) == None:
if self.blames.get((author, self.filename), None) is None:
self.blames[(author, self.filename)] = BlameEntry()
self.blames[(author, self.filename)].comments += comments
self.blames[(author, self.filename)].rows += 1
if (self.blamechunk_time - self.changes.first_commit_date).days > 0:
self.blames[(author, self.filename)].skew += ((self.changes.last_commit_date - self.blamechunk_time).days /
(7.0 if self.useweeks else AVG_DAYS_PER_MONTH))
self.blames[(author, self.filename)].skew += (self.changes.last_commit_date - self.blamechunk_time).days / (
7.0 if self.useweeks else AVG_DAYS_PER_MONTH
)
__blame_lock__.release() # ...to here.
@ -97,7 +102,7 @@ class BlameThread(threading.Thread):
self.__clear_blamechunk_info__()
#pylint: disable=W0201
# pylint: disable=W0201
for j in range(0, len(rows)):
row = rows[j].decode("utf-8", "replace").strip()
keyval = row.split(" ", 2)
@ -118,34 +123,45 @@ class BlameThread(threading.Thread):
__thread_lock__.release() # Lock controlling the number of threads running
PROGRESS_TEXT = N_("Checking how many rows belong to each author (2 of 2): {0:.0f}%")
class Blame(object):
def __init__(self, repo, hard, useweeks, changes):
self.blames = {}
ls_tree_p = subprocess.Popen(["git", "ls-tree", "--name-only", "-r", interval.get_ref()],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
ls_tree_p = subprocess.Popen(
["git", "ls-tree", "--name-only", "-r", interval.get_ref()], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
lines = ls_tree_p.communicate()[0].splitlines()
ls_tree_p.stdout.close()
if ls_tree_p.returncode == 0:
progress_text = _(PROGRESS_TEXT)
if repo != None:
if repo is not None:
progress_text = "[%s] " % repo.name + progress_text
for i, row in enumerate(lines):
row = row.strip().decode("unicode_escape", "ignore")
row = row.encode("latin-1", "replace")
row = row.decode("utf-8", "replace").strip("\"").strip("'").strip()
row = row.decode("utf-8", "replace").strip('"').strip("'").strip()
if FileDiff.get_extension(row) in extensions.get_located() and \
FileDiff.is_valid_extension(row) and not filtering.set_filtered(FileDiff.get_filename(row)):
blame_command = [_f for _f in ["git", "blame", "--line-porcelain", "-w"] + \
(["-C", "-C", "-M"] if hard else []) +
[interval.get_since(), interval.get_ref(), "--", row] if _f]
thread = BlameThread(useweeks, changes, blame_command, FileDiff.get_extension(row),
self.blames, row.strip())
if (
FileDiff.get_extension(row) in extensions.get_located()
and FileDiff.is_valid_extension(row)
and not filtering.set_filtered(FileDiff.get_filename(row))
):
blame_command = [
_f
for _f in ["git", "blame", "--line-porcelain", "-w"]
+ (["-C", "-C", "-M"] if hard else [])
+ [interval.get_since(), interval.get_ref(), "--", row]
if _f
]
thread = BlameThread(
useweeks, changes, blame_command, FileDiff.get_extension(row), self.blames, row.strip()
)
thread.daemon = True
thread.start()
@ -163,15 +179,15 @@ class Blame(object):
def __iadd__(self, other):
try:
self.blames.update(other.blames)
return self;
return self
except AttributeError:
return other;
return other
@staticmethod
def is_revision(string):
revision = re.search("([0-9a-f]{40})", string)
if revision == None:
if revision is None:
return False
return revision.group(1).strip()
@ -191,7 +207,7 @@ class Blame(object):
def get_summed_blames(self):
summed_blames = {}
for i in list(self.blames.items()):
if summed_blames.get(i[0][0], None) == None:
if summed_blames.get(i[0][0], None) is None:
summed_blames[i[0][0]] = BlameEntry()
summed_blames[i[0][0]].rows += i[1].rows

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import bisect
import datetime
import multiprocessing
@ -34,6 +33,7 @@ NUM_THREADS = multiprocessing.cpu_count()
__thread_lock__ = threading.BoundedSemaphore(NUM_THREADS)
__changes_lock__ = threading.Lock()
class FileDiff(object):
def __init__(self, string):
commit_line = string.split("|")
@ -46,26 +46,27 @@ class FileDiff(object):
@staticmethod
def is_filediff_line(string):
string = string.split("|")
return string.__len__() == 2 and string[1].find("Bin") == -1 and ('+' in string[1] or '-' in string[1])
return string.__len__() == 2 and string[1].find("Bin") == -1 and ("+" in string[1] or "-" in string[1])
@staticmethod
def get_extension(string):
string = string.split("|")[0].strip().strip("{}").strip("\"").strip("'")
string = string.split("|")[0].strip().strip("{}").strip('"').strip("'")
return os.path.splitext(string)[1][1:]
@staticmethod
def get_filename(string):
return string.split("|")[0].strip().strip("{}").strip("\"").strip("'")
return string.split("|")[0].strip().strip("{}").strip('"').strip("'")
@staticmethod
def is_valid_extension(string):
extension = FileDiff.get_extension(string)
for i in extensions.get():
if (extension == "" and i == "*") or extension == i or i == '**':
if (extension == "" and i == "*") or extension == i or i == "**":
return True
return False
class Commit(object):
def __init__(self, string):
self.filediffs = []
@ -98,12 +99,14 @@ class Commit(object):
def is_commit_line(string):
return string.split("|").__len__() == 5
class AuthorInfo(object):
email = None
insertions = 0
deletions = 0
commits = 0
class ChangesThread(threading.Thread):
def __init__(self, hard, changes, first_hash, second_hash, offset):
__thread_lock__.acquire() # Lock controlling the number of threads running
@ -122,10 +125,27 @@ class ChangesThread(threading.Thread):
thread.start()
def run(self):
git_log_r = subprocess.Popen([_f for _f in ["git", "log", "--reverse", "--pretty=%ct|%cd|%H|%aN|%aE",
"--stat=100000,8192", "--no-merges", "-w", interval.get_since(),
interval.get_until(), "--date=short"] + (["-C", "-C", "-M"] if self.hard else []) +
[self.first_hash + self.second_hash] if _f], stdout=subprocess.PIPE).stdout
git_log_r = subprocess.Popen(
[
_f
for _f in [
"git",
"log",
"--reverse",
"--pretty=%ct|%cd|%H|%aN|%aE",
"--stat=100000,8192",
"--no-merges",
"-w",
interval.get_since(),
interval.get_until(),
"--date=short",
]
+ (["-C", "-C", "-M"] if self.hard else [])
+ [self.first_hash + self.second_hash]
if _f
],
stdout=subprocess.PIPE,
).stdout
lines = git_log_r.readlines()
git_log_r.close()
@ -154,15 +174,15 @@ class ChangesThread(threading.Thread):
is_filtered = False
commit = Commit(j)
if Commit.is_commit_line(j) and \
(filtering.set_filtered(commit.author, "author") or \
filtering.set_filtered(commit.email, "email") or \
filtering.set_filtered(commit.sha, "revision") or \
filtering.set_filtered(commit.sha, "message")):
if Commit.is_commit_line(j) and (
filtering.set_filtered(commit.author, "author")
or filtering.set_filtered(commit.email, "email")
or filtering.set_filtered(commit.sha, "revision")
or filtering.set_filtered(commit.sha, "message")
):
is_filtered = True
if FileDiff.is_filediff_line(j) and not \
filtering.set_filtered(FileDiff.get_filename(j)) and not is_filtered:
if FileDiff.is_filediff_line(j) and not filtering.set_filtered(FileDiff.get_filename(j)) and not is_filtered:
extensions.add_located(FileDiff.get_extension(j))
if FileDiff.is_valid_extension(j):
@ -174,8 +194,10 @@ class ChangesThread(threading.Thread):
__changes_lock__.release() # ...to here.
__thread_lock__.release() # Lock controlling the number of threads running
PROGRESS_TEXT = N_("Fetching and calculating primary statistics (1 of 2): {0:.0f}%")
class Changes(object):
authors = {}
authors_dateinfo = {}
@ -184,16 +206,22 @@ class Changes(object):
def __init__(self, repo, hard):
self.commits = []
interval.set_ref("HEAD");
git_rev_list_p = subprocess.Popen([_f for _f in ["git", "rev-list", "--reverse", "--no-merges",
interval.get_since(), interval.get_until(), "HEAD"] if _f],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
interval.set_ref("HEAD")
git_rev_list_p = subprocess.Popen(
[
_f
for _f in ["git", "rev-list", "--reverse", "--no-merges", interval.get_since(), interval.get_until(), "HEAD"]
if _f
],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
lines = git_rev_list_p.communicate()[0].splitlines()
git_rev_list_p.stdout.close()
if git_rev_list_p.returncode == 0 and len(lines) > 0:
progress_text = _(PROGRESS_TEXT)
if repo != None:
if repo is not None:
progress_text = "[%s] " % repo.name + progress_text
chunks = len(lines) // CHANGES_PER_THREAD
@ -229,10 +257,12 @@ class Changes(object):
if interval.has_interval():
interval.set_ref(self.commits[-1].sha)
self.first_commit_date = datetime.date(int(self.commits[0].date[0:4]), int(self.commits[0].date[5:7]),
int(self.commits[0].date[8:10]))
self.last_commit_date = datetime.date(int(self.commits[-1].date[0:4]), int(self.commits[-1].date[5:7]),
int(self.commits[-1].date[8:10]))
self.first_commit_date = datetime.date(
int(self.commits[0].date[0:4]), int(self.commits[0].date[5:7]), int(self.commits[0].date[8:10])
)
self.last_commit_date = datetime.date(
int(self.commits[-1].date[0:4]), int(self.commits[-1].date[5:7]), int(self.commits[-1].date[8:10])
)
def __iadd__(self, other):
try:
@ -255,7 +285,7 @@ class Changes(object):
@staticmethod
def modify_authorinfo(authors, key, commit):
if authors.get(key, None) == None:
if authors.get(key, None) is None:
authors[key] = AuthorInfo()
if commit.get_filediffs():

View File

@ -31,6 +31,7 @@ except:
__cloned_paths__ = []
def create(url):
class Repository(object):
def __init__(self, name, location):
@ -39,8 +40,13 @@ def create(url):
parsed_url = urlparse(url)
if parsed_url.scheme == "file" or parsed_url.scheme == "git" or parsed_url.scheme == "http" or \
parsed_url.scheme == "https" or parsed_url.scheme == "ssh":
if (
parsed_url.scheme == "file"
or parsed_url.scheme == "git"
or parsed_url.scheme == "http"
or parsed_url.scheme == "https"
or parsed_url.scheme == "ssh"
):
path = tempfile.mkdtemp(suffix=".gitinspector")
git_clone = subprocess.Popen(["git", "clone", url, path], stdout=sys.stderr)
git_clone.wait()
@ -53,6 +59,7 @@ def create(url):
return Repository(None, os.path.abspath(url))
def delete():
for path in __cloned_paths__:
shutil.rmtree(path, ignore_errors=True)

View File

@ -18,50 +18,128 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
__comment_begining__ = {
"java": "/*",
"c": "/*",
"cc": "/*",
"cpp": "/*",
"cs": "/*",
"h": "/*",
"hh": "/*",
"hpp": "/*",
"hs": "{-",
"html": "<!--",
"php": "/*",
"py": '"""',
"glsl": "/*",
"rb": "=begin",
"js": "/*",
"jspx": "<!--",
"scala": "/*",
"sql": "/*",
"tex": "\\begin{comment}",
"xhtml": "<!--",
"xml": "<!--",
"ml": "(*",
"mli": "(*",
"go": "/*",
"ly": "%{",
"ily": "%{",
}
__comment_begining__ = {"java": "/*", "c": "/*", "cc": "/*", "cpp": "/*", "cs": "/*", "h": "/*", "hh": "/*", "hpp": "/*",
"hs": "{-", "html": "<!--", "php": "/*", "py": "\"\"\"", "glsl": "/*", "rb": "=begin", "js": "/*",
"jspx": "<!--", "scala": "/*", "sql": "/*", "tex": "\\begin{comment}", "xhtml": "<!--",
"xml": "<!--", "ml": "(*", "mli": "(*", "go": "/*", "ly": "%{", "ily": "%{"}
__comment_end__ = {
"java": "*/",
"c": "*/",
"cc": "*/",
"cpp": "*/",
"cs": "*/",
"h": "*/",
"hh": "*/",
"hpp": "*/",
"hs": "-}",
"html": "-->",
"php": "*/",
"py": '"""',
"glsl": "*/",
"rb": "=end",
"js": "*/",
"jspx": "-->",
"scala": "*/",
"sql": "*/",
"tex": "\\end{comment}",
"xhtml": "-->",
"xml": "-->",
"ml": "*)",
"mli": "*)",
"go": "*/",
"ly": "%}",
"ily": "%}",
}
__comment_end__ = {"java": "*/", "c": "*/", "cc": "*/", "cpp": "*/", "cs": "*/", "h": "*/", "hh": "*/", "hpp": "*/", "hs": "-}",
"html": "-->", "php": "*/", "py": "\"\"\"", "glsl": "*/", "rb": "=end", "js": "*/", "jspx": "-->",
"scala": "*/", "sql": "*/", "tex": "\\end{comment}", "xhtml": "-->", "xml": "-->", "ml": "*)", "mli": "*)",
"go": "*/", "ly": "%}", "ily": "%}"}
__comment__ = {"java": "//", "c": "//", "cc": "//", "cpp": "//", "cs": "//", "h": "//", "hh": "//", "hpp": "//", "hs": "--",
"pl": "#", "php": "//", "py": "#", "glsl": "//", "rb": "#", "robot": "#", "rs": "//", "rlib": "//", "js": "//",
"scala": "//", "sql": "--", "tex": "%", "ada": "--", "ads": "--", "adb": "--", "pot": "#", "po": "#", "go": "//",
"ly": "%", "ily": "%"}
__comment__ = {
"java": "//",
"c": "//",
"cc": "//",
"cpp": "//",
"cs": "//",
"h": "//",
"hh": "//",
"hpp": "//",
"hs": "--",
"pl": "#",
"php": "//",
"py": "#",
"glsl": "//",
"rb": "#",
"robot": "#",
"rs": "//",
"rlib": "//",
"js": "//",
"scala": "//",
"sql": "--",
"tex": "%",
"ada": "--",
"ads": "--",
"adb": "--",
"pot": "#",
"po": "#",
"go": "//",
"ly": "%",
"ily": "%",
}
__comment_markers_must_be_at_begining__ = {"tex": True}
def __has_comment_begining__(extension, string):
if __comment_markers_must_be_at_begining__.get(extension, None) == True:
if __comment_markers_must_be_at_begining__.get(extension, None):
return string.find(__comment_begining__[extension]) == 0
elif __comment_begining__.get(extension, None) != None and string.find(__comment_end__[extension], 2) == -1:
elif __comment_begining__.get(extension, None) is not None and string.find(__comment_end__[extension], 2) == -1:
return string.find(__comment_begining__[extension]) != -1
return False
def __has_comment_end__(extension, string):
if __comment_markers_must_be_at_begining__.get(extension, None) == True:
if __comment_markers_must_be_at_begining__.get(extension, None):
return string.find(__comment_end__[extension]) == 0
elif __comment_end__.get(extension, None) != None:
elif __comment_end__.get(extension, None) is not None:
return string.find(__comment_end__[extension]) != -1
return False
def is_comment(extension, string):
if __comment_begining__.get(extension, None) != None and string.strip().startswith(__comment_begining__[extension]):
if __comment_begining__.get(extension, None) is not None and string.strip().startswith(__comment_begining__[extension]):
return True
if __comment_end__.get(extension, None) != None and string.strip().endswith(__comment_end__[extension]):
if __comment_end__.get(extension, None) is not None and string.strip().endswith(__comment_end__[extension]):
return True
if __comment__.get(extension, None) != None and string.strip().startswith(__comment__[extension]):
if __comment__.get(extension, None) is not None and string.strip().startswith(__comment__[extension]):
return True
return False
def handle_comment_block(is_inside_comment, extension, content):
comments = 0

View File

@ -22,6 +22,7 @@ import os
import subprocess
from . import extensions, filtering, format, interval, optval
class GitConfig(object):
def __init__(self, run, repo, global_only=False):
self.run = run
@ -31,8 +32,10 @@ class GitConfig(object):
def __read_git_config__(self, variable):
previous_directory = os.getcwd()
os.chdir(self.repo)
setting = subprocess.Popen([_f for _f in ["git", "config", "--global" if self.global_only else "",
"inspector." + variable] if _f], stdout=subprocess.PIPE).stdout
setting = subprocess.Popen(
[_f for _f in ["git", "config", "--global" if self.global_only else "", "inspector." + variable] if _f],
stdout=subprocess.PIPE,
).stdout
os.chdir(previous_directory)
try:

View File

@ -18,24 +18,27 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
DEFAULT_EXTENSIONS = ["java", "c", "cc", "cpp", "h", "hh", "hpp", "py", "glsl", "rb", "js", "sql"]
__extensions__ = DEFAULT_EXTENSIONS
__located_extensions__ = set()
def get():
return __extensions__
def define(string):
global __extensions__
__extensions__ = string.split(",")
def add_located(string):
if len(string) == 0:
__located_extensions__.add("*")
else:
__located_extensions__.add(string)
def get_located():
return __located_extensions__

View File

@ -21,17 +21,25 @@
import re
import subprocess
__filters__ = {"file": [set(), set()], "author": [set(), set()], "email": [set(), set()], "revision": [set(), set()],
"message" : [set(), None]}
__filters__ = {
"file": [set(), set()],
"author": [set(), set()],
"email": [set(), set()],
"revision": [set(), set()],
"message": [set(), None],
}
class InvalidRegExpError(ValueError):
def __init__(self, msg):
super(InvalidRegExpError, self).__init__(msg)
self.msg = msg
def get():
return __filters__
def __add_one__(string):
for i in __filters__:
if (i + ":").lower() == string[0:len(i) + 1].lower():
@ -39,27 +47,33 @@ def __add_one__(string):
return
__filters__["file"][0].add(string)
def add(string):
rules = string.split(",")
for rule in rules:
__add_one__(rule)
def clear():
for i in __filters__:
__filters__[i][0] = set()
def get_filered(filter_type="file"):
return __filters__[filter_type][1]
def has_filtered():
for i in __filters__:
if __filters__[i][1]:
return True
return False
def __find_commit_message__(sha):
git_show_r = subprocess.Popen([_f for _f in ["git", "show", "-s", "--pretty=%B", "-w", sha] if _f],
stdout=subprocess.PIPE).stdout
git_show_r = subprocess.Popen(
[_f for _f in ["git", "show", "-s", "--pretty=%B", "-w", sha] if _f], stdout=subprocess.PIPE
).stdout
commit_message = git_show_r.read()
git_show_r.close()
@ -68,6 +82,7 @@ def __find_commit_message__(sha):
commit_message = commit_message.encode("latin-1", "replace")
return commit_message.decode("utf-8", "replace")
def set_filtered(string, filter_type="file"):
string = string.strip()
@ -78,7 +93,7 @@ def set_filtered(string, filter_type="file"):
if filter_type == "message":
search_for = __find_commit_message__(string)
try:
if re.search(i, search_for) != None:
if re.search(i, search_for) is not None:
if filter_type == "message":
__add_one__("revision:" + string)
else:

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import base64
import os
import textwrap
@ -33,23 +32,28 @@ DEFAULT_FORMAT = __available_formats__[3]
__selected_format__ = DEFAULT_FORMAT
class InvalidFormatError(Exception):
def __init__(self, msg):
super(InvalidFormatError, self).__init__(msg)
self.msg = msg
def select(format):
global __selected_format__
__selected_format__ = format
return format in __available_formats__
def get_selected():
return __selected_format__
def is_interactive_format():
return __selected_format__ == "text"
def __output_html_template__(name):
template_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), name)
file_r = open(template_path, "rb")
@ -58,6 +62,7 @@ def __output_html_template__(name):
file_r.close()
return template
def __get_zip_file_content__(name, file_name="/html/flot.zip"):
zip_file = zipfile.ZipFile(basedir.get_basedir() + file_name, "r")
content = zip_file.read(name)
@ -65,17 +70,20 @@ def __get_zip_file_content__(name, file_name="/html/flot.zip"):
zip_file.close()
return content.decode("utf-8", "replace")
INFO_ONE_REPOSITORY = N_("Statistical information for the repository '{0}' was gathered on {1}.")
INFO_MANY_REPOSITORIES = N_("Statistical information for the repositories '{0}' was gathered on {1}.")
def output_header(repos):
repos_string = ", ".join([repo.name for repo in repos])
if __selected_format__ == "html" or __selected_format__ == "htmlembedded":
base = basedir.get_basedir()
html_header = __output_html_template__(base + "/html/html.header")
tablesorter_js = __get_zip_file_content__("jquery.tablesorter.min.js",
"/html/jquery.tablesorter.min.js.zip").encode("latin-1", "replace")
tablesorter_js = __get_zip_file_content__("jquery.tablesorter.min.js", "/html/jquery.tablesorter.min.js.zip").encode(
"latin-1", "replace"
)
tablesorter_js = tablesorter_js.decode("utf-8", "ignore")
flot_js = __get_zip_file_content__("jquery.flot.js")
pie_js = __get_zip_file_content__("jquery.flot.pie.js")
@ -89,40 +97,44 @@ def output_header(repos):
if __selected_format__ == "htmlembedded":
jquery_js = ">" + __get_zip_file_content__("jquery.js")
else:
jquery_js = " src=\"https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js\">"
jquery_js = ' src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">'
print(html_header.format(title=_("Repository statistics for '{0}'").format(repos_string),
print(
html_header.format(
title=_("Repository statistics for '{0}'").format(repos_string),
jquery=jquery_js,
jquery_tablesorter=tablesorter_js,
jquery_flot=flot_js,
jquery_flot_pie=pie_js,
jquery_flot_resize=resize_js,
logo=logo.decode("utf-8", "replace"),
logo_text=_("The output has been generated by {0} {1}. The statistical analysis tool"
" for git repositories.").format(
"<a href=\"https://github.com/ejwa/gitinspector\">gitinspector</a>",
version.__version__),
logo_text=_(
"The output has been generated by {0} {1}. The statistical analysis tool" " for git repositories."
).format('<a href="https://github.com/ejwa/gitinspector">gitinspector</a>', version.__version__),
repo_text=_(INFO_ONE_REPOSITORY if len(repos) <= 1 else INFO_MANY_REPOSITORIES).format(
repos_string, localization.get_date()),
repos_string, localization.get_date()
),
show_minor_authors=_("Show minor authors"),
hide_minor_authors=_("Hide minor authors"),
show_minor_rows=_("Show rows with minor work"),
hide_minor_rows=_("Hide rows with minor work")))
hide_minor_rows=_("Hide rows with minor work"),
)
)
elif __selected_format__ == "json":
print("{\n\t\"gitinspector\": {")
print("\t\t\"version\": \"" + version.__version__ + "\",")
print('{\n\t"gitinspector": {')
print('\t\t"version": "' + version.__version__ + '",')
if len(repos) <= 1:
print("\t\t\"repository\": \"" + repos_string + "\",")
print('\t\t"repository": "' + repos_string + '",')
else:
repos_json = "\t\t\"repositories\": [ "
repos_json = '\t\t"repositories": [ '
for repo in repos:
repos_json += "\"" + repo.name + "\", "
repos_json += '"' + repo.name + '", '
print(repos_json[:-2] + " ],")
print("\t\t\"report_date\": \"" + time.strftime("%Y/%m/%d") + "\",")
print('\t\t"report_date": "' + time.strftime("%Y/%m/%d") + '",')
elif __selected_format__ == "xml":
print("<gitinspector>")
@ -140,8 +152,15 @@ def output_header(repos):
print("\t<report-date>" + time.strftime("%Y/%m/%d") + "</report-date>")
else:
print(textwrap.fill(_(INFO_ONE_REPOSITORY if len(repos) <= 1 else INFO_MANY_REPOSITORIES).format(
repos_string, localization.get_date()), width=terminal.get_size()[0]))
print(
textwrap.fill(
_(INFO_ONE_REPOSITORY if len(repos) <= 1 else INFO_MANY_REPOSITORIES).format(
repos_string, localization.get_date()
),
width=terminal.get_size()[0],
)
)
def output_footer():
if __selected_format__ == "html" or __selected_format__ == "htmlembedded":

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import atexit
import getopt
import os
@ -27,8 +26,7 @@ from .blame import Blame
from .changes import Changes
from .config import GitConfig
from .metrics import MetricsLogic
from . import (basedir, clone, extensions, filtering, format, help, interval,
localization, optval, terminal, version)
from . import basedir, clone, extensions, filtering, format, help, interval, localization, optval, terminal, version
from .output import outputable
from .output.blameoutput import BlameOutput
from .output.changesoutput import ChangesOutput
@ -40,6 +38,7 @@ from .output.timelineoutput import TimelineOutput
localization.init()
class Runner(object):
def __init__(self):
self.hard = False
@ -102,22 +101,24 @@ class Runner(object):
format.output_footer()
os.chdir(previous_directory)
def __check_python_version__():
if sys.version_info < (2, 6):
python_version = str(sys.version_info[0]) + "." + str(sys.version_info[1])
sys.exit(_("gitinspector requires at least Python 2.6 to run (version {0} was found).").format(python_version))
def __get_validated_git_repos__(repos_relative):
if not repos_relative:
repos_relative = "."
repos = []
#Try to clone the repos or return the same directory and bail out.
# Try to clone the repos or return the same directory and bail out.
for repo in repos_relative:
cloned_repo = clone.create(repo)
if cloned_repo.name == None:
if cloned_repo.name is None:
cloned_repo.location = basedir.get_basedir_git(cloned_repo.location)
cloned_repo.name = os.path.basename(cloned_repo.location)
@ -125,6 +126,7 @@ def __get_validated_git_repos__(repos_relative):
return repos
def main():
terminal.check_terminal_encoding()
terminal.set_stdin_encoding()
@ -133,23 +135,40 @@ def main():
repos = []
try:
opts, args = optval.gnu_getopt(argv[1:], "f:F:hHlLmrTwx:", ["exclude=", "file-types=", "format=",
"hard:true", "help", "list-file-types:true", "localize-output:true",
"metrics:true", "responsibilities:true", "since=", "grading:true",
"timeline:true", "until=", "version", "weeks:true"])
opts, args = optval.gnu_getopt(
argv[1:],
"f:F:hHlLmrTwx:",
[
"exclude=",
"file-types=",
"format=",
"hard:true",
"help",
"list-file-types:true",
"localize-output:true",
"metrics:true",
"responsibilities:true",
"since=",
"grading:true",
"timeline:true",
"until=",
"version",
"weeks:true",
],
)
repos = __get_validated_git_repos__(set(args))
#We need the repos above to be set before we read the git config.
# We need the repos above to be set before we read the git config.
GitConfig(run, repos[-1].location).read()
clear_x_on_next_pass = True
for o, a in opts:
if o in("-h", "--help"):
if o in ("-h", "--help"):
help.output()
sys.exit(0)
elif o in("-f", "--file-types"):
elif o in ("-f", "--file-types"):
extensions.define(a)
elif o in("-F", "--format"):
elif o in ("-F", "--format"):
if not format.select(a):
raise format.InvalidFormatError(_("specified output format not supported."))
elif o == "-H":
@ -196,7 +215,7 @@ def main():
run.useweeks = True
elif o == "--weeks":
run.useweeks = optval.get_boolean_argument(a)
elif o in("-x", "--exclude"):
elif o in ("-x", "--exclude"):
if clear_x_on_next_pass:
clear_x_on_next_pass = False
filtering.clear()
@ -210,9 +229,11 @@ def main():
print(_("Try `{0} --help' for more information.").format(sys.argv[0]), file=sys.stderr)
sys.exit(2)
@atexit.register
def cleanup():
clone.delete()
if __name__ == "__main__":
main()

View File

@ -27,6 +27,7 @@ except:
from . import format
def get_url(email, size=20):
md5hash = hashlib.md5(email.encode("utf-8").lower().strip()).hexdigest()
base_url = "https://www.gravatar.com/avatar/" + md5hash

View File

@ -18,13 +18,13 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import sys
from .extensions import DEFAULT_EXTENSIONS
from .format import __available_formats__
__doc__ = _("""Usage: {0} [OPTION]... [REPOSITORY]...
__doc__ = _(
"""Usage: {0} [OPTION]... [REPOSITORY]...
List information about the repository in REPOSITORY. If no repository is
specified, the current directory is used. If multiple repositories are
given, information will be merged into a unified statistical report.
@ -76,7 +76,9 @@ add or remove one of the specified extensions, see -f or --file-types for
more information.
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."""
)
def output():
print(__doc__.format(sys.argv[0], ",".join(DEFAULT_EXTENSIONS), ",".join(__available_formats__)))

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
try:
from shlex import quote
except ImportError:
@ -30,26 +29,33 @@ __until__ = ""
__ref__ = "HEAD"
def has_interval():
return __since__ + __until__ != ""
def get_since():
return __since__
def set_since(since):
global __since__
__since__ = "--since=" + quote(since)
def get_until():
return __until__
def set_until(until):
global __until__
__until__ = "--until=" + quote(until)
def get_ref():
return __ref__
def set_ref(ref):
global __ref__
__ref__ = ref

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import gettext
import locale
import os
@ -31,10 +30,12 @@ __enabled__ = False
__installed__ = False
__translation__ = None
#Dummy function used to handle string constants
# Dummy function used to handle string constants
def N_(message):
return message
def init():
global __enabled__
global __installed__
@ -48,12 +49,12 @@ def init():
else:
lang = locale.getlocale()
#Fix for non-POSIX-compliant systems (Windows et al.).
if os.getenv('LANG') is None:
# Fix for non-POSIX-compliant systems (Windows et al.).
if os.getenv("LANG") is None:
lang = locale.getdefaultlocale()
if lang[0]:
os.environ['LANG'] = lang[0]
os.environ["LANG"] = lang[0]
if lang[0] is not None:
filename = basedir.get_basedir() + "/translations/messages_%s.mo" % lang[0][0:2]
@ -70,27 +71,32 @@ def init():
__installed__ = True
__translation__.install()
def check_compatibility(version):
if isinstance(__translation__, gettext.GNUTranslations):
header_pattern = re.compile("^([^:\n]+): *(.*?) *$", re.MULTILINE)
header_entries = dict(header_pattern.findall(_("")))
if header_entries["Project-Id-Version"] != "gitinspector {0}".format(version):
print("WARNING: The translation for your system locale is not up to date with the current gitinspector "
print(
"WARNING: The translation for your system locale is not up to date with the current gitinspector "
"version. The current maintainer of this locale is {0}.".format(header_entries["Last-Translator"]),
file=sys.stderr)
file=sys.stderr,
)
def get_date():
if __enabled__ and isinstance(__translation__, gettext.GNUTranslations):
date = time.strftime("%x")
if hasattr(date, 'decode'):
if hasattr(date, "decode"):
date = date.decode("utf-8", "replace")
return date
else:
return time.strftime("%Y/%m/%d")
def enable():
if isinstance(__translation__, gettext.GNUTranslations):
__translation__.install(True)
@ -98,6 +104,7 @@ def enable():
global __enabled__
__enabled__ = True
def disable():
global __enabled__
__enabled__ = False

View File

@ -23,29 +23,62 @@ import subprocess
from .changes import FileDiff
from . import comment, filtering, interval
__metric_eloc__ = {"java": 500, "c": 500, "cpp": 500, "cs": 500, "h": 300, "hpp": 300, "php": 500, "py": 500, "glsl": 1000,
"rb": 500, "js": 500, "sql": 1000, "xml": 1000}
__metric_eloc__ = {
"java": 500,
"c": 500,
"cpp": 500,
"cs": 500,
"h": 300,
"hpp": 300,
"php": 500,
"py": 500,
"glsl": 1000,
"rb": 500,
"js": 500,
"sql": 1000,
"xml": 1000,
}
__metric_cc_tokens__ = [[["java", "js", "c", "cc", "cpp"], ["else", r"for\s+\(.*\)", r"if\s+\(.*\)", r"case\s+\w+:",
"default:", r"while\s+\(.*\)"],
["assert", "break", "continue", "return"]],
[["cs"], ["else", r"for\s+\(.*\)", r"foreach\s+\(.*\)", r"goto\s+\w+:", r"if\s+\(.*\)", r"case\s+\w+:",
"default:", r"while\s+\(.*\)"],
["assert", "break", "continue", "return"]],
[["py"], [r"^\s+elif .*:$", r"^\s+else:$", r"^\s+for .*:", r"^\s+if .*:$", r"^\s+while .*:$"],
[r"^\s+assert", "break", "continue", "return"]]]
__metric_cc_tokens__ = [
[
["java", "js", "c", "cc", "cpp"],
["else", r"for\s+\(.*\)", r"if\s+\(.*\)", r"case\s+\w+:", "default:", r"while\s+\(.*\)"],
["assert", "break", "continue", "return"],
],
[
["cs"],
[
"else",
r"for\s+\(.*\)",
r"foreach\s+\(.*\)",
r"goto\s+\w+:",
r"if\s+\(.*\)",
r"case\s+\w+:",
"default:",
r"while\s+\(.*\)",
],
["assert", "break", "continue", "return"],
],
[
["py"],
[r"^\s+elif .*:$", r"^\s+else:$", r"^\s+for .*:", r"^\s+if .*:$", r"^\s+while .*:$"],
[r"^\s+assert", "break", "continue", "return"],
],
]
METRIC_CYCLOMATIC_COMPLEXITY_THRESHOLD = 50
METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD = 0.75
class MetricsLogic(object):
def __init__(self):
self.eloc = {}
self.cyclomatic_complexity = {}
self.cyclomatic_complexity_density = {}
ls_tree_p = subprocess.Popen(["git", "ls-tree", "--name-only", "-r", interval.get_ref()],
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
ls_tree_p = subprocess.Popen(
["git", "ls-tree", "--name-only", "-r", interval.get_ref()], stdout=subprocess.PIPE, stderr=subprocess.STDOUT
)
lines = ls_tree_p.communicate()[0].splitlines()
ls_tree_p.stdout.close()
@ -53,17 +86,18 @@ class MetricsLogic(object):
for i in lines:
i = i.strip().decode("unicode_escape", "ignore")
i = i.encode("latin-1", "replace")
i = i.decode("utf-8", "replace").strip("\"").strip("'").strip()
i = i.decode("utf-8", "replace").strip('"').strip("'").strip()
if FileDiff.is_valid_extension(i) and not filtering.set_filtered(FileDiff.get_filename(i)):
file_r = subprocess.Popen(["git", "show", interval.get_ref() + ":{0}".format(i.strip())],
stdout=subprocess.PIPE).stdout.readlines()
file_r = subprocess.Popen(
["git", "show", interval.get_ref() + ":{0}".format(i.strip())], stdout=subprocess.PIPE
).stdout.readlines()
extension = FileDiff.get_extension(i)
lines = MetricsLogic.get_eloc(file_r, extension)
cycc = MetricsLogic.get_cyclomatic_complexity(file_r, extension)
if __metric_eloc__.get(extension, None) != None and __metric_eloc__[extension] < lines:
if __metric_eloc__.get(extension, None) is not None and __metric_eloc__[extension] < lines:
self.eloc[i.strip()] = lines
if METRIC_CYCLOMATIC_COMPLEXITY_THRESHOLD < cycc:
@ -79,7 +113,7 @@ class MetricsLogic(object):
self.cyclomatic_complexity_density.update(other.cyclomatic_complexity_density)
return self
except AttributeError:
return other;
return other
@staticmethod
def get_cyclomatic_complexity(file_r, extension):

View File

@ -20,11 +20,13 @@
import getopt
class InvalidOptionArgument(Exception):
def __init__(self, msg):
super(InvalidOptionArgument, self).__init__(msg)
self.msg = msg
def __find_arg_in_options__(arg, options):
for opt in options:
if opt[0].find(arg) == 0:
@ -32,6 +34,7 @@ def __find_arg_in_options__(arg, options):
return None
def __find_options_to_extend__(long_options):
options_to_extend = []
@ -43,8 +46,10 @@ def __find_options_to_extend__(long_options):
return options_to_extend
# This is a duplicate of gnu_getopt, but with support for optional arguments in long options, in the form; "arg:default_value".
def gnu_getopt(args, options, long_options):
options_to_extend = __find_options_to_extend__(long_options)
@ -55,10 +60,11 @@ def gnu_getopt(args, options, long_options):
return getopt.gnu_getopt(args, options, long_options)
def get_boolean_argument(arg):
if isinstance(arg, bool):
return arg
elif arg == None or arg.lower() == "false" or arg.lower() == "f" or arg == "0":
elif arg is None or arg.lower() == "false" or arg.lower() == "f" or arg == "0":
return False
elif arg.lower() == "true" or arg.lower() == "t" or arg == "1":
return True

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import json
import sys
import textwrap
@ -27,8 +26,10 @@ from .. import format, gravatar, terminal
from ..blame import Blame
from .outputable import Outputable
BLAME_INFO_TEXT = N_("Below are the number of rows from each author that have survived and are still "
"intact in the current revision")
BLAME_INFO_TEXT = N_(
"Below are the number of rows from each author that have survived and are still " "intact in the current revision"
)
class BlameOutput(Outputable):
def __init__(self, changes, blame):
@ -40,10 +41,11 @@ class BlameOutput(Outputable):
Outputable.__init__(self)
def output_html(self):
blame_xml = "<div><div class=\"box\">"
blame_xml += "<p>" + _(BLAME_INFO_TEXT) + ".</p><div><table id=\"blame\" class=\"git\">"
blame_xml = '<div><div class="box">'
blame_xml += "<p>" + _(BLAME_INFO_TEXT) + '.</p><div><table id="blame" class="git">'
blame_xml += "<thead><tr> <th>{0}</th> <th>{1}</th> <th>{2}</th> <th>{3}</th> <th>{4}</th> </tr></thead>".format(
_("Author"), _("Rows"), _("Stability"), _("Age"), _("% in comments"))
_("Author"), _("Rows"), _("Stability"), _("Age"), _("% in comments")
)
blame_xml += "<tbody>"
chart_data = ""
blames = sorted(self.blame.get_summed_blames().items())
@ -54,11 +56,11 @@ class BlameOutput(Outputable):
for i, entry in enumerate(blames):
work_percentage = str("{0:.2f}".format(100.0 * entry[1].rows / total_blames))
blame_xml += "<tr " + ("class=\"odd\">" if i % 2 == 1 else ">")
blame_xml += "<tr " + ('class="odd">' if i % 2 == 1 else ">")
if format.get_selected() == "html":
author_email = self.changes.get_latest_email_by_author(entry[0])
blame_xml += "<td><img src=\"{0}\"/>{1}</td>".format(gravatar.get_url(author_email), entry[0])
blame_xml += '<td><img src="{0}"/>{1}</td>'.format(gravatar.get_url(author_email), entry[0])
else:
blame_xml += "<td>" + entry[0] + "</td>"
@ -66,24 +68,24 @@ class BlameOutput(Outputable):
blame_xml += "<td>" + ("{0:.1f}".format(Blame.get_stability(entry[0], entry[1].rows, self.changes)) + "</td>")
blame_xml += "<td>" + "{0:.1f}".format(float(entry[1].skew) / entry[1].rows) + "</td>"
blame_xml += "<td>" + "{0:.2f}".format(100.0 * entry[1].comments / entry[1].rows) + "</td>"
blame_xml += "<td style=\"display: none\">" + work_percentage + "</td>"
blame_xml += '<td style="display: none">' + work_percentage + "</td>"
blame_xml += "</tr>"
chart_data += "{{label: {0}, data: {1}}}".format(json.dumps(entry[0]), work_percentage)
if blames[-1] != entry:
chart_data += ", "
blame_xml += "<tfoot><tr> <td colspan=\"5\">&nbsp;</td> </tr></tfoot></tbody></table>"
blame_xml += "<div class=\"chart\" id=\"blame_chart\"></div></div>"
blame_xml += "<script type=\"text/javascript\">"
blame_xml += " blame_plot = $.plot($(\"#blame_chart\"), [{0}], {{".format(chart_data)
blame_xml += '<tfoot><tr> <td colspan="5">&nbsp;</td> </tr></tfoot></tbody></table>'
blame_xml += '<div class="chart" id="blame_chart"></div></div>'
blame_xml += '<script type="text/javascript">'
blame_xml += ' blame_plot = $.plot($("#blame_chart"), [{0}], {{'.format(chart_data)
blame_xml += " series: {"
blame_xml += " pie: {"
blame_xml += " innerRadius: 0.4,"
blame_xml += " show: true,"
blame_xml += " combine: {"
blame_xml += " threshold: 0.01,"
blame_xml += " label: \"" + _("Minor Authors") + "\""
blame_xml += ' label: "' + _("Minor Authors") + '"'
blame_xml += " }"
blame_xml += " }"
blame_xml += " }, grid: {"
@ -95,35 +97,51 @@ class BlameOutput(Outputable):
print(blame_xml)
def output_json(self):
message_json = "\t\t\t\"message\": \"" + _(BLAME_INFO_TEXT) + "\",\n"
message_json = '\t\t\t"message": "' + _(BLAME_INFO_TEXT) + '",\n'
blame_json = ""
for i in sorted(self.blame.get_summed_blames().items()):
author_email = self.changes.get_latest_email_by_author(i[0])
name_json = "\t\t\t\t\"name\": \"" + i[0] + "\",\n"
email_json = "\t\t\t\t\"email\": \"" + author_email + "\",\n"
gravatar_json = "\t\t\t\t\"gravatar\": \"" + gravatar.get_url(author_email) + "\",\n"
rows_json = "\t\t\t\t\"rows\": " + str(i[1].rows) + ",\n"
stability_json = ("\t\t\t\t\"stability\": " + "{0:.1f}".format(Blame.get_stability(i[0], i[1].rows,
self.changes)) + ",\n")
age_json = ("\t\t\t\t\"age\": " + "{0:.1f}".format(float(i[1].skew) / i[1].rows) + ",\n")
percentage_in_comments_json = ("\t\t\t\t\"percentage_in_comments\": " +
"{0:.2f}".format(100.0 * i[1].comments / i[1].rows) + "\n")
blame_json += ("{\n" + name_json + email_json + gravatar_json + rows_json + stability_json + age_json +
percentage_in_comments_json + "\t\t\t},")
name_json = '\t\t\t\t"name": "' + i[0] + '",\n'
email_json = '\t\t\t\t"email": "' + author_email + '",\n'
gravatar_json = '\t\t\t\t"gravatar": "' + gravatar.get_url(author_email) + '",\n'
rows_json = '\t\t\t\t"rows": ' + str(i[1].rows) + ",\n"
stability_json = (
'\t\t\t\t"stability": ' + "{0:.1f}".format(Blame.get_stability(i[0], i[1].rows, self.changes)) + ",\n"
)
age_json = '\t\t\t\t"age": ' + "{0:.1f}".format(float(i[1].skew) / i[1].rows) + ",\n"
percentage_in_comments_json = (
'\t\t\t\t"percentage_in_comments": ' + "{0:.2f}".format(100.0 * i[1].comments / i[1].rows) + "\n"
)
blame_json += (
"{\n"
+ name_json
+ email_json
+ gravatar_json
+ rows_json
+ stability_json
+ age_json
+ percentage_in_comments_json
+ "\t\t\t},"
)
else:
blame_json = blame_json[:-1]
print(",\n\t\t\"blame\": {\n" + message_json + "\t\t\t\"authors\": [\n\t\t\t" + blame_json + "]\n\t\t}", end="")
print(',\n\t\t"blame": {\n' + message_json + '\t\t\t"authors": [\n\t\t\t' + blame_json + "]\n\t\t}", end="")
def output_text(self):
if sys.stdout.isatty() and format.is_interactive_format():
terminal.clear_row()
print(textwrap.fill(_(BLAME_INFO_TEXT) + ":", width=terminal.get_size()[0]) + "\n")
terminal.printb(terminal.ljust(_("Author"), 21) + terminal.rjust(_("Rows"), 10) + terminal.rjust(_("Stability"), 15) +
terminal.rjust(_("Age"), 13) + terminal.rjust(_("% in comments"), 20))
terminal.printb(
terminal.ljust(_("Author"), 21)
+ terminal.rjust(_("Rows"), 10)
+ terminal.rjust(_("Stability"), 15)
+ terminal.rjust(_("Age"), 13)
+ terminal.rjust(_("% in comments"), 20)
)
for i in sorted(self.blame.get_summed_blames().items()):
print(terminal.ljust(i[0], 20)[0:20 - terminal.get_excess_column_count(i[0])], end=" ")
@ -143,12 +161,25 @@ class BlameOutput(Outputable):
email_xml = "\t\t\t\t<email>" + author_email + "</email>\n"
gravatar_xml = "\t\t\t\t<gravatar>" + gravatar.get_url(author_email) + "</gravatar>\n"
rows_xml = "\t\t\t\t<rows>" + str(i[1].rows) + "</rows>\n"
stability_xml = ("\t\t\t\t<stability>" + "{0:.1f}".format(Blame.get_stability(i[0], i[1].rows,
self.changes)) + "</stability>\n")
age_xml = ("\t\t\t\t<age>" + "{0:.1f}".format(float(i[1].skew) / i[1].rows) + "</age>\n")
percentage_in_comments_xml = ("\t\t\t\t<percentage-in-comments>" + "{0:.2f}".format(100.0 * i[1].comments / i[1].rows) +
"</percentage-in-comments>\n")
blame_xml += ("\t\t\t<author>\n" + name_xml + email_xml + gravatar_xml + rows_xml + stability_xml +
age_xml + percentage_in_comments_xml + "\t\t\t</author>\n")
stability_xml = (
"\t\t\t\t<stability>" + "{0:.1f}".format(Blame.get_stability(i[0], i[1].rows, self.changes)) + "</stability>\n"
)
age_xml = "\t\t\t\t<age>" + "{0:.1f}".format(float(i[1].skew) / i[1].rows) + "</age>\n"
percentage_in_comments_xml = (
"\t\t\t\t<percentage-in-comments>"
+ "{0:.2f}".format(100.0 * i[1].comments / i[1].rows)
+ "</percentage-in-comments>\n"
)
blame_xml += (
"\t\t\t<author>\n"
+ name_xml
+ email_xml
+ gravatar_xml
+ rows_xml
+ stability_xml
+ age_xml
+ percentage_in_comments_xml
+ "\t\t\t</author>\n"
)
print("\t<blame>\n" + message_xml + "\t\t<authors>\n" + blame_xml + "\t\t</authors>\n\t</blame>")

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import json
import textwrap
from ..localization import N_
@ -28,6 +27,7 @@ from .outputable import Outputable
HISTORICAL_INFO_TEXT = N_("The following historical commit information, by author, was found")
NO_COMMITED_FILES_TEXT = N_("No commited files with the specified extensions were found")
class ChangesOutput(Outputable):
def __init__(self, changes):
self.changes = changes
@ -36,7 +36,7 @@ class ChangesOutput(Outputable):
def output_html(self):
authorinfo_list = self.changes.get_authorinfo_list()
total_changes = 0.0
changes_xml = "<div><div class=\"box\">"
changes_xml = '<div><div class="box">'
chart_data = ""
for i in authorinfo_list:
@ -44,20 +44,22 @@ class ChangesOutput(Outputable):
total_changes += authorinfo_list.get(i).deletions
if authorinfo_list:
changes_xml += "<p>" + _(HISTORICAL_INFO_TEXT) + ".</p><div><table id=\"changes\" class=\"git\">"
changes_xml += "<p>" + _(HISTORICAL_INFO_TEXT) + '.</p><div><table id="changes" class="git">'
changes_xml += "<thead><tr> <th>{0}</th> <th>{1}</th> <th>{2}</th> <th>{3}</th> <th>{4}</th>".format(
_("Author"), _("Commits"), _("Insertions"), _("Deletions"), _("% of changes"))
_("Author"), _("Commits"), _("Insertions"), _("Deletions"), _("% of changes")
)
changes_xml += "</tr></thead><tbody>"
for i, entry in enumerate(sorted(authorinfo_list)):
authorinfo = authorinfo_list.get(entry)
percentage = 0 if total_changes == 0 else (authorinfo.insertions + authorinfo.deletions) / total_changes * 100
changes_xml += "<tr " + ("class=\"odd\">" if i % 2 == 1 else ">")
changes_xml += "<tr " + ('class="odd">' if i % 2 == 1 else ">")
if format.get_selected() == "html":
changes_xml += "<td><img src=\"{0}\"/>{1}</td>".format(
gravatar.get_url(self.changes.get_latest_email_by_author(entry)), entry)
changes_xml += '<td><img src="{0}"/>{1}</td>'.format(
gravatar.get_url(self.changes.get_latest_email_by_author(entry)), entry
)
else:
changes_xml += "<td>" + entry + "</td>"
@ -71,17 +73,17 @@ class ChangesOutput(Outputable):
if sorted(authorinfo_list)[-1] != entry:
chart_data += ", "
changes_xml += ("<tfoot><tr> <td colspan=\"5\">&nbsp;</td> </tr></tfoot></tbody></table>")
changes_xml += "<div class=\"chart\" id=\"changes_chart\"></div></div>"
changes_xml += "<script type=\"text/javascript\">"
changes_xml += " changes_plot = $.plot($(\"#changes_chart\"), [{0}], {{".format(chart_data)
changes_xml += '<tfoot><tr> <td colspan="5">&nbsp;</td> </tr></tfoot></tbody></table>'
changes_xml += '<div class="chart" id="changes_chart"></div></div>'
changes_xml += '<script type="text/javascript">'
changes_xml += ' changes_plot = $.plot($("#changes_chart"), [{0}], {{'.format(chart_data)
changes_xml += " series: {"
changes_xml += " pie: {"
changes_xml += " innerRadius: 0.4,"
changes_xml += " show: true,"
changes_xml += " combine: {"
changes_xml += " threshold: 0.01,"
changes_xml += " label: \"" + _("Minor Authors") + "\""
changes_xml += ' label: "' + _("Minor Authors") + '"'
changes_xml += " }"
changes_xml += " }"
changes_xml += " }, grid: {"
@ -104,7 +106,7 @@ class ChangesOutput(Outputable):
total_changes += authorinfo_list.get(i).deletions
if authorinfo_list:
message_json = "\t\t\t\"message\": \"" + _(HISTORICAL_INFO_TEXT) + "\",\n"
message_json = '\t\t\t"message": "' + _(HISTORICAL_INFO_TEXT) + '",\n'
changes_json = ""
for i in sorted(authorinfo_list):
@ -112,23 +114,32 @@ class ChangesOutput(Outputable):
authorinfo = authorinfo_list.get(i)
percentage = 0 if total_changes == 0 else (authorinfo.insertions + authorinfo.deletions) / total_changes * 100
name_json = "\t\t\t\t\"name\": \"" + i + "\",\n"
email_json = "\t\t\t\t\"email\": \"" + author_email + "\",\n"
gravatar_json = "\t\t\t\t\"gravatar\": \"" + gravatar.get_url(author_email) + "\",\n"
commits_json = "\t\t\t\t\"commits\": " + str(authorinfo.commits) + ",\n"
insertions_json = "\t\t\t\t\"insertions\": " + str(authorinfo.insertions) + ",\n"
deletions_json = "\t\t\t\t\"deletions\": " + str(authorinfo.deletions) + ",\n"
percentage_json = "\t\t\t\t\"percentage_of_changes\": " + "{0:.2f}".format(percentage) + "\n"
name_json = '\t\t\t\t"name": "' + i + '",\n'
email_json = '\t\t\t\t"email": "' + author_email + '",\n'
gravatar_json = '\t\t\t\t"gravatar": "' + gravatar.get_url(author_email) + '",\n'
commits_json = '\t\t\t\t"commits": ' + str(authorinfo.commits) + ",\n"
insertions_json = '\t\t\t\t"insertions": ' + str(authorinfo.insertions) + ",\n"
deletions_json = '\t\t\t\t"deletions": ' + str(authorinfo.deletions) + ",\n"
percentage_json = '\t\t\t\t"percentage_of_changes": ' + "{0:.2f}".format(percentage) + "\n"
changes_json += ("{\n" + name_json + email_json + gravatar_json + commits_json +
insertions_json + deletions_json + percentage_json + "\t\t\t}")
changes_json += (
"{\n"
+ name_json
+ email_json
+ gravatar_json
+ commits_json
+ insertions_json
+ deletions_json
+ percentage_json
+ "\t\t\t}"
)
changes_json += ","
else:
changes_json = changes_json[:-1]
print("\t\t\"changes\": {\n" + message_json + "\t\t\t\"authors\": [\n\t\t\t" + changes_json + "]\n\t\t}", end="")
print('\t\t"changes": {\n' + message_json + '\t\t\t"authors": [\n\t\t\t' + changes_json + "]\n\t\t}", end="")
else:
print("\t\t\"exception\": \"" + _(NO_COMMITED_FILES_TEXT) + "\"")
print('\t\t"exception": "' + _(NO_COMMITED_FILES_TEXT) + '"')
def output_text(self):
authorinfo_list = self.changes.get_authorinfo_list()
@ -140,9 +151,13 @@ class ChangesOutput(Outputable):
if authorinfo_list:
print(textwrap.fill(_(HISTORICAL_INFO_TEXT) + ":", width=terminal.get_size()[0]) + "\n")
terminal.printb(terminal.ljust(_("Author"), 21) + terminal.rjust(_("Commits"), 13) +
terminal.rjust(_("Insertions"), 14) + terminal.rjust(_("Deletions"), 15) +
terminal.rjust(_("% of changes"), 16))
terminal.printb(
terminal.ljust(_("Author"), 21)
+ terminal.rjust(_("Commits"), 13)
+ terminal.rjust(_("Insertions"), 14)
+ terminal.rjust(_("Deletions"), 15)
+ terminal.rjust(_("% of changes"), 16)
)
for i in sorted(authorinfo_list):
authorinfo = authorinfo_list.get(i)
@ -179,10 +194,21 @@ class ChangesOutput(Outputable):
commits_xml = "\t\t\t\t<commits>" + str(authorinfo.commits) + "</commits>\n"
insertions_xml = "\t\t\t\t<insertions>" + str(authorinfo.insertions) + "</insertions>\n"
deletions_xml = "\t\t\t\t<deletions>" + str(authorinfo.deletions) + "</deletions>\n"
percentage_xml = "\t\t\t\t<percentage-of-changes>" + "{0:.2f}".format(percentage) + "</percentage-of-changes>\n"
percentage_xml = (
"\t\t\t\t<percentage-of-changes>" + "{0:.2f}".format(percentage) + "</percentage-of-changes>\n"
)
changes_xml += ("\t\t\t<author>\n" + name_xml + email_xml + gravatar_xml + commits_xml +
insertions_xml + deletions_xml + percentage_xml + "\t\t\t</author>\n")
changes_xml += (
"\t\t\t<author>\n"
+ name_xml
+ email_xml
+ gravatar_xml
+ commits_xml
+ insertions_xml
+ deletions_xml
+ percentage_xml
+ "\t\t\t</author>\n"
)
print("\t<changes>\n" + message_xml + "\t\t<authors>\n" + changes_xml + "\t\t</authors>\n\t</changes>")
else:

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import textwrap
from ..localization import N_
from .. import extensions, terminal
@ -28,6 +27,7 @@ from .outputable import Outputable
EXTENSIONS_INFO_TEXT = N_("The extensions below were found in the repository history")
EXTENSIONS_MARKED_TEXT = N_("(extensions used during statistical analysis are marked)")
class ExtensionsOutput(Outputable):
@staticmethod
def is_marked(extension):
@ -38,7 +38,7 @@ class ExtensionsOutput(Outputable):
def output_html(self):
if extensions.__located_extensions__:
extensions_xml = "<div><div class=\"box\">"
extensions_xml = '<div><div class="box">'
extensions_xml += "<p>{0} {1}.</p><p>".format(_(EXTENSIONS_INFO_TEXT), _(EXTENSIONS_MARKED_TEXT))
for i in sorted(extensions.__located_extensions__):
@ -53,32 +53,45 @@ class ExtensionsOutput(Outputable):
def output_json(self):
if extensions.__located_extensions__:
message_json = "\t\t\t\"message\": \"" + _(EXTENSIONS_INFO_TEXT) + "\",\n"
message_json = '\t\t\t"message": "' + _(EXTENSIONS_INFO_TEXT) + '",\n'
used_extensions_json = ""
unused_extensions_json = ""
for i in sorted(extensions.__located_extensions__):
if ExtensionsOutput.is_marked(i):
used_extensions_json += "\"" + i + "\", "
used_extensions_json += '"' + i + '", '
else:
unused_extensions_json += "\"" + i + "\", "
unused_extensions_json += '"' + i + '", '
used_extensions_json = used_extensions_json[:-2]
unused_extensions_json = unused_extensions_json[:-2]
print(",\n\t\t\"extensions\": {\n" + message_json + "\t\t\t\"used\": [ " + used_extensions_json +
" ],\n\t\t\t\"unused\": [ " + unused_extensions_json + " ]\n" + "\t\t}", end="")
print(
',\n\t\t"extensions": {\n'
+ message_json
+ '\t\t\t"used": [ '
+ used_extensions_json
+ ' ],\n\t\t\t"unused": [ '
+ unused_extensions_json
+ " ]\n"
+ "\t\t}",
end="",
)
def output_text(self):
if extensions.__located_extensions__:
print("\n" + textwrap.fill("{0} {1}:".format(_(EXTENSIONS_INFO_TEXT), _(EXTENSIONS_MARKED_TEXT)),
width=terminal.get_size()[0]))
print(
"\n"
+ textwrap.fill(
"{0} {1}:".format(_(EXTENSIONS_INFO_TEXT), _(EXTENSIONS_MARKED_TEXT)), width=terminal.get_size()[0]
)
)
for i in sorted(extensions.__located_extensions__):
if ExtensionsOutput.is_marked(i):
print("[" + terminal.__bold__ + i + terminal.__normal__ + "]", end=" ")
else:
print (i, end=" ")
print(i, end=" ")
print("")
def output_xml(self):
@ -93,5 +106,14 @@ class ExtensionsOutput(Outputable):
else:
unused_extensions_xml += "\t\t\t<extension>" + i + "</extension>\n"
print("\t<extensions>\n" + message_xml + "\t\t<used>\n" + used_extensions_xml + "\t\t</used>\n" +
"\t\t<unused>\n" + unused_extensions_xml + "\t\t</unused>\n" + "\t</extensions>")
print(
"\t<extensions>\n"
+ message_xml
+ "\t\t<used>\n"
+ used_extensions_xml
+ "\t\t</used>\n"
+ "\t\t<unused>\n"
+ unused_extensions_xml
+ "\t\t</unused>\n"
+ "\t</extensions>"
)

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import textwrap
from ..localization import N_
from ..filtering import __filters__, has_filtered
@ -26,11 +25,16 @@ from .. import terminal
from .outputable import Outputable
FILTERING_INFO_TEXT = N_("The following files were excluded from the statistics due to the specified exclusion patterns")
FILTERING_AUTHOR_INFO_TEXT = N_("The following authors were excluded from the statistics due to the specified exclusion patterns")
FILTERING_EMAIL_INFO_TEXT = N_("The authors with the following emails were excluded from the statistics due to the specified " \
"exclusion patterns")
FILTERING_COMMIT_INFO_TEXT = N_("The following commit revisions were excluded from the statistics due to the specified " \
"exclusion patterns")
FILTERING_AUTHOR_INFO_TEXT = N_(
"The following authors were excluded from the statistics due to the specified exclusion patterns"
)
FILTERING_EMAIL_INFO_TEXT = N_(
"The authors with the following emails were excluded from the statistics due to the specified " "exclusion patterns"
)
FILTERING_COMMIT_INFO_TEXT = N_(
"The following commit revisions were excluded from the statistics due to the specified " "exclusion patterns"
)
class FilteringOutput(Outputable):
@staticmethod
@ -38,7 +42,7 @@ class FilteringOutput(Outputable):
filtering_xml = ""
if filtered:
filtering_xml += "<p>" + info_string + "."+ "</p>"
filtering_xml += "<p>" + info_string + "." + "</p>"
for i in filtered:
filtering_xml += "<p>" + i + "</p>"
@ -47,7 +51,7 @@ class FilteringOutput(Outputable):
def output_html(self):
if has_filtered():
filtering_xml = "<div><div class=\"box\">"
filtering_xml = '<div><div class="box">'
FilteringOutput.__output_html_section__(_(FILTERING_INFO_TEXT), __filters__["file"][1])
FilteringOutput.__output_html_section__(_(FILTERING_AUTHOR_INFO_TEXT), __filters__["author"][1])
FilteringOutput.__output_html_section__(_(FILTERING_EMAIL_INFO_TEXT), __filters__["email"][1])
@ -59,26 +63,35 @@ class FilteringOutput(Outputable):
@staticmethod
def __output_json_section__(info_string, filtered, container_tagname):
if filtered:
message_json = "\t\t\t\t\"message\": \"" + info_string + "\",\n"
message_json = '\t\t\t\t"message": "' + info_string + '",\n'
filtering_json = ""
for i in filtered:
filtering_json += "\t\t\t\t\t\"" + i + "\",\n"
filtering_json += '\t\t\t\t\t"' + i + '",\n'
else:
filtering_json = filtering_json[:-3]
return "\n\t\t\t\"{0}\": {{\n".format(container_tagname) + message_json + \
"\t\t\t\t\"entries\": [\n" + filtering_json + "\"\n\t\t\t\t]\n\t\t\t},"
return (
'\n\t\t\t"{0}": {{\n'.format(container_tagname)
+ message_json
+ '\t\t\t\t"entries": [\n'
+ filtering_json
+ '"\n\t\t\t\t]\n\t\t\t},'
)
return ""
def output_json(self):
if has_filtered():
output = ",\n\t\t\"filtering\": {"
output = ',\n\t\t"filtering": {'
output += FilteringOutput.__output_json_section__(_(FILTERING_INFO_TEXT), __filters__["file"][1], "files")
output += FilteringOutput.__output_json_section__(_(FILTERING_AUTHOR_INFO_TEXT), __filters__["author"][1], "authors")
output += FilteringOutput.__output_json_section__(
_(FILTERING_AUTHOR_INFO_TEXT), __filters__["author"][1], "authors"
)
output += FilteringOutput.__output_json_section__(_(FILTERING_EMAIL_INFO_TEXT), __filters__["email"][1], "emails")
output += FilteringOutput.__output_json_section__(_(FILTERING_COMMIT_INFO_TEXT), __filters__["revision"][1], "revision")
output += FilteringOutput.__output_json_section__(
_(FILTERING_COMMIT_INFO_TEXT), __filters__["revision"][1], "revision"
)
output = output[:-1]
output += "\n\t\t}"
print(output, end="")
@ -90,7 +103,7 @@ class FilteringOutput(Outputable):
for i in filtered:
(width, _unused) = 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)
def output_text(self):
FilteringOutput.__output_text_section__(_(FILTERING_INFO_TEXT), __filters__["file"][1])

View File

@ -18,25 +18,27 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from ..changes import FileDiff
from ..localization import N_
from ..metrics import (__metric_eloc__, METRIC_CYCLOMATIC_COMPLEXITY_THRESHOLD, METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD)
from ..metrics import __metric_eloc__, METRIC_CYCLOMATIC_COMPLEXITY_THRESHOLD, METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD
from .outputable import Outputable
ELOC_INFO_TEXT = N_("The following files are suspiciously big (in order of severity)")
CYCLOMATIC_COMPLEXITY_TEXT = N_("The following files have an elevated cyclomatic complexity (in order of severity)")
CYCLOMATIC_COMPLEXITY_DENSITY_TEXT = N_("The following files have an elevated cyclomatic complexity density " \
"(in order of severity)")
CYCLOMATIC_COMPLEXITY_DENSITY_TEXT = N_(
"The following files have an elevated cyclomatic complexity density " "(in order of severity)"
)
METRICS_MISSING_INFO_TEXT = N_("No metrics violations were found in the repository")
METRICS_VIOLATION_SCORES = [[1.0, "minimal"], [1.25, "minor"], [1.5, "medium"], [2.0, "bad"], [3.0, "severe"]]
def __get_metrics_score__(ceiling, value):
for i in reversed(METRICS_VIOLATION_SCORES):
if value > ceiling * i[0]:
return i[1]
class MetricsOutput(Outputable):
def __init__(self, metrics):
self.metrics = metrics
@ -58,11 +60,13 @@ class MetricsOutput(Outputable):
if self.metrics.cyclomatic_complexity_density:
print("\n" + _(CYCLOMATIC_COMPLEXITY_DENSITY_TEXT) + ":")
for i in sorted(set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity_density.items())]), reverse=True):
for i in sorted(
set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity_density.items())]), reverse=True
):
print(_("{0} ({1:.3f} in cyclomatic complexity density)").format(i[1], i[0]))
def output_html(self):
metrics_xml = "<div><div class=\"box\" id=\"metrics\">"
metrics_xml = '<div><div class="box" id="metrics">'
if not self.metrics.eloc and not self.metrics.cyclomatic_complexity and not self.metrics.cyclomatic_complexity_density:
metrics_xml += "<p>" + _(METRICS_MISSING_INFO_TEXT) + ".</p>"
@ -70,25 +74,41 @@ class MetricsOutput(Outputable):
if self.metrics.eloc:
metrics_xml += "<div><h4>" + _(ELOC_INFO_TEXT) + ".</h4>"
for num, i in enumerate(sorted(set([(j, i) for (i, j) in list(self.metrics.eloc.items())]), reverse=True)):
metrics_xml += "<div class=\"" + __get_metrics_score__(__metric_eloc__[FileDiff.get_extension(i[1])], i[0]) + \
(" odd\">" if num % 2 == 1 else "\">") + \
_("{0} ({1} estimated lines of code)").format(i[1], str(i[0])) + "</div>"
metrics_xml += (
'<div class="'
+ __get_metrics_score__(__metric_eloc__[FileDiff.get_extension(i[1])], i[0])
+ (' odd">' if num % 2 == 1 else '">')
+ _("{0} ({1} estimated lines of code)").format(i[1], str(i[0]))
+ "</div>"
)
metrics_xml += "</div>"
if self.metrics.cyclomatic_complexity:
metrics_xml += "<div><h4>" + _(CYCLOMATIC_COMPLEXITY_TEXT) + "</h4>"
for num, i in enumerate(sorted(set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity.items())]), reverse=True)):
metrics_xml += "<div class=\"" + __get_metrics_score__(METRIC_CYCLOMATIC_COMPLEXITY_THRESHOLD, i[0]) + \
(" odd\">" if num % 2 == 1 else "\">") + \
_("{0} ({1} in cyclomatic complexity)").format(i[1], str(i[0])) + "</div>"
for num, i in enumerate(
sorted(set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity.items())]), reverse=True)
):
metrics_xml += (
'<div class="'
+ __get_metrics_score__(METRIC_CYCLOMATIC_COMPLEXITY_THRESHOLD, i[0])
+ (' odd">' if num % 2 == 1 else '">')
+ _("{0} ({1} in cyclomatic complexity)").format(i[1], str(i[0]))
+ "</div>"
)
metrics_xml += "</div>"
if self.metrics.cyclomatic_complexity_density:
metrics_xml += "<div><h4>" + _(CYCLOMATIC_COMPLEXITY_DENSITY_TEXT) + "</h4>"
for num, i in enumerate(sorted(set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity_density.items())]), reverse=True)):
metrics_xml += "<div class=\"" + __get_metrics_score__(METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD, i[0]) + \
(" odd\">" if num % 2 == 1 else "\">") + \
_("{0} ({1:.3f} in cyclomatic complexity density)").format(i[1], i[0]) + "</div>"
for num, i in enumerate(
sorted(set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity_density.items())]), reverse=True)
):
metrics_xml += (
'<div class="'
+ __get_metrics_score__(METRIC_CYCLOMATIC_COMPLEXITY_DENSITY_THRESHOLD, i[0])
+ (' odd">' if num % 2 == 1 else '">')
+ _("{0} ({1:.3f} in cyclomatic complexity density)").format(i[1], i[0])
+ "</div>"
)
metrics_xml += "</div>"
metrics_xml += "</div></div>"
@ -96,15 +116,15 @@ class MetricsOutput(Outputable):
def output_json(self):
if not self.metrics.eloc and not self.metrics.cyclomatic_complexity and not self.metrics.cyclomatic_complexity_density:
print(",\n\t\t\"metrics\": {\n\t\t\t\"message\": \"" + _(METRICS_MISSING_INFO_TEXT) + "\"\n\t\t}", end="")
print(',\n\t\t"metrics": {\n\t\t\t"message": "' + _(METRICS_MISSING_INFO_TEXT) + '"\n\t\t}', end="")
else:
eloc_json = ""
if self.metrics.eloc:
for i in sorted(set([(j, i) for (i, j) in list(self.metrics.eloc.items())]), reverse=True):
eloc_json += "{\n\t\t\t\t\"type\": \"estimated-lines-of-code\",\n"
eloc_json += "\t\t\t\t\"file_name\": \"" + i[1] + "\",\n"
eloc_json += "\t\t\t\t\"value\": " + str(i[0]) + "\n"
eloc_json += '{\n\t\t\t\t"type": "estimated-lines-of-code",\n'
eloc_json += '\t\t\t\t"file_name": "' + i[1] + '",\n'
eloc_json += '\t\t\t\t"value": ' + str(i[0]) + "\n"
eloc_json += "\t\t\t},"
else:
if not self.metrics.cyclomatic_complexity:
@ -112,24 +132,27 @@ class MetricsOutput(Outputable):
if self.metrics.cyclomatic_complexity:
for i in sorted(set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity.items())]), reverse=True):
eloc_json += "{\n\t\t\t\t\"type\": \"cyclomatic-complexity\",\n"
eloc_json += "\t\t\t\t\"file_name\": \"" + i[1] + "\",\n"
eloc_json += "\t\t\t\t\"value\": " + str(i[0]) + "\n"
eloc_json += '{\n\t\t\t\t"type": "cyclomatic-complexity",\n'
eloc_json += '\t\t\t\t"file_name": "' + i[1] + '",\n'
eloc_json += '\t\t\t\t"value": ' + str(i[0]) + "\n"
eloc_json += "\t\t\t},"
else:
if not self.metrics.cyclomatic_complexity_density:
eloc_json = eloc_json[:-1]
if self.metrics.cyclomatic_complexity_density:
for i in sorted(set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity_density.items())]), reverse=True):
eloc_json += "{\n\t\t\t\t\"type\": \"cyclomatic-complexity-density\",\n"
eloc_json += "\t\t\t\t\"file_name\": \"" + i[1] + "\",\n"
eloc_json += "\t\t\t\t\"value\": {0:.3f}\n".format(i[0])
for i in sorted(
set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity_density.items())]), reverse=True
):
eloc_json += '{\n\t\t\t\t"type": "cyclomatic-complexity-density",\n'
eloc_json += '\t\t\t\t"file_name": "' + i[1] + '",\n'
eloc_json += '\t\t\t\t"value": {0:.3f}\n'.format(i[0])
eloc_json += "\t\t\t},"
else:
eloc_json = eloc_json[:-1]
print(",\n\t\t\"metrics\": {\n\t\t\t\"violations\": [\n\t\t\t" + eloc_json + "]\n\t\t}", end="")
print(',\n\t\t"metrics": {\n\t\t\t"violations": [\n\t\t\t' + eloc_json + "]\n\t\t}", end="")
def output_xml(self):
if not self.metrics.eloc and not self.metrics.cyclomatic_complexity and not self.metrics.cyclomatic_complexity_density:
print("\t<metrics>\n\t\t<message>" + _(METRICS_MISSING_INFO_TEXT) + "</message>\n\t</metrics>")
@ -151,7 +174,9 @@ class MetricsOutput(Outputable):
eloc_xml += "\t\t\t</cyclomatic-complexity>\n"
if self.metrics.cyclomatic_complexity_density:
for i in sorted(set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity_density.items())]), reverse=True):
for i in sorted(
set([(j, i) for (i, j) in list(self.metrics.cyclomatic_complexity_density.items())]), reverse=True
):
eloc_xml += "\t\t\t<cyclomatic-complexity-density>\n"
eloc_xml += "\t\t\t\t<file-name>" + i[1] + "</file-name>\n"
eloc_xml += "\t\t\t\t<value>{0:.3f}</value>\n".format(i[0])

View File

@ -18,21 +18,22 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from .. import format
class Outputable(object):
def output_html(self):
raise NotImplementedError(_("HTML output not yet supported in") + " \"" + self.__class__.__name__ + "\".")
raise NotImplementedError(_("HTML output not yet supported in") + ' "' + self.__class__.__name__ + '".')
def output_json(self):
raise NotImplementedError(_("JSON output not yet supported in") + " \"" + self.__class__.__name__ + "\".")
raise NotImplementedError(_("JSON output not yet supported in") + ' "' + self.__class__.__name__ + '".')
def output_text(self):
raise NotImplementedError(_("Text output not yet supported in") + " \"" + self.__class__.__name__ + "\".")
raise NotImplementedError(_("Text output not yet supported in") + ' "' + self.__class__.__name__ + '".')
def output_xml(self):
raise NotImplementedError(_("XML output not yet supported in") + " \"" + self.__class__.__name__ + "\".")
raise NotImplementedError(_("XML output not yet supported in") + ' "' + self.__class__.__name__ + '".')
def output(outputable):
if format.get_selected() == "html" or format.get_selected() == "htmlembedded":

View File

@ -18,18 +18,20 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import textwrap
from ..localization import N_
from .. import format, gravatar, terminal
from .. import responsibilities as resp
from .outputable import Outputable
RESPONSIBILITIES_INFO_TEXT = N_("The following responsibilities, by author, were found in the current "
RESPONSIBILITIES_INFO_TEXT = N_(
"The following responsibilities, by author, were found in the current "
"revision of the repository (comments are excluded from the line count, "
"if possible)")
"if possible)"
)
MOSTLY_RESPONSIBLE_FOR_TEXT = N_("is mostly responsible for")
class ResponsibilitiesOutput(Outputable):
def __init__(self, changes, blame):
self.changes = changes
@ -50,13 +52,13 @@ class ResponsibilitiesOutput(Outputable):
width -= 7
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:
break
def output_html(self):
resp_xml = "<div><div class=\"box\" id=\"responsibilities\">"
resp_xml = '<div><div class="box" id="responsibilities">'
resp_xml += "<p>" + _(RESPONSIBILITIES_INFO_TEXT) + ".</p>"
for i in sorted(set(i[0] for i in self.blame.blames)):
@ -67,14 +69,16 @@ class ResponsibilitiesOutput(Outputable):
if format.get_selected() == "html":
author_email = self.changes.get_latest_email_by_author(i)
resp_xml += "<h3><img src=\"{0}\"/>{1} {2}</h3>".format(gravatar.get_url(author_email, size=32),
i, _(MOSTLY_RESPONSIBLE_FOR_TEXT))
resp_xml += '<h3><img src="{0}"/>{1} {2}</h3>'.format(
gravatar.get_url(author_email, size=32), i, _(MOSTLY_RESPONSIBLE_FOR_TEXT)
)
else:
resp_xml += "<h3>{0} {1}</h3>".format(i, _(MOSTLY_RESPONSIBLE_FOR_TEXT))
for j, entry in enumerate(responsibilities):
resp_xml += "<div" + (" class=\"odd\">" if j % 2 == 1 else ">") + entry[1] + \
" (" + str(entry[0]) + " eloc)</div>"
resp_xml += (
"<div" + (' class="odd">' if j % 2 == 1 else ">") + entry[1] + " (" + str(entry[0]) + " eloc)</div>"
)
if j >= 9:
break
@ -83,7 +87,7 @@ class ResponsibilitiesOutput(Outputable):
print(resp_xml)
def output_json(self):
message_json = "\t\t\t\"message\": \"" + _(RESPONSIBILITIES_INFO_TEXT) + "\",\n"
message_json = '\t\t\t"message": "' + _(RESPONSIBILITIES_INFO_TEXT) + '",\n'
resp_json = ""
for i in sorted(set(i[0] for i in self.blame.blames)):
@ -93,15 +97,15 @@ class ResponsibilitiesOutput(Outputable):
author_email = self.changes.get_latest_email_by_author(i)
resp_json += "{\n"
resp_json += "\t\t\t\t\"name\": \"" + i + "\",\n"
resp_json += "\t\t\t\t\"email\": \"" + author_email + "\",\n"
resp_json += "\t\t\t\t\"gravatar\": \"" + gravatar.get_url(author_email) + "\",\n"
resp_json += "\t\t\t\t\"files\": [\n\t\t\t\t"
resp_json += '\t\t\t\t"name": "' + i + '",\n'
resp_json += '\t\t\t\t"email": "' + author_email + '",\n'
resp_json += '\t\t\t\t"gravatar": "' + gravatar.get_url(author_email) + '",\n'
resp_json += '\t\t\t\t"files": [\n\t\t\t\t'
for j, entry in enumerate(responsibilities):
resp_json += "{\n"
resp_json += "\t\t\t\t\t\"name\": \"" + entry[1] + "\",\n"
resp_json += "\t\t\t\t\t\"rows\": " + str(entry[0]) + "\n"
resp_json += '\t\t\t\t\t"name": "' + entry[1] + '",\n'
resp_json += '\t\t\t\t\t"rows": ' + str(entry[0]) + "\n"
resp_json += "\t\t\t\t},"
if j >= 9:
@ -111,7 +115,7 @@ class ResponsibilitiesOutput(Outputable):
resp_json += "]\n\t\t\t},"
resp_json = resp_json[:-1]
print(",\n\t\t\"responsibilities\": {\n" + message_json + "\t\t\t\"authors\": [\n\t\t\t" + resp_json + "]\n\t\t}", end="")
print(',\n\t\t"responsibilities": {\n' + message_json + '\t\t\t"authors": [\n\t\t\t' + resp_json + "]\n\t\t}", end="")
def output_xml(self):
message_xml = "\t\t<message>" + _(RESPONSIBILITIES_INFO_TEXT) + "</message>\n"

View File

@ -18,7 +18,6 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
import textwrap
from ..localization import N_
from .. import format, gravatar, terminal, timeline
@ -27,6 +26,7 @@ from .outputable import Outputable
TIMELINE_INFO_TEXT = N_("The following history timeline has been gathered from the repository")
MODIFIED_ROWS_TEXT = N_("Modified Rows:")
def __output_row__text__(timeline_data, periods, names):
print("\n" + terminal.__bold__ + terminal.ljust(_("Author"), 20), end=" ")
@ -42,9 +42,13 @@ def __output_row__text__(timeline_data, periods, names):
for period in periods:
multiplier = timeline_data.get_multiplier(period, 9)
signs = timeline_data.get_author_signs_in_period(name[0], period, multiplier)
signs_str = (signs[1] * "-" + signs[0] * "+")
print (("." if timeline_data.is_author_in_period(period, name[0]) and
len(signs_str) == 0 else signs_str).rjust(10), end=" ")
signs_str = signs[1] * "-" + signs[0] * "+"
print(
("." if timeline_data.is_author_in_period(period, name[0]) and len(signs_str) == 0 else signs_str).rjust(
10
),
end=" ",
)
print("")
print(terminal.__bold__ + terminal.ljust(_(MODIFIED_ROWS_TEXT), 20) + terminal.__normal__, end=" ")
@ -52,15 +56,16 @@ def __output_row__text__(timeline_data, periods, names):
for period in periods:
total_changes = str(timeline_data.get_total_changes_in_period(period)[2])
if hasattr(total_changes, 'decode'):
if hasattr(total_changes, "decode"):
total_changes = total_changes.decode("utf-8", "replace")
print(terminal.rjust(total_changes, 10), end=" ")
print("")
def __output_row__html__(timeline_data, periods, names):
timeline_xml = "<table class=\"git full\"><thead><tr><th>" + _("Author") + "</th>"
timeline_xml = '<table class="git full"><thead><tr><th>' + _("Author") + "</th>"
for period in periods:
timeline_xml += "<th>" + str(period) + "</th>"
@ -70,19 +75,21 @@ def __output_row__html__(timeline_data, periods, names):
for name in names:
if timeline_data.is_author_in_periods(periods, name[0]):
timeline_xml += "<tr" + (" class=\"odd\">" if i % 2 == 1 else ">")
timeline_xml += "<tr" + (' class="odd">' if i % 2 == 1 else ">")
if format.get_selected() == "html":
timeline_xml += "<td><img src=\"{0}\"/>{1}</td>".format(gravatar.get_url(name[1]), name[0])
timeline_xml += '<td><img src="{0}"/>{1}</td>'.format(gravatar.get_url(name[1]), name[0])
else:
timeline_xml += "<td>" + name[0] + "</td>"
for period in periods:
multiplier = timeline_data.get_multiplier(period, 18)
signs = timeline_data.get_author_signs_in_period(name[0], period, multiplier)
signs_str = (signs[1] * "<div class=\"remove\">&nbsp;</div>" + signs[0] * "<div class=\"insert\">&nbsp;</div>")
signs_str = signs[1] * '<div class="remove">&nbsp;</div>' + signs[0] * '<div class="insert">&nbsp;</div>'
timeline_xml += "<td>" + ("." if timeline_data.is_author_in_period(period, name[0]) and len(signs_str) == 0 else signs_str)
timeline_xml += "<td>" + (
"." if timeline_data.is_author_in_period(period, name[0]) and len(signs_str) == 0 else signs_str
)
timeline_xml += "</td>"
timeline_xml += "</tr>"
i = i + 1
@ -96,6 +103,7 @@ def __output_row__html__(timeline_data, periods, names):
timeline_xml += "</tr></tfoot></tbody></table>"
print(timeline_xml)
class TimelineOutput(Outputable):
def __init__(self, changes, useweeks):
self.changes = changes
@ -113,7 +121,7 @@ class TimelineOutput(Outputable):
max_periods_per_row = int((width - 21) / 11)
for i in range(0, len(periods), max_periods_per_row):
__output_row__text__(timeline_data, periods[i:i+max_periods_per_row], names)
__output_row__text__(timeline_data, periods[i:i + max_periods_per_row], names)
def output_html(self):
if self.changes.get_commits():
@ -122,61 +130,62 @@ class TimelineOutput(Outputable):
names = timeline_data.get_authors()
max_periods_per_row = 8
timeline_xml = "<div><div id=\"timeline\" class=\"box\">"
timeline_xml = '<div><div id="timeline" class="box">'
timeline_xml += "<p>" + _(TIMELINE_INFO_TEXT) + ".</p>"
print(timeline_xml)
for i in range(0, len(periods), max_periods_per_row):
__output_row__html__(timeline_data, periods[i:i+max_periods_per_row], names)
__output_row__html__(timeline_data, periods[i:i + max_periods_per_row], names)
timeline_xml = "</div></div>"
print(timeline_xml)
def output_json(self):
if self.changes.get_commits():
message_json = "\t\t\t\"message\": \"" + _(TIMELINE_INFO_TEXT) + "\",\n"
message_json = '\t\t\t"message": "' + _(TIMELINE_INFO_TEXT) + '",\n'
timeline_json = ""
periods_json = "\t\t\t\"period_length\": \"{0}\",\n".format("week" if self.useweeks else "month")
periods_json += "\t\t\t\"periods\": [\n\t\t\t"
periods_json = '\t\t\t"period_length": "{0}",\n'.format("week" if self.useweeks else "month")
periods_json += '\t\t\t"periods": [\n\t\t\t'
timeline_data = timeline.TimelineData(self.changes, self.useweeks)
periods = timeline_data.get_periods()
names = timeline_data.get_authors()
for period in periods:
name_json = "\t\t\t\t\"name\": \"" + str(period) + "\",\n"
authors_json = "\t\t\t\t\"authors\": [\n\t\t\t\t"
name_json = '\t\t\t\t"name": "' + str(period) + '",\n'
authors_json = '\t\t\t\t"authors": [\n\t\t\t\t'
for name in names:
if timeline_data.is_author_in_period(period, name[0]):
multiplier = timeline_data.get_multiplier(period, 24)
signs = timeline_data.get_author_signs_in_period(name[0], period, multiplier)
signs_str = (signs[1] * "-" + signs[0] * "+")
signs_str = signs[1] * "-" + signs[0] * "+"
if len(signs_str) == 0:
signs_str = "."
authors_json += "{\n\t\t\t\t\t\"name\": \"" + name[0] + "\",\n"
authors_json += "\t\t\t\t\t\"email\": \"" + name[1] + "\",\n"
authors_json += "\t\t\t\t\t\"gravatar\": \"" + gravatar.get_url(name[1]) + "\",\n"
authors_json += "\t\t\t\t\t\"work\": \"" + signs_str + "\"\n\t\t\t\t},"
authors_json += '{\n\t\t\t\t\t"name": "' + name[0] + '",\n'
authors_json += '\t\t\t\t\t"email": "' + name[1] + '",\n'
authors_json += '\t\t\t\t\t"gravatar": "' + gravatar.get_url(name[1]) + '",\n'
authors_json += '\t\t\t\t\t"work": "' + signs_str + '"\n\t\t\t\t},'
else:
authors_json = authors_json[:-1]
authors_json += "],\n"
modified_rows_json = "\t\t\t\t\"modified_rows\": " + \
str(timeline_data.get_total_changes_in_period(period)[2]) + "\n"
modified_rows_json = (
'\t\t\t\t"modified_rows": ' + str(timeline_data.get_total_changes_in_period(period)[2]) + "\n"
)
timeline_json += "{\n" + name_json + authors_json + modified_rows_json + "\t\t\t},"
else:
timeline_json = timeline_json[:-1]
print(",\n\t\t\"timeline\": {\n" + message_json + periods_json + timeline_json + "]\n\t\t}", end="")
print(',\n\t\t"timeline": {\n' + message_json + periods_json + timeline_json + "]\n\t\t}", end="")
def output_xml(self):
if self.changes.get_commits():
message_xml = "\t\t<message>" + _(TIMELINE_INFO_TEXT) + "</message>\n"
timeline_xml = ""
periods_xml = "\t\t<periods length=\"{0}\">\n".format("week" if self.useweeks else "month")
periods_xml = '\t\t<periods length="{0}">\n'.format("week" if self.useweeks else "month")
timeline_data = timeline.TimelineData(self.changes, self.useweeks)
periods = timeline_data.get_periods()
@ -190,7 +199,7 @@ class TimelineOutput(Outputable):
if timeline_data.is_author_in_period(period, name[0]):
multiplier = timeline_data.get_multiplier(period, 24)
signs = timeline_data.get_author_signs_in_period(name[0], period, multiplier)
signs_str = (signs[1] * "-" + signs[0] * "+")
signs_str = signs[1] * "-" + signs[0] * "+"
if len(signs_str) == 0:
signs_str = "."
@ -201,8 +210,11 @@ class TimelineOutput(Outputable):
authors_xml += "\t\t\t\t\t\t<work>" + signs_str + "</work>\n\t\t\t\t\t</author>\n"
authors_xml += "\t\t\t\t</authors>\n"
modified_rows_xml = "\t\t\t\t<modified_rows>" + \
str(timeline_data.get_total_changes_in_period(period)[2]) + "</modified_rows>\n"
modified_rows_xml = (
"\t\t\t\t<modified_rows>"
+ str(timeline_data.get_total_changes_in_period(period)[2])
+ "</modified_rows>\n"
)
timeline_xml += "\t\t\t<period>\n" + name_xml + authors_xml + modified_rows_xml + "\t\t\t</period>\n"
print("\t<timeline>\n" + message_xml + periods_xml + timeline_xml + "\t\t</periods>\n\t</timeline>")

View File

@ -18,11 +18,10 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
class ResponsibiltyEntry(object):
blames = {}
class Responsibilities(object):
@staticmethod
def get(blame, author_name):

View File

@ -29,6 +29,7 @@ __normal__ = "\033[0;0m"
DEFAULT_TERMINAL_SIZE = (80, 25)
def __get_size_windows__():
res = None
try:
@ -42,6 +43,7 @@ def __get_size_windows__():
if res:
import struct
(_, _, _, _, _, left, top, right, bottom, _, _) = struct.unpack("hhhhHhhhhhh", csbi.raw)
sizex = right - left + 1
sizey = bottom - top + 1
@ -49,11 +51,13 @@ def __get_size_windows__():
else:
return DEFAULT_TERMINAL_SIZE
def __get_size_linux__():
def ioctl_get_window_size(file_descriptor):
try:
import fcntl, termios, struct
size = struct.unpack('hh', fcntl.ioctl(file_descriptor, termios.TIOCGWINSZ, "1234"))
size = struct.unpack("hh", fcntl.ioctl(file_descriptor, termios.TIOCGWINSZ, "1234"))
except:
return DEFAULT_TERMINAL_SIZE
@ -76,9 +80,11 @@ def __get_size_linux__():
return int(size[1]), int(size[0])
def clear_row():
print("\r", end="")
def skip_escapes(skip):
if skip:
global __bold__
@ -86,9 +92,11 @@ def skip_escapes(skip):
__bold__ = ""
__normal__ = ""
def printb(string):
print(__bold__ + string + __normal__)
def get_size():
width = 0
height = 0
@ -106,14 +114,17 @@ def get_size():
return DEFAULT_TERMINAL_SIZE
def set_stdout_encoding():
if not sys.stdout.isatty() and sys.version_info < (3,):
sys.stdout = codecs.getwriter("utf-8")(sys.stdout)
def set_stdin_encoding():
if not sys.stdin.isatty() and sys.version_info < (3,):
sys.stdin = codecs.getreader("utf-8")(sys.stdin)
def convert_command_line_to_utf8():
try:
argv = []
@ -125,13 +136,20 @@ def convert_command_line_to_utf8():
except AttributeError:
return sys.argv
def check_terminal_encoding():
if sys.stdout.isatty() and (sys.stdout.encoding == None or sys.stdin.encoding == None):
print(_("WARNING: The terminal encoding is not correctly configured. gitinspector might malfunction. "
"The encoding can be configured with the environment variable 'PYTHONIOENCODING'."), file=sys.stderr)
if sys.stdout.isatty() and (sys.stdout.encoding is None or sys.stdin.encoding is None):
print(
_(
"WARNING: The terminal encoding is not correctly configured. gitinspector might malfunction. "
"The encoding can be configured with the environment variable 'PYTHONIOENCODING'."
),
file=sys.stderr,
)
def get_excess_column_count(string):
width_mapping = {'F': 2, 'H': 1, 'W': 2, 'Na': 1, 'N': 1, 'A': 1}
width_mapping = {"F": 2, "H": 1, "W": 2, "Na": 1, "N": 1, "A": 1}
result = 0
for i in string:
@ -140,19 +158,22 @@ def get_excess_column_count(string):
return result - len(string)
def ljust(string, pad):
return string.ljust(pad - get_excess_column_count(string))
def rjust(string, pad):
return string.rjust(pad - get_excess_column_count(string))
def output_progress(text, pos, length):
if sys.stdout.isatty():
(width, _unused) = get_size()
progress_text = text.format(100 * pos / length)
if len(progress_text) > width:
progress_text = "...%s" % progress_text[-width+3:]
progress_text = "...%s" % progress_text[-width + 3:]
print("\r{0}\r{1}".format(" " * width, progress_text), end="")
sys.stdout.flush()

View File

@ -20,6 +20,7 @@
import datetime
class TimelineData(object):
def __init__(self, changes, useweeks):
authordateinfo_list = sorted(changes.get_authordateinfo_list().items())
@ -37,7 +38,7 @@ class TimelineData(object):
else:
key = (i[0][1], i[0][0][0:7])
if self.entries.get(key, None) == None:
if self.entries.get(key, None) is None:
self.entries[key] = i[1]
else:
self.entries[key].insertions += i[1].insertions
@ -49,12 +50,11 @@ class TimelineData(object):
for author in self.get_authors():
entry = self.entries.get((author[0], period), None)
if entry != None:
if entry is not None:
total_insertions += entry.insertions
total_deletions += entry.deletions
self.total_changes_by_period[period] = (total_insertions, total_deletions,
total_insertions + total_deletions)
self.total_changes_by_period[period] = (total_insertions, total_deletions, total_insertions + total_deletions)
def get_periods(self):
return sorted(set([i[1] for i in self.entries]))
@ -91,7 +91,7 @@ class TimelineData(object):
multiplier += 0.25
def is_author_in_period(self, period, author):
return self.entries.get((author, period), None) != None
return self.entries.get((author, period), None) is not None
def is_author_in_periods(self, periods, author):
for period in periods:

View File

@ -18,17 +18,21 @@
# along with gitinspector. If not, see <http://www.gnu.org/licenses/>.
from . import localization
localization.init()
__version__ = "0.5.0dev"
__doc__ = _("""Copyright © 2012-2015 Ejwa Software. All rights reserved.
__doc__ = _(
"""Copyright © 2012-2015 Ejwa Software. All rights reserved.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Adam Waldenberg.""")
Written by Adam Waldenberg."""
)
def output():
print("gitinspector {0}\n".format(__version__) + __doc__)

View File

@ -19,10 +19,10 @@
from __future__ import unicode_literals
import os
import sys
import unittest
import gitinspector.comment
def __test_extension__(commented_file, extension):
base = os.path.dirname(os.path.realpath(__file__))
tex_file = open(base + commented_file, "r")
@ -38,11 +38,13 @@ def __test_extension__(commented_file, extension):
return comment_counter
class TexFileTest(unittest.TestCase):
def test(self):
comment_counter = __test_extension__("/resources/commented_file.tex", "tex")
self.assertEqual(comment_counter, 30)
class CppFileTest(unittest.TestCase):
def test(self):
comment_counter = __test_extension__("/resources/commented_file.cpp", "cpp")