From d073b155ef5f4ce43fe21aa259d2c245d6cad409 Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Tue, 12 Dec 2023 09:41:50 -0300 Subject: [PATCH] [KiRi] Moved project data to a file - No more need to touch the index.html --- kibot/out_kiri.py | 88 +++------------------- kibot/resources/kiri/commits_template.html | 21 ------ kibot/resources/kiri/index.html | 8 +- kibot/resources/kiri/kiri.js | 18 ++++- kibot/resources/kiri/layers_template.html | 6 -- kibot/resources/kiri/pages_template.html | 6 -- 6 files changed, 29 insertions(+), 118 deletions(-) delete mode 100644 kibot/resources/kiri/commits_template.html delete mode 100644 kibot/resources/kiri/layers_template.html delete mode 100644 kibot/resources/kiri/pages_template.html diff --git a/kibot/out_kiri.py b/kibot/out_kiri.py index 3fcea66e..d74e8ede 100644 --- a/kibot/out_kiri.py +++ b/kibot/out_kiri.py @@ -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(''): -# self.create_commits(f, commits) -# elif ln.endswith(''): -# self.create_pages(f) -# elif ln.endswith(''): -# 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 diff --git a/kibot/resources/kiri/commits_template.html b/kibot/resources/kiri/commits_template.html deleted file mode 100644 index 6d347e3f..00000000 --- a/kibot/resources/kiri/commits_template.html +++ /dev/null @@ -1,21 +0,0 @@ - - - diff --git a/kibot/resources/kiri/index.html b/kibot/resources/kiri/index.html index a3099eb1..f54557f5 100644 --- a/kibot/resources/kiri/index.html +++ b/kibot/resources/kiri/index.html @@ -25,12 +25,12 @@

Kicad Revision Inspector

-

[SCH_TITLE]

-

Rev. [SCH_REVISION] ([SCH_DATE])

+

[SCH_TITLE]

+

Rev. [SCH_REVISION] ([SCH_DATE])

diff --git a/kibot/resources/kiri/kiri.js b/kibot/resources/kiri/kiri.js index 29c3f36d..4cd619fa 100644 --- a/kibot/resources/kiri/kiri.js +++ b/kibot/resources/kiri/kiri.js @@ -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() `; - 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(); diff --git a/kibot/resources/kiri/layers_template.html b/kibot/resources/kiri/layers_template.html deleted file mode 100644 index 7aab62c7..00000000 --- a/kibot/resources/kiri/layers_template.html +++ /dev/null @@ -1,6 +0,0 @@ - - - diff --git a/kibot/resources/kiri/pages_template.html b/kibot/resources/kiri/pages_template.html deleted file mode 100644 index 99056165..00000000 --- a/kibot/resources/kiri/pages_template.html +++ /dev/null @@ -1,6 +0,0 @@ - - -