Skip to content
Snippets Groups Projects
Commit ec13a727 authored by Nick Mathewson's avatar Nick Mathewson :game_die:
Browse files

practracker: Rename "Problem" to "Item".

I'm about to refactor the code into a set of iterators that yield
*all* the metrics for the code, and then add a filter on top of that
to return the problems.
parent 3efe5cc5
No related branches found
No related tags found
No related merge requests found
......@@ -65,7 +65,7 @@ def consider_file_size(fname, f):
file_size = metrics.get_file_len(f)
if file_size > MAX_FILE_SIZE:
p = problem.FileSizeProblem(fname, file_size)
p = problem.FileSizeItem(fname, file_size)
if ProblemVault.register_problem(p):
return 1
return 0
......@@ -75,7 +75,7 @@ def consider_includes(fname, f):
include_count = metrics.get_include_count(f)
if include_count > MAX_INCLUDE_COUNT:
p = problem.IncludeCountProblem(fname, include_count)
p = problem.IncludeCountItem(fname, include_count)
if ProblemVault.register_problem(p):
return 1
return 0
......@@ -91,7 +91,7 @@ def consider_function_size(fname, f):
# That's a big function! Issue a problem!
canonical_function_name = "%s:%s()" % (fname, name)
p = problem.FunctionSizeProblem(canonical_function_name, lines)
p = problem.FunctionSizeItem(canonical_function_name, lines)
if ProblemVault.register_problem(p):
found_new_issues += 1
......
......@@ -100,10 +100,10 @@ class ProblemVault(object):
if fn is not None:
ex.metric_value = fn(ex.metric_value)
class Problem(object):
class Item(object):
"""
A generic problem in our source code. See the subclasses below for the
specific problems we are trying to tackle.
A generic measurement about some aspect of our source code. See
the subclasses below for the specific problems we are trying to tackle.
"""
def __init__(self, problem_type, problem_location, metric_value):
self.problem_location = problem_location
......@@ -125,7 +125,7 @@ class Problem(object):
def key(self):
"""Generate a unique key that describes this problem that can be used as a dictionary key"""
# Problem location is a filesystem path, so we need to normalize this
# Item location is a filesystem path, so we need to normalize this
# across platforms otherwise same paths are not gonna match.
canonical_location = os.path.normcase(self.problem_location)
return "%s:%s" % (canonical_location, self.problem_type)
......@@ -133,7 +133,7 @@ class Problem(object):
def __str__(self):
return "problem %s %s %s" % (self.problem_type, self.problem_location, self.metric_value)
class FileSizeProblem(Problem):
class FileSizeItem(Item):
"""
Denotes a problem with the size of a .c file.
......@@ -141,9 +141,9 @@ class FileSizeProblem(Problem):
'metric_value' is the number of lines in the .c file.
"""
def __init__(self, problem_location, metric_value):
super(FileSizeProblem, self).__init__("file-size", problem_location, metric_value)
super(FileSizeItem, self).__init__("file-size", problem_location, metric_value)
class IncludeCountProblem(Problem):
class IncludeCountItem(Item):
"""
Denotes a problem with the number of #includes in a .c file.
......@@ -151,9 +151,9 @@ class IncludeCountProblem(Problem):
'metric_value' is the number of #includes in the .c file.
"""
def __init__(self, problem_location, metric_value):
super(IncludeCountProblem, self).__init__("include-count", problem_location, metric_value)
super(IncludeCountItem, self).__init__("include-count", problem_location, metric_value)
class FunctionSizeProblem(Problem):
class FunctionSizeItem(Item):
"""
Denotes a problem with a size of a function in a .c file.
......@@ -164,7 +164,7 @@ class FunctionSizeProblem(Problem):
The 'metric_value' is the size of the offending function in lines.
"""
def __init__(self, problem_location, metric_value):
super(FunctionSizeProblem, self).__init__("function-size", problem_location, metric_value)
super(FunctionSizeItem, self).__init__("function-size", problem_location, metric_value)
comment_re = re.compile(r'#.*$')
......@@ -182,10 +182,10 @@ def get_old_problem_from_exception_str(exception_str):
raise ValueError("Misformatted line {!r}".format(orig_str))
if problem_type == "file-size":
return FileSizeProblem(problem_location, metric_value)
return FileSizeItem(problem_location, metric_value)
elif problem_type == "include-count":
return IncludeCountProblem(problem_location, metric_value)
return IncludeCountItem(problem_location, metric_value)
elif problem_type == "function-size":
return FunctionSizeProblem(problem_location, metric_value)
return FunctionSizeItem(problem_location, metric_value)
else:
raise ValueError("Unknown exception type {!r}".format(orig_str))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment