Skip to content

Commit

Permalink
Add version indicator in dialog and generated page
Browse files Browse the repository at this point in the history
Code attempts to get 'git describe' output and falls back
to hardcoded tag if that fails.

Fixes #132
  • Loading branch information
qu1ck committed Feb 5, 2020
1 parent ce51782 commit 2579007
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 8 deletions.
3 changes: 2 additions & 1 deletion InteractiveHtmlBom/core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,9 @@ def _split(s):
def _join(lst):
return ','.join([s.replace(',', '\\,') for s in lst])

def __init__(self):
def __init__(self, version):
"""Init from config file if it exists."""
self.version = version
if not os.path.isfile(self.config_file):
return
f = FileConfig(localFilename=self.config_file)
Expand Down
2 changes: 2 additions & 0 deletions InteractiveHtmlBom/core/ibom.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ def main(parser, config, logger):
return

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

# build BOM
bom_file = generate_file(pcb_file_dir, pcb_file_name, pcbdata, config)
Expand All @@ -315,6 +316,7 @@ def save_config(dialog_panel):
extra_data_func=parser.extra_data_func,
config_save_func=save_config,
file_name_format_hint=config.FILE_NAME_FORMAT_HINT,
version=config.version
)
try:
config.netlist_initial_directory = os.path.dirname(parser.file_name)
Expand Down
3 changes: 2 additions & 1 deletion InteractiveHtmlBom/dialog/settings_dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ def pop_error(msg):

class SettingsDialog(dialog_base.SettingsDialogBase):
def __init__(self, extra_data_func, config_save_func,
file_name_format_hint):
file_name_format_hint, version):
dialog_base.SettingsDialogBase.__init__(self, None)
self.panel = SettingsDialogPanel(
self, extra_data_func, config_save_func, file_name_format_hint)
best_size = self.panel.BestSize
# hack for some gtk themes that incorrectly calculate best size
best_size.IncBy(dx=0, dy=30)
self.SetClientSize(best_size)
self.SetTitle('InteractiveHtmlBom %s' % version)

# hack for new wxFormBuilder generating code incompatible with old wxPython
# noinspection PyMethodOverriding
Expand Down
3 changes: 1 addition & 2 deletions InteractiveHtmlBom/dialog_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from dialog.settings_dialog import *


class MyApp(wx.App):
def OnInit(self):
frame = SettingsDialog(lambda: None, lambda x: None, "Hi")
frame = SettingsDialog(lambda: None, lambda x: None, "Hi", 'test')
if frame.ShowModal() == wx.ID_OK:
print("Should generate bom")
frame.Destroy()
Expand Down
4 changes: 3 additions & 1 deletion InteractiveHtmlBom/ecad/kicad.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ def defaults(self):
pass

def Run(self):
config = Config()
from ..version import version
self.version = version
config = Config(self.version)
board = pcbnew.GetBoard()
pcb_file_name = board.GetFileName()

Expand Down
3 changes: 2 additions & 1 deletion InteractiveHtmlBom/generate_interactive_bom.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def to_utf(s):
from .core import ibom
from .core.config import Config
from .ecad import get_parser_by_extension
from .version import version

app = wx.App()

Expand All @@ -36,7 +37,7 @@ def to_utf(s):
parser.add_argument('file',
type=lambda s: to_utf(s),
help="KiCad PCB file")
config = Config()
config = Config(version)
config.add_options(parser, config.FILE_NAME_FORMAT_HINT)
args = parser.parse_args()
if not os.path.isfile(args.file):
Expand Down
22 changes: 22 additions & 0 deletions InteractiveHtmlBom/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Update this when new version is tagged.
LAST_TAG = 'v2.3'

import os
plugin_path = os.path.realpath(os.path.dirname(__file__))
plugin_path if not os.path.islink(plugin_path) else os.readlink(plugin_path)

def _get_git_version():
import os, subprocess
try:
git_version = subprocess.check_output(
['git', 'describe', '--tags', '--abbrev=4', '--dirty=-*'],
cwd=plugin_path)
return git_version.decode('utf-8') if isinstance(git_version, bytes) else git_version
except subprocess.CalledProcessError as e:
print('Git version check failed: ' + str(e))
except Exception as e:
print('Git process cannot be launched: ' + str(e))
return None


version = _get_git_version() or LAST_TAG
2 changes: 1 addition & 1 deletion InteractiveHtmlBom/web/ibom.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
<label class="menu-label">
<span class="shameless-plug">
<span>Created using</span>
<a target="blank" href="https://github.com/openscopeproject/InteractiveHtmlBom">InteractiveHtmlBom</a>
<a id="github-link" target="blank" href="https://github.com/openscopeproject/InteractiveHtmlBom">InteractiveHtmlBom</a>
</span>
</label>
</div>
Expand Down
4 changes: 4 additions & 0 deletions InteractiveHtmlBom/web/ibom.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ function populateMetadata() {
if (pcbdata.metadata.title != "") {
document.title = pcbdata.metadata.title + " BOM";
}
// Calculate board stats
var fp_f = 0, fp_b = 0, pads_f = 0, pads_b = 0, pads_th = 0;
for (var i = 0; i < pcbdata.modules.length; i++) {
if (pcbdata.bom.skipped.includes(i)) continue;
Expand Down Expand Up @@ -658,6 +659,9 @@ function populateMetadata() {
document.getElementById("stats-smd-pads-back").innerHTML = pads_b;
document.getElementById("stats-smd-pads-total").innerHTML = pads_f + pads_b;
document.getElementById("stats-th-pads").innerHTML = pads_th;
// Update version string
document.getElementById("github-link").innerHTML = "InteractiveHtmlBom&nbsp;" +
/^v\d+\.\d+/.exec(pcbdata.ibom_version)[0];
}

function changeBomLayout(layout) {
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Plugin code is licensed under MIT license, see `LICENSE` for more info.

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

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

0 comments on commit 2579007

Please sign in to comment.