[KiRi] Moved project data to a file

- No more need to touch the index.html
This commit is contained in:
Salvador E. Tropea 2023-12-12 09:41:50 -03:00
parent ad3f8bb7d7
commit d073b155ef
6 changed files with 29 additions and 118 deletions

View File

@ -140,14 +140,6 @@ class KiRiOptions(VariantOptions):
else:
la.color = UNDEF_COLOR
# def create_layers(self, f):
# template = self.load_html_template('layers', 11)
# for i, la in enumerate(self._solved_layers):
# # TODO: Configure checked?
# checked = 'checked="checked"' if i == 0 else ''
# f.write(template.format(i=i+1, layer_id_padding='%02d' % (i+1), layer_name=la.suffix,
# layer_id=la.id, layer_color=la.color, checked=checked))
def save_sch_sheet(self, hash, name_sch):
# Load the schematic. Really worth?
sch = load_any_sch(name_sch, GS.sch_basename)
@ -165,76 +157,6 @@ class KiRiOptions(VariantOptions):
sheet_path = GS.sch_basename+'-'+sheet_path[1:]
f.write(f'{no_ext}|{rel_name}||{instance_name}|{sheet_path}\n')
# def create_pages(self, f):
# template = self.load_html_template('pages', 11)
# for i, s in enumerate(sorted(GS.sch.all_sheets, key=lambda s: s.sheet_path_h)):
# fname = s.fname
# checked = 'checked="checked"' if i == 0 else ''
# base_name = os.path.basename(fname)
# rel_name = os.path.relpath(fname, GS.sch_dir)
# if s.sheet_path_h == '/':
# instance_name = sheet_path = GS.sch_basename
# else:
# instance_name = os.path.basename(s.sheet_path_h)
# sheet_path = s.sheet_path_h.replace('/', '-')
# sheet_path = GS.sch_basename+'-'+sheet_path[1:]
# f.write(template.format(i=i+1, page_name=instance_name, page_filename_path=rel_name,
# page_filename=base_name, checked=checked))
def load_html_template(self, type, tabs):
""" Load a template used to generate an HTML section.
Outside of the code for easier modification/customization. """
with open(os.path.join(GS.get_resource_path('kiri'), f'{type}_template.html'), 'rt') as f:
template = f.read()
template = template.replace('${', '{')
template = template.replace('$(printf "%02d" {i})', '{i02}')
template = template.replace('{class}', '{cls}')
template = template.replace('\t\t', '\t'*tabs)
return template
def create_index(self, commits):
# Get the KiRi template
with open(os.path.join(GS.get_resource_path('kiri'), 'index.html'), 'rt') as f:
template = f.read()
today = datetime.datetime.today().strftime('%Y-%m-%d')
# Replacement keys
rep = {}
rep['PROJECT_TITLE'] = GS.pro_basename or GS.sch_basename or GS.pcb_basename or 'unknown'
rep['SCH_TITLE'] = GS.sch_title or 'No title'
rep['SCH_REVISION'] = GS.sch_rev or ''
rep['SCH_DATE'] = GS.sch_date or today
rep['PCB_TITLE'] = GS.pcb_title or 'No title'
rep['PCB_REVISION'] = GS.pcb_rev or ''
rep['PCB_DATE'] = GS.pcb_date or today
# Fill the template
with open(os.path.join(self.cache_dir, 'web', 'index.html'), 'wt') as f:
for ln in iter(template.splitlines()):
for k, v in rep.items():
ln = ln.replace(f'[{k}]', v)
f.write(ln+'\n')
# if ln.endswith('<!-- FILL_COMMITS_HERE -->'):
# self.create_commits(f, commits)
# elif ln.endswith('<!-- FILL_PAGES_HERE -->'):
# self.create_pages(f)
# elif ln.endswith('<!-- FILL_LAYERS_HERE -->'):
# self.create_layers(f)
# def create_commits(self, f, commits):
# template = self.load_html_template('commits', 8)
# for i, c in enumerate(commits):
# hash = c[0][:7]
# dt = c[1].split()[0]
# author = c[2]+' '
# desc = c[3]
# tooltip = TOOLTIP_HTML.format(hash=hash, dt=dt, author=author, desc=desc)
# cls = 'text-warning' if hash == HASH_LOCAL else 'text-info'
# icon_pcb = PCB_IMG if c[0] in self.commits_with_changed_pcb else EMPTY_IMG
# icon_sch = SCH_IMG if c[0] in self.commits_with_changed_sch else EMPTY_IMG
# # TODO What's this? if we only track changes in PCB/Sch this should be empty
# icon_txt = TXT_IMG
# f.write(template.format(i=i+1, hash=hash, tooltip=tooltip, text=c[3], cls=cls, i02='%02d' % (i+1),
# date=dt, user=author, pcb_icon=icon_pcb, sch_icon=icon_sch, txt_icon=icon_txt, hash_label=hash))
def save_commits(self, commits):
with open(os.path.join(self.cache_dir, 'commits'), 'wt') as f:
for c in commits:
@ -246,6 +168,13 @@ class KiRiOptions(VariantOptions):
pcb_changed = c[0] in self.commits_with_changed_pcb
f.write(f'{hash}|{dt}|{author}|{desc}|{sch_changed}|{pcb_changed}\n')
def save_project_data(self):
today = datetime.datetime.today().strftime('%Y-%m-%d')
with open(os.path.join(self.cache_dir, 'project'), 'wt') as f:
f.write((GS.pro_basename or GS.sch_basename or GS.pcb_basename or 'unknown')+'\n')
f.write((GS.sch_title or 'No title')+'|'+(GS.sch_rev or '')+'|'+(GS.sch_date or today)+'\n')
f.write((GS.pcb_title or 'No title')+'|'+(GS.pcb_rev or '')+'|'+(GS.pcb_date or today)+'\n')
def get_modified_status(self, pcb_file, sch_files):
res = self.run_git(['log', '--pretty=format:%H', '--', pcb_file])
self.commits_with_changed_pcb = set(res.split())
@ -265,6 +194,7 @@ class KiRiOptions(VariantOptions):
copy2(os.path.join(src_dir, 'favicon.ico'), os.path.join(web_dir, 'favicon.ico'))
copy2(os.path.join(src_dir, 'kiri.css'), os.path.join(web_dir, 'kiri.css'))
copy2(os.path.join(src_dir, 'kiri.js'), os.path.join(web_dir, 'kiri.js'))
copy2(os.path.join(src_dir, 'index.html'), os.path.join(web_dir, 'index.html'))
# Colors for the layers
with open(os.path.join(web_dir, 'layer_colors.css'), 'wt') as f:
f.write(LAYER_COLORS_HEAD)
@ -345,8 +275,8 @@ class KiRiOptions(VariantOptions):
if self.incl_file:
os.remove(self.incl_file)
self.create_kiri_files()
self.create_index(hashes)
self.save_commits(hashes)
self.save_project_data()
@output_class

View File

@ -1,21 +0,0 @@
<!-- Commit ${i} -->
<input class="chkGroup" type="checkbox" id="${hash}" name="commit" value="${hash}" onchange="update_commits()">
<label class="text-sm-left list-group-item" style="display: block; width: 445px; margin-left: 0px;" for="${hash}">
<table data-toggle="tooltip" title="${tooltip}">
<tr>
<td rowspan=2 style="vertical-align: top; width: 1.8em;">
<svg viewBox="0 0 15 15" fill="none" xmlns="http://www.w3.org/2000/svg" width="15" height="15">
<path d="M7.5 10.5a3 3 0 010-6m0 6a3 3 0 000-6m0 6V15m0-10.5V0" stroke="currentColor"></path>
</svg>
</td>
<td style="white-space:nowrap; overflow: hidden; text-overflow: ellipsis;">
<span class="text-muted"> $(printf "%02d" ${i}) | </span> <span class="text-success font-weight-normal">${hash_label}</span> <span class="text-muted"> | </span> ${sch_icon} ${pcb_icon} ${txt_icon} <span class="text-muted font-weight-normal"> | ${date} | ${user}</span>
</td>
</tr>
<tr>
<td>
<em class="${class}" style=" line-height: 0.7;">${text}</em>
</td>
</tr>
</table>
</label>

View File

@ -25,12 +25,12 @@
<span style="margin-top: 1em"></span>
<h3 class="text-light" style="margin-left: 5px;">Kicad Revision Inspector</h3>
<div id="sch_title" style="display: inline; margin-left: 5px;">
<h4 class="text-warning text-bold" style="margin-bottom: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">[SCH_TITLE]</h4>
<p class="text-light text-sm" >Rev. [SCH_REVISION] ([SCH_DATE])</p>
<h4 id="sch_title_text" class="text-warning text-bold" style="margin-bottom: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">[SCH_TITLE]</h4>
<p id="sch_rev" class="text-light text-sm" >Rev. [SCH_REVISION] ([SCH_DATE])</p>
</div>
<div id="pcb_title" style="display: none; margin-left: 5px;">
<h4 class="text-info text-bold" style="margin-bottom: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">[PCB_TITLE]</h4>
<p class="text-light text-sm">Rev. [PCB_REVISION] ([PCB_DATE])</p>
<h4 id="pcb_title_text" class="text-info text-bold" style="margin-bottom: 0px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">[PCB_TITLE]</h4>
<p id="pcb_rev" class="text-light text-sm">Rev. [PCB_REVISION] ([PCB_DATE])</p>
</div>
<p class="text-light" >
<span style="margin-left:5px; margin-right:0.5em" class="iconify" data-icon="fa-solid:code-branch" data-inline="false"></span>

View File

@ -877,7 +877,6 @@ function pad(num, size)
function load_commits()
{
commits = loadFile("../commits").split("\n").filter((a) => a);
console.log(commits);
var i = 1;
var all_commits_html = "";
for (const line of commits)
@ -919,7 +918,6 @@ function load_commits()
</table>
</label>
`;
console.log(commit_html);
all_commits_html = all_commits_html + commit_html;
i = i+1;
}
@ -927,6 +925,21 @@ function load_commits()
document.getElementById("commits_form").innerHTML = all_commits_html;
}
function load_project_data()
{
// Data format: TITLE
// SCH_TITLE|SCH_REVISION|SCH_DATE
// PCB_TITLE|PCB_REVISION|PCB_DATE
data = loadFile("../project").split("\n").filter((a) => a);
document.title = data[0];
splitted = data[1].split("|");
document.getElementById("sch_title_text").innerHTML = splitted[0];
document.getElementById("sch_rev").innerHTML = `Rev. ${splitted[1]} (${splitted[2]})`;
splitted = data[2].split("|");
document.getElementById("pcb_title_text").innerHTML = splitted[0];
document.getElementById("pcb_rev").innerHTML = `Rev. ${splitted[1]} (${splitted[2]})`;
}
function update_layers_list(commit1, commit2, selected_layer_idx, selected_layer_id)
{
var used_layers_1;
@ -1247,6 +1260,7 @@ $(document).ready(function()
function ready()
{
console.log('Starting JS');
load_project_data();
load_commits();
check_server_status();
select_initial_commits();

View File

@ -1,6 +0,0 @@
<!-- Layer ${i} -->
<input id="layer-${layer_id_padding}" value="layer-${layer_name}" type="radio" name="layers" onchange="change_layer()" ${checked}>
<label for="layer-${layer_id_padding}" id="label-layer-${layer_id_padding}" data-toggle="tooltip" title="${layer_id}, ${layer_name}" class="rounded text-sm-left list-group-item radio-box" onclick="change_layer_onclick()">
<span style="margin-left:0.5em; margin-right:0.1em; color: ${layer_color}" class="iconify" data-icon="teenyicons-square-solid" data-inline="false"></span>
${layer_name}
</label>

View File

@ -1,6 +0,0 @@
<!-- Page ${i} -->
<input id="${page_name}" data-toggle="tooltip" title="${page_filename_path}" type="radio" value="${page_filename}" name="pages" ${checked} onchange="change_page()">
<label for="${page_name}" data-toggle="tooltip" title="${page_filename_path}" id="label-${page_name}" class="rounded text-sm-left list-group-item radio-box" onclick="change_page_onclick()" style="white-space: nowrap; overflow: hidden; text-overflow: ellipsis;">
<span data-toggle="tooltip" title="${page_filename_path}" style="margin-left:0.5em; margin-right:0.1em;" class="iconify" data-icon="gridicons:pages" data-inline="false"></span>
${page_name}
</label>