Skip to content

Commit 2579007

Browse files
committed
Add version indicator in dialog and generated page
Code attempts to get 'git describe' output and falls back to hardcoded tag if that fails. Fixes #132
1 parent ce51782 commit 2579007

File tree

10 files changed

+40
-8
lines changed

10 files changed

+40
-8
lines changed

InteractiveHtmlBom/core/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ def _split(s):
8585
def _join(lst):
8686
return ','.join([s.replace(',', '\\,') for s in lst])
8787

88-
def __init__(self):
88+
def __init__(self, version):
8989
"""Init from config file if it exists."""
90+
self.version = version
9091
if not os.path.isfile(self.config_file):
9192
return
9293
f = FileConfig(localFilename=self.config_file)

InteractiveHtmlBom/core/ibom.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ def main(parser, config, logger):
296296
return
297297

298298
pcbdata["bom"] = generate_bom(components, config, extra_fields)
299+
pcbdata["ibom_version"] = config.version
299300

300301
# build BOM
301302
bom_file = generate_file(pcb_file_dir, pcb_file_name, pcbdata, config)
@@ -315,6 +316,7 @@ def save_config(dialog_panel):
315316
extra_data_func=parser.extra_data_func,
316317
config_save_func=save_config,
317318
file_name_format_hint=config.FILE_NAME_FORMAT_HINT,
319+
version=config.version
318320
)
319321
try:
320322
config.netlist_initial_directory = os.path.dirname(parser.file_name)

InteractiveHtmlBom/dialog/settings_dialog.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ def pop_error(msg):
1313

1414
class SettingsDialog(dialog_base.SettingsDialogBase):
1515
def __init__(self, extra_data_func, config_save_func,
16-
file_name_format_hint):
16+
file_name_format_hint, version):
1717
dialog_base.SettingsDialogBase.__init__(self, None)
1818
self.panel = SettingsDialogPanel(
1919
self, extra_data_func, config_save_func, file_name_format_hint)
2020
best_size = self.panel.BestSize
2121
# hack for some gtk themes that incorrectly calculate best size
2222
best_size.IncBy(dx=0, dy=30)
2323
self.SetClientSize(best_size)
24+
self.SetTitle('InteractiveHtmlBom %s' % version)
2425

2526
# hack for new wxFormBuilder generating code incompatible with old wxPython
2627
# noinspection PyMethodOverriding

InteractiveHtmlBom/dialog_test.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
from dialog.settings_dialog import *
22

3-
43
class MyApp(wx.App):
54
def OnInit(self):
6-
frame = SettingsDialog(lambda: None, lambda x: None, "Hi")
5+
frame = SettingsDialog(lambda: None, lambda x: None, "Hi", 'test')
76
if frame.ShowModal() == wx.ID_OK:
87
print("Should generate bom")
98
frame.Destroy()

InteractiveHtmlBom/ecad/kicad.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -510,7 +510,9 @@ def defaults(self):
510510
pass
511511

512512
def Run(self):
513-
config = Config()
513+
from ..version import version
514+
self.version = version
515+
config = Config(self.version)
514516
board = pcbnew.GetBoard()
515517
pcb_file_name = board.GetFileName()
516518

InteractiveHtmlBom/generate_interactive_bom.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def to_utf(s):
2727
from .core import ibom
2828
from .core.config import Config
2929
from .ecad import get_parser_by_extension
30+
from .version import version
3031

3132
app = wx.App()
3233

@@ -36,7 +37,7 @@ def to_utf(s):
3637
parser.add_argument('file',
3738
type=lambda s: to_utf(s),
3839
help="KiCad PCB file")
39-
config = Config()
40+
config = Config(version)
4041
config.add_options(parser, config.FILE_NAME_FORMAT_HINT)
4142
args = parser.parse_args()
4243
if not os.path.isfile(args.file):

InteractiveHtmlBom/version.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Update this when new version is tagged.
2+
LAST_TAG = 'v2.3'
3+
4+
import os
5+
plugin_path = os.path.realpath(os.path.dirname(__file__))
6+
plugin_path if not os.path.islink(plugin_path) else os.readlink(plugin_path)
7+
8+
def _get_git_version():
9+
import os, subprocess
10+
try:
11+
git_version = subprocess.check_output(
12+
['git', 'describe', '--tags', '--abbrev=4', '--dirty=-*'],
13+
cwd=plugin_path)
14+
return git_version.decode('utf-8') if isinstance(git_version, bytes) else git_version
15+
except subprocess.CalledProcessError as e:
16+
print('Git version check failed: ' + str(e))
17+
except Exception as e:
18+
print('Git process cannot be launched: ' + str(e))
19+
return None
20+
21+
22+
version = _get_git_version() or LAST_TAG

InteractiveHtmlBom/web/ibom.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@
110110
<label class="menu-label">
111111
<span class="shameless-plug">
112112
<span>Created using</span>
113-
<a target="blank" href="https://github.com/openscopeproject/InteractiveHtmlBom">InteractiveHtmlBom</a>
113+
<a id="github-link" target="blank" href="https://github.com/openscopeproject/InteractiveHtmlBom">InteractiveHtmlBom</a>
114114
</span>
115115
</label>
116116
</div>

InteractiveHtmlBom/web/ibom.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ function populateMetadata() {
626626
if (pcbdata.metadata.title != "") {
627627
document.title = pcbdata.metadata.title + " BOM";
628628
}
629+
// Calculate board stats
629630
var fp_f = 0, fp_b = 0, pads_f = 0, pads_b = 0, pads_th = 0;
630631
for (var i = 0; i < pcbdata.modules.length; i++) {
631632
if (pcbdata.bom.skipped.includes(i)) continue;
@@ -658,6 +659,9 @@ function populateMetadata() {
658659
document.getElementById("stats-smd-pads-back").innerHTML = pads_b;
659660
document.getElementById("stats-smd-pads-total").innerHTML = pads_f + pads_b;
660661
document.getElementById("stats-th-pads").innerHTML = pads_th;
662+
// Update version string
663+
document.getElementById("github-link").innerHTML = "InteractiveHtmlBom&nbsp;" +
664+
/^v\d+\.\d+/.exec(pcbdata.ibom_version)[0];
661665
}
662666

663667
function changeBomLayout(layout) {

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ Plugin code is licensed under MIT license, see `LICENSE` for more info.
3232

3333
Html page uses [Split.js](https://github.com/nathancahill/Split.js),
3434
[PEP.js](https://github.com/jquery/PEP) and (stripped down)
35-
[lz-strings.js](https://github.com/pieroxy/lz-string) libraries that get embedded into
35+
[lz-string.js](https://github.com/pieroxy/lz-string) libraries that get embedded into
3636
generated bom page.
3737

3838
`units.py` is borrowed from [KiBom](https://github.com/SchrodingersGat/KiBoM)

0 commit comments

Comments
 (0)