Skip to content
This repository has been archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Merge 8a42f43 into 30fc616
Browse files Browse the repository at this point in the history
  • Loading branch information
Hai Hoang Dang committed Jul 3, 2018
2 parents 30fc616 + 8a42f43 commit a2451c5
Show file tree
Hide file tree
Showing 4 changed files with 201 additions and 178 deletions.
85 changes: 43 additions & 42 deletions sktm/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
class SktDb(object):
def __init__(self, db):
if not os.path.isfile(db):
self.createdb(db)
self.__createdb(db)

self.conn = sqlite3.connect(db)
self.cur = self.conn.cursor()

def __del__(self):
self.conn.close()

def createdb(self, db):
def __createdb(self, db):
tc = sqlite3.connect(db)
c = tc.cursor()

Expand Down Expand Up @@ -89,7 +89,7 @@ def createdb(self, db):
c.close()
tc.close()

def create_repoid(self, baserepo):
def __create_repoid(self, baserepo):
"""Create a repoid for a git repo URL.
Args:
Expand All @@ -102,7 +102,7 @@ def create_repoid(self, baserepo):

return self.cur.lastrowid

def get_repoid(self, baserepo):
def __get_repoid(self, baserepo):
"""Fetch a repoid for a git repo URL.
Args:
Expand All @@ -116,11 +116,11 @@ def get_repoid(self, baserepo):
result = self.cur.fetchone()

if not result:
return self.create_repoid(baserepo)
return self.__create_repoid(baserepo)

return result[0]

def create_sourceid(self, baseurl, project_id):
def __create_sourceid(self, baseurl, project_id):
"""Create a patchsource record that links a baseurl and project_id.
Args:
Expand All @@ -135,7 +135,7 @@ def create_sourceid(self, baseurl, project_id):

return self.cur.lastrowid

def get_sourceid(self, baseurl, project_id):
def __get_sourceid(self, baseurl, project_id):
"""Fetch a patchsource id that links a baseurl and project_id.
Args:
Expand All @@ -151,7 +151,7 @@ def get_sourceid(self, baseurl, project_id):
result = self.cur.fetchone()

if not result:
return self.create_sourceid(baseurl, project_id)
return self.__create_sourceid(baseurl, project_id)

return result[0]

Expand All @@ -163,7 +163,7 @@ def get_last_checked_patch(self, baseurl, project_id):
project_id: Project ID in Patchwork.
"""
sourceid = self.get_sourceid(baseurl, project_id)
sourceid = self.__get_sourceid(baseurl, project_id)

self.cur.execute('SELECT patch.id FROM patch WHERE '
'patchsource_id = ? '
Expand All @@ -184,7 +184,7 @@ def get_last_pending_patch(self, baseurl, project_id):
project_id: Project ID in Patchwork.
"""
sourceid = self.get_sourceid(baseurl, project_id)
sourceid = self.__get_sourceid(baseurl, project_id)

self.cur.execute('SELECT id FROM pendingpatches WHERE '
'patchsource_id = ? '
Expand All @@ -205,7 +205,7 @@ def get_last_checked_patch_date(self, baseurl, project_id):
project_id: Project ID in Patchwork.
"""
sourceid = self.get_sourceid(baseurl, project_id)
sourceid = self.__get_sourceid(baseurl, project_id)

self.cur.execute('SELECT patch.date FROM patch WHERE '
'patchsource_id = ? '
Expand All @@ -226,7 +226,7 @@ def get_last_pending_patch_date(self, baseurl, project_id):
project_id: Project ID in Patchwork.
"""
sourceid = self.get_sourceid(baseurl, project_id)
sourceid = self.__get_sourceid(baseurl, project_id)

self.cur.execute('SELECT pdate FROM pendingpatches WHERE '
'patchsource_id = ? '
Expand Down Expand Up @@ -257,7 +257,7 @@ def get_expired_pending_patches(self, baseurl, project_id, exptime=86400):
List of patch IDs.
"""
patchlist = list()
sourceid = self.get_sourceid(baseurl, project_id)
sourceid = self.__get_sourceid(baseurl, project_id)
tstamp = int(time.time()) - exptime

self.cur.execute('SELECT id FROM pendingpatches WHERE '
Expand All @@ -273,7 +273,7 @@ def get_expired_pending_patches(self, baseurl, project_id, exptime=86400):

return patchlist

def get_baselineid(self, baserepo_id, commithash):
def __get_baselineid(self, baserepo_id, commithash):
"""Get the baseline_id for a particular baserepo_id and commithash.
Args:
Expand All @@ -291,7 +291,7 @@ def get_baselineid(self, baserepo_id, commithash):

return result[0]

def get_commitdate(self, baserepo, commithash):
def __get_commitdate(self, baserepo, commithash):
"""Get the date of a commit in a baseline.
Args:
Expand All @@ -302,7 +302,7 @@ def get_commitdate(self, baserepo, commithash):
Date string or None if the commithash is not found.
"""
baserepo_id = self.get_repoid(baserepo)
baserepo_id = self.__get_repoid(baserepo)

self.cur.execute('SELECT commitdate FROM baseline WHERE '
'commitid = ? AND '
Expand All @@ -315,7 +315,7 @@ def get_commitdate(self, baserepo, commithash):

return result[0]

def get_baselineresult(self, baserepo, commithash):
def __get_baselineresult(self, baserepo, commithash):
"""Get the result of a baseline testrun.
Args:
Expand All @@ -327,7 +327,7 @@ def get_baselineresult(self, baserepo, commithash):
exist.
"""
baserepo_id = self.get_repoid(baserepo)
baserepo_id = self.__get_repoid(baserepo)

self.cur.execute('SELECT testrun.result_id FROM baseline, testrun '
'WHERE baseline.commitid = ? AND '
Expand All @@ -352,7 +352,7 @@ def get_stable(self, baserepo):
Latest stable commit ID, or None, if there are no stable commits.
"""
baserepo_id = self.get_repoid(baserepo)
baserepo_id = self.__get_repoid(baserepo)

self.cur.execute('SELECT commitid FROM baseline, testrun WHERE '
'baseline.baserepo_id = ? AND '
Expand All @@ -368,7 +368,7 @@ def get_stable(self, baserepo):

return result[0]

def get_latest(self, baserepo):
def __get_latest(self, baserepo):
"""Get the commit hash of the latest baseline.
Args:
Expand All @@ -379,7 +379,7 @@ def get_latest(self, baserepo):
exist.
"""
baserepo_id = self.get_repoid(baserepo)
baserepo_id = self.__get_repoid(baserepo)

self.cur.execute('SELECT commitid FROM baseline WHERE '
'baserepo_id = ? '
Expand Down Expand Up @@ -410,7 +410,7 @@ def set_patchset_pending(self, baseurl, project_id, series_data):
patch date string.
"""
sourceid = self.get_sourceid(baseurl, project_id)
sourceid = self.__get_sourceid(baseurl, project_id)
tstamp = int(time.time())

logging.debug("setting patches as pending: %s", series_data)
Expand All @@ -422,7 +422,7 @@ def set_patchset_pending(self, baseurl, project_id, series_data):
(patch_id, patch_date) in series_data])
self.conn.commit()

def unset_patchset_pending(self, baseurl, patch_id_list):
def __unset_patchset_pending(self, baseurl, patch_id_list):
"""Remove a patch from the list of pending patches.
Remove each specified patch from the list of "pending" patches, for
Expand Down Expand Up @@ -457,11 +457,11 @@ def update_baseline(self, baserepo, commithash, commitdate,
build_id: The build ID of the test run.
"""
baserepo_id = self.get_repoid(baserepo)
baserepo_id = self.__get_repoid(baserepo)

testrun_id = self.commit_testrun(result, build_id)
testrun_id = self.__commit_testrun(result, build_id)

prev_res = self.get_baselineresult(baserepo, commithash)
prev_res = self.__get_baselineresult(baserepo, commithash)
logging.debug("previous result: %s", prev_res)

if prev_res is None:
Expand Down Expand Up @@ -490,31 +490,32 @@ def commit_tested(self, patches, series=None):
"""
logging.debug("commit_tested: patches=%d", len(patches))
self.commit_series(patches, series)
self.__commit_series(patches, series)

for (patch_id, patch_name, patch_url, baseurl, project_id,
patch_date) in patches:
# TODO: Can accumulate per-project list instead of doing it one by
# one
self.unset_patchset_pending(baseurl, [patch_id])
self.__unset_patchset_pending(baseurl, [patch_id])

def commit_testrun(self, result, buildid):
def __commit_testrun(self, result, buildid):
"""Add a test run to the database.
Args:
result: Result of the test run.
build_id: The build ID of the test run.
"""
logging.debug("commit_testrun: result=%s; buildid=%d", result, buildid)
logging.debug("__commit_testrun: result=%s; buildid=%d",
result, buildid)
self.cur.execute('INSERT INTO testrun(result_id, build_id) '
'VALUES(?,?)',
(result.value, buildid))
self.conn.commit()
return self.cur.lastrowid

def commit_patch(self, patch_id, patch_name, patch_url, series_id,
baseurl, project_id, patch_date):
def __commit_patch(self, patch_id, patch_name, patch_url, series_id,
baseurl, project_id, patch_date):
"""Create/update a patch record in the database.
Args:
Expand All @@ -528,24 +529,24 @@ def commit_patch(self, patch_id, patch_name, patch_url, series_id,
"""
# pylint: disable=too-many-arguments
logging.debug("commit_patch: pid=%s; sid=%s", patch_id, series_id)
source_id = self.get_sourceid(baseurl, project_id)
logging.debug("__commit_patch: pid=%s; sid=%s", patch_id, series_id)
source_id = self.__get_sourceid(baseurl, project_id)
self.cur.execute('INSERT OR REPLACE INTO patch(id, name, url, '
'patchsource_id, series_id, date) '
'VALUES(?,?,?,?,?,?)',
(patch_id, patch_name, patch_url, source_id,
series_id, patch_date))
self.conn.commit()

def commit_series(self, patches, series_id=None):
def __commit_series(self, patches, series_id=None):
"""Create patch records for a list of patches.
Args:
patches: List of patches to insert into the database.
series_id: Series ID from patchwork that contains the patches.
"""
logging.debug("commit_series: %s (%s)", patches, series_id)
logging.debug("__commit_series: %s (%s)", patches, series_id)

if series_id is None:

Expand All @@ -564,11 +565,11 @@ def commit_series(self, patches, series_id=None):
for (patch_id, patch_name, patch_url, baseurl, project_id,
patch_date) in patches:
# If the source_id doesn't exist, this method will create it.
self.get_sourceid(baseurl, project_id)
self.__get_sourceid(baseurl, project_id)

# Add the patches to the database
self.commit_patch(patch_id, patch_name, patch_url, series_id,
baseurl, project_id, patch_date)
self.__commit_patch(patch_id, patch_name, patch_url, series_id,
baseurl, project_id, patch_date)

self.conn.commit()

Expand Down Expand Up @@ -596,9 +597,9 @@ def dump_baserepo_info(self): # pragma: no cover
for (burl,) in self.cur.fetchall():
print("repo url:", burl)
stable = self.get_stable(burl)
latest = self.get_latest(burl)
latest = self.__get_latest(burl)
print("most recent stable commit: {} ({})".format(
stable, self.get_commitdate(burl, stable)))
stable, self.__get_commitdate(burl, stable)))
print("most recent stable commit: {} ({})".format(
latest, self.get_commitdate(burl, latest)))
latest, self.__get_commitdate(burl, latest)))
print("---")
Loading

0 comments on commit a2451c5

Please sign in to comment.