Skip to content

Commit

Permalink
webfaf: Move out JSON-encoding to to_json()
Browse files Browse the repository at this point in the history
So that the encoder stops growing and we stop importing everything
everywhere.
  • Loading branch information
ernestask authored and mkutlak committed Mar 20, 2020
1 parent e9e72d7 commit 1b3490c
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 58 deletions.
11 changes: 11 additions & 0 deletions src/pyfaf/storage/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ class Problem(GenericTable):
secondary=ProblemComponent.__table__,
order_by=ProblemComponent.order)

def to_json(self):
return {
"id": self.id,
"components": self.unique_component_names,
"crash_function": self.crash_function,
"bugs": [bug.url for bug in self.bugs],
"status": self.status,
"type": self.type,
"reports": self.reports,
}

@property
def unique_component_names(self):
return set(c.name for c in self.components)
Expand Down
53 changes: 53 additions & 0 deletions src/pyfaf/storage/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ class Report(GenericTable):
problem = relationship(Problem, backref="reports")
max_certainty = Column(Integer, nullable=True)

def to_json(self):
return {
"id": self.id,
"bugs": [bug.url for bug in self.bugs],
"component": self.component,
"count": self.count,
"first_occurrence": self.first_occurrence,
"last_occurrence": self.last_occurrence,
"problem_id": self.problem_id,
"comments": self.comments,
}

@property
def bugs(self):
# must be imported here to avoid dependency circle
Expand Down Expand Up @@ -268,6 +280,23 @@ class ReportBtFrame(GenericTable):
passive_deletes=True))
symbolsource = relationship(SymbolSource, backref=backref('frames'))

def to_json(self):
name = " "

if self.symbolsource.symbol is not None:
if self.symbolsource.symbol.nice_name:
name = self.symbolsource.symbol.nice_name
else:
name = self.symbolsource.symbol.name

return {
"frame": self.order,
"name": name,
"binary_path": self.symbolsource.path,
"source_path": self.symbolsource.source_path,
"line_numer": self.symbolsource.line_number,
}


class ReportBtHash(GenericTable):
__tablename__ = "reportbthashes"
Expand Down Expand Up @@ -434,6 +463,12 @@ class ReportHistoryMonthly(GenericTable):
unique = Column(Integer, nullable=False, default=0, server_default="0")
opsysrelease = relationship(OpSysRelease)

def to_json(self):
return {
"date": self.month,
"count": self.count,
}


class ReportHistoryWeekly(GenericTable):
__tablename__ = "reporthistoryweekly"
Expand All @@ -447,6 +482,12 @@ class ReportHistoryWeekly(GenericTable):
unique = Column(Integer, nullable=False, default=0, server_default="0")
opsysrelease = relationship(OpSysRelease)

def to_json(self):
return {
"week": self.week,
"count": self.count,
}


class ReportHistoryDaily(GenericTable):
__tablename__ = "reporthistorydaily"
Expand All @@ -459,6 +500,12 @@ class ReportHistoryDaily(GenericTable):
unique = Column(Integer, nullable=False, default=0, server_default="0")
opsysrelease = relationship(OpSysRelease)

def to_json(self):
return {
"day": self.day,
"count": self.count,
}


class KernelTaintFlag(GenericTable):
__tablename__ = "kerneltaintedflags"
Expand Down Expand Up @@ -570,6 +617,12 @@ class ReportComment(GenericTable):

report = relationship(Report, backref="comments")

def to_json(self):
return {
"saved": self.saved,
"text": self.text,
}


class ReportReleaseDesktop(GenericTable):
__tablename__ = "reportreleasedesktops"
Expand Down
58 changes: 0 additions & 58 deletions src/webfaf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@
from flask.json import JSONEncoder

from pyfaf.storage import GenericTable
from pyfaf.storage.problem import Problem
from pyfaf.storage.report import (Report,
ReportBtFrame,
ReportComment,
ReportHistoryDaily,
ReportHistoryWeekly,
ReportHistoryMonthly)
from pyfaf.storage.bugzilla import BzUser
from pyfaf import queries

Expand Down Expand Up @@ -227,57 +220,6 @@ def default(self, o): #pylint: disable=method-hidden
return o.isoformat()
if isinstance(o, datetime.date):
return o.isoformat()
if isinstance(o, Problem):
d = {"id": o.id,
"components": o.unique_component_names,
"crash_function": o.crash_function,
"bugs": [bug.url for bug in o.bugs],
"status": o.status,
"type": o.type,
"reports": o.reports,
}
if hasattr(o, "count"):
d["count"] = o.count
return d
if isinstance(o, Report):
d = {"id": o.id,
"bugs": [bug.url for bug in o.bugs],
"component": o.component,
"count": o.count,
"first_occurrence": o.first_occurrence,
"last_occurrence": o.last_occurrence,
"problem_id": o.problem_id,
"comments": o.comments,
}

return d
if isinstance(o, ReportBtFrame):
if o.symbolsource.symbol is None:
name = " "
else:
if o.symbolsource.symbol.nice_name:
name = o.symbolsource.symbol.nice_name
else:
name = o.symbolsource.symbol.name

d = {"frame": o.order,
"name": name,
"binary_path": o.symbolsource.path,
"source_path": o.symbolsource.source_path,
"line_numer": o.symbolsource.line_number,
}
return d
if isinstance(o, ReportComment):
d = {"saved": o.saved,
"text": o.text,
}
return d
if isinstance(o, ReportHistoryDaily):
return dict(date=o.day, count=o.count)
if isinstance(o, ReportHistoryWeekly):
return dict(date=o.week, count=o.count)
if isinstance(o, ReportHistoryMonthly):
return dict(date=o.month, count=o.count)
if isinstance(o, GenericTable):
return str(o)
if isinstance(o, set):
Expand Down

0 comments on commit 1b3490c

Please sign in to comment.