Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Ardupilot
GitHub Repository: Ardupilot/ardupilot
Path: blob/master/Tools/scripts/build_binaries_history.py
9688 views
1
import os
2
import sqlite3
3
4
5
class BuildBinariesHistory():
6
def __init__(self, db_filepath):
7
self.db_filepath = db_filepath
8
self.assure_db_present()
9
10
def progress(self, msg):
11
print("BBHIST: %s" % msg)
12
13
def conn(self):
14
return sqlite3.connect(self.db_filepath)
15
16
def create_schema(self, c):
17
'''create our tables and whatnot'''
18
schema_version = 1
19
c.execute("create table version (version integer)")
20
c.execute("insert into version (version) values (?)", (schema_version,))
21
# at some stage we should probably directly associate build with runs....
22
c.execute("create table build (hash text, tag text, vehicle text, board text, "
23
"frame text, text integer, data integer, bss integer, start_time real, duration real)")
24
c.execute("create table run (hash text, tag text, start_time real, duration real)")
25
c.commit()
26
27
def sizes_for_file(self, filepath):
28
cmd = "size %s" % (filepath,)
29
stuff = os.popen(cmd).read()
30
lines = stuff.split("\n")
31
sizes = lines[1].split("\t")
32
text = int(sizes[0])
33
data = int(sizes[1])
34
bss = int(sizes[2])
35
self.progress("Binary size of %s:" % filepath)
36
self.progress("text=%u" % text)
37
self.progress("data=%u" % data)
38
self.progress("bss=%u" % bss)
39
return (text, data, bss)
40
41
def assure_db_present(self):
42
c = self.conn()
43
need_schema_create = False
44
try:
45
version_cursor = c.execute("select version from version")
46
except sqlite3.OperationalError as e:
47
if "no such table" in str(e): # FIXME: do better here? what's in "e"?
48
print("need schema create")
49
need_schema_create = True
50
51
if need_schema_create:
52
self.create_schema(c)
53
version_cursor = c.execute("select version from version")
54
55
version_results = version_cursor.fetchall()
56
57
if len(version_results) == 0:
58
raise IOError("No version number?")
59
if len(version_results) > 1:
60
raise IOError("More than one version result?")
61
first = version_results[0]
62
want_version = 1
63
got_version = first[0]
64
if got_version != want_version:
65
raise IOError("Bad version number (want=%u got=%u" %
66
(want_version, got_version))
67
self.progress("Got history version %u" % got_version)
68
69
def record_build(self, hash, tag, vehicle, board, frame, bare_path, start_time, duration):
70
if bare_path is None:
71
(text, data, bss) = (None, None, None)
72
else:
73
(text, data, bss) = self.sizes_for_file(bare_path)
74
c = self.conn()
75
c.execute("replace into build (hash, tag, vehicle, board, frame, text, data, bss, start_time, duration) "
76
"values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
77
(hash, tag, vehicle, board, frame, text, data, bss, start_time, duration))
78
c.commit()
79
80
def record_run(self, hash, tag, start_time, duration):
81
c = self.conn()
82
c.execute("replace into run (hash, tag, start_time, duration) "
83
"values (?, ?, ?, ?)",
84
(hash, tag, start_time, duration))
85
c.commit()
86
87