Skip to content

Commit c7bbd30

Browse files
authored
Merge pull request #3 from s0hey1/main
Automating library inspections and extracting information from them
2 parents 331d28d + b3979b4 commit c7bbd30

File tree

8 files changed

+178464
-29
lines changed

8 files changed

+178464
-29
lines changed

.github/scripts/README.md.template

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Altium-library
2+
3+
| Statistics | Libraries | Components |
4+
|---|---|---|
5+
| Schematic | {{libraries['schlibs']|length}} | {{libraries['schlibs']|get_total_comp}} |
6+
| Pcb | {{libraries['pcblibs']|length}} | {{libraries['pcblibs']|get_total_comp}} |
7+
8+
## [Browse Libraries](https://{{get_webpage_subdomain()}}.github.io/{{get_webpage_path()}})
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
import os
2+
from pathlib import Path
3+
import json
4+
import glob
5+
import olefile
6+
from jinja2 import Environment, FileSystemLoader, select_autoescape
7+
8+
9+
def schlib_parse(input):
10+
fullPath = input
11+
ole = olefile.OleFileIO(fullPath)
12+
components = []
13+
for entry in ole.listdir(streams=True, storages=False):
14+
if "Data" in entry:
15+
stream = ole.openstream(entry)
16+
params = stream.read()[5:-1]
17+
pairs = params.split(b"|")
18+
component = {}
19+
model = {}
20+
for pair in pairs:
21+
data = pair.split(b"=")
22+
keyword = data[0].decode("utf-8", "ignore").upper()
23+
if keyword in [
24+
"LIBREFERENCE",
25+
"COMPONENTDESCRIPTION",
26+
"MODELNAME",
27+
"DESCRIPTION",
28+
]:
29+
if keyword in ["MODELNAME", "DESCRIPTION"]:
30+
if "Models" not in component:
31+
component["Models"] = []
32+
if data[0].decode() in model:
33+
component["Models"].append(dict(reversed(model.items())))
34+
model.clear()
35+
model[data[0].decode()] = data[1].decode("utf-8", "ignore")
36+
else:
37+
component[data[0].decode()] = data[1].decode("utf-8", "ignore")
38+
if bool(model):
39+
component["Models"].append(dict(reversed(model.items())))
40+
components.append(component)
41+
return components
42+
43+
44+
def pcblib_parse(input):
45+
fullPath = input
46+
ole = olefile.OleFileIO(fullPath)
47+
components = []
48+
for entry in ole.listdir(streams=True, storages=False):
49+
if "PARAMETERS" in [e.upper() for e in entry]:
50+
stream = ole.openstream(entry)
51+
params = stream.read()[5:-1]
52+
pairs = params.split(b"|")
53+
component = {}
54+
for pair in pairs:
55+
data = pair.split(b"=")
56+
component[data[0].decode()] = data[1].decode("utf-8", "ignore")
57+
components.append(component)
58+
return components
59+
60+
61+
def inspect_libraries():
62+
libraries = {}
63+
libraries["schlibs"] = {}
64+
libraries["pcblibs"] = {}
65+
schlib_path = "AltiumSCHLIB/"
66+
for filepath in glob.iglob(schlib_path + "**/*.??????", recursive=True):
67+
filename = Path(filepath).stem
68+
if Path(filepath).suffix.lower() == ".schlib":
69+
libraries["schlibs"][filename] = schlib_parse(filepath)
70+
pcblib_path = "AltiumPCBLIB/"
71+
for filepath in glob.iglob(pcblib_path + "**/*.??????", recursive=True):
72+
filename = Path(filepath).stem
73+
if Path(filepath).suffix.lower() == ".pcblib":
74+
libraries["pcblibs"][filename] = pcblib_parse(filepath)
75+
return libraries
76+
77+
78+
def generate_json(libraries):
79+
json_file = open("inspect_result.json", "w")
80+
json.dump(libraries, json_file, indent=4)
81+
82+
83+
def get_total_comp(libs):
84+
sum = 0
85+
for comps in libs.values():
86+
sum = sum + len(comps)
87+
return sum
88+
89+
90+
def get_webpage_subdomain():
91+
return os.environ["BROWSING_WEBPAGE_SUBDOMAIN"]
92+
93+
94+
def get_webpage_path():
95+
return os.environ["BROWSING_WEBPAGE_PATH"]
96+
97+
98+
def render_template(libraries, file_path):
99+
env = Environment(loader=FileSystemLoader("."), autoescape=select_autoescape())
100+
env.filters["get_total_comp"] = get_total_comp
101+
env.globals["get_webpage_subdomain"] = get_webpage_subdomain
102+
env.globals["get_webpage_path"] = get_webpage_path
103+
template_dir_path = (
104+
Path(__file__).resolve().parent.relative_to(Path.cwd().as_posix()).as_posix()
105+
+ "/"
106+
)
107+
template_file = env.get_template(template_dir_path + file_path)
108+
return template_file.render(libraries=libraries)
109+
110+
111+
def generate_readme(libraries):
112+
readme = render_template(libraries, "README.md.template")
113+
with open("README.md", "w") as readme_fhdl:
114+
readme_fhdl.write(readme)
115+
116+
117+
def generate_browsing_webpage(libraries):
118+
browsing_webpage = render_template(libraries, "index.html.template")
119+
with open("index.html", "w") as browsing_webpage_fhdl:
120+
browsing_webpage_fhdl.write(browsing_webpage)
121+
122+
123+
def main():
124+
libraries = inspect_libraries()
125+
generate_json(libraries)
126+
generate_readme(libraries)
127+
generate_browsing_webpage(libraries)
128+
129+
130+
if __name__ == "__main__":
131+
main()
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta name="viewport" content="width=device-width, initial-scale=1">
5+
<style>
6+
ul, #CustomUL {
7+
list-style-type: none;
8+
}
9+
10+
#CustomUL {
11+
margin: 0;
12+
padding: 0;
13+
}
14+
15+
.color_text{
16+
color:blue;
17+
}
18+
19+
.caret {
20+
cursor: pointer;
21+
-webkit-user-select: none; /* Safari 3.1+ */
22+
-moz-user-select: none; /* Firefox 2+ */
23+
-ms-user-select: none; /* IE 10+ */
24+
user-select: none;
25+
}
26+
27+
.caret::before {
28+
content: "\25B6";
29+
color: black;
30+
display: inline-block;
31+
margin-right: 6px;
32+
}
33+
34+
.caret-down::before {
35+
-ms-transform: rotate(90deg); /* IE 9 */
36+
-webkit-transform: rotate(90deg); /* Safari */'
37+
transform: rotate(90deg);
38+
}
39+
40+
.nested {
41+
display: none;
42+
}
43+
44+
.active {
45+
display: block;
46+
}
47+
</style>
48+
</head>
49+
<body>
50+
51+
<h2>Altium Libraries</h2>
52+
53+
{%for libType, libs in libraries.items() %}
54+
{%if libType == 'schlibs' -%}
55+
<ul id="CustomUL">
56+
<li><span class="caret">Schematic libraries [ <code class="color_text">#libraries: {{libs|length}}</code> , <code class="color_text">#components : {{libs|get_total_comp}}</code> ]</span>
57+
{% else -%}
58+
<ul id="CustomUL">
59+
<li><span class="caret">Pcb libraries [ <code class="color_text">#libraries: {{libs|length}}</code> , <code class="color_text">#components : {{libs|get_total_comp}}</code> ]</span>
60+
{% endif -%}
61+
<ul class="nested">
62+
{%for libname, comps in libs.items() -%}
63+
<li><span class="caret">{{libname}} [ <code class="color_text">#components : {{comps|length}}</code> ]</span>
64+
<ul class="nested">
65+
{%for comp in comps -%}
66+
<li><span class="caret">{{ comp.values()|first }}</span>
67+
<ul class="nested">
68+
{%for comp_lbl, comp_val in comp.items() -%}
69+
{%if loop.index > 1 -%}
70+
{%if comp_lbl == 'Models' and comp_val.__class__.__name__ == 'list' -%}
71+
<li><span class="caret">Models [ <code class="color_text">#models : {{comp_val|length}}</code> ]</span>
72+
<ul class="nested">
73+
{%for model in comp_val -%}
74+
{%for model_lbl, model_val in model.items() -%}
75+
<li>{{model_lbl}} : <code>{{model_val}}</code></li>
76+
{% endfor -%}
77+
{% endfor -%}
78+
</ul>
79+
</li>
80+
{% else -%}
81+
<li>{{comp_lbl}} : <code>{{comp_val}}</code></li>
82+
{% endif -%}
83+
{% endif -%}
84+
{% endfor -%}
85+
</ul>
86+
</li>
87+
{% endfor -%}
88+
</ul>
89+
</li>
90+
{% endfor -%}
91+
</ul>
92+
</li>
93+
{% endfor -%}
94+
95+
<script>
96+
var toggler = document.getElementsByClassName("caret");
97+
var i;
98+
99+
for (i = 0; i < toggler.length; i++) {
100+
toggler[i].addEventListener("click", function() {
101+
this.parentElement.querySelector(".nested").classList.toggle("active");
102+
this.classList.toggle("caret-down");
103+
});
104+
}
105+
</script>
106+
107+
</body>
108+
</html>

.github/scripts/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
olefile==0.46
2+
Jinja2==3.1.4
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Altium Library Inspector
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
pull_request:
7+
branches: ["main"]
8+
9+
permissions:
10+
contents: write
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
env:
16+
BROWSING_WEBPAGE_SUBDOMAIN: ${{ github.repository_owner }}
17+
BROWSING_WEBPAGE_REPO: ${{ github.repository }}
18+
ACTIONS_ALLOW_UNSECURE_COMMANDS: "true"
19+
steps:
20+
- run: echo ::set-env name=BROWSING_WEBPAGE_PATH::$(echo $BROWSING_WEBPAGE_REPO | awk -F / '{print $2}')
21+
shell: bash
22+
- uses: actions/checkout@v4
23+
- name: Set up Python 3.10
24+
uses: actions/setup-python@v3
25+
with:
26+
python-version: "3.10"
27+
- name: Install dependencies
28+
run: |
29+
python -m pip install --upgrade pip
30+
pip install -r .github/scripts/requirements.txt
31+
- name: Run Altium Library Inspector
32+
run: |
33+
python .github/scripts/altium_lib_inspector.py
34+
- name: Update README.md
35+
run: |
36+
if [[ "$(git status --porcelain)" != "" ]]; then
37+
git config user.name "GitHub Action"
38+
git config user.email "[email protected]"
39+
git add .
40+
git commit -m "Auto-update README.md"
41+
git push
42+
fi

README.md

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,8 @@
1-
# Altium-Library
2-
| Part name | Descrpition | Manufacturer | Part number | Parameters |
3-
|-----------|-------------|--------------|-------------|------------|
4-
|7SEG_1DIGIT_CA_GRN_7MM |7SEGMENT, 1DIGIT, common ANODE |Kingbright | ACSA02-41SGWA-F01 |20mA, 2.2v, -40~85oC
5-
|7SEG_1DIGIT_CA_RED_5INCH |7SEGMENT, 1DIGIT, common ANODE |Kingbright | SA50-31SRWA, SA50-21EWA, SNS-50101BSR |20mA, -40~85oC 18.5~25VF
6-
|7SEG_1DIGIT_CA_RED_7MM |7SEGMENT, 1DIGIT, common ANODE |Kingbright | ACSC02-41SURKWA-F01, ACSA02-41SURKWA-F01, ACSA02-41EWA-F01|30mA, 2v, -40~85oC
7-
|7SEG_1DIGIT_CA_YLW_7MM |7SEGMENT, 1DIGIT, common ANODE |Kingbright | ACSA02-41YWA-F01 |20mA, 2.2v, -40~85oC
8-
|7SEG_1DIGIT_CC_0.4INCH |7SEGMENT, 1DIGIT, common cathode |manf | manf_p# |
9-
|7SEG_1DIGIT_CC_5611 |7SEGMENT, 1DIGIT, common cathode |manf | manf_p# |
10-
|7SEG_1DIGIT_CC_GRN_7MM |7SEGMENT, 1DIGIT, common cathode |Kingbright | ACSC02-41SGWA-F01, ACSC02-41CGKWA-F01 |20mA, 2.2v, -40~85oC
11-
|7SEG_2DIGIT_CA_BLU_0.2INCH |7SEGMENT, 2DIGIT, common Anode |Kingbright | ACDA02-41PBWA/A-F01 |20mA, 3.2V, -40~85oC
12-
|7SEG_2DIGIT_CA_BLU_0.3INCH |7SEGMENT, 2DIGIT, common Anode |Kingbright | ACDA03-41PBWA/A-F01 |10~20mA, 2~2.2V, -40~85oC
13-
|7SEG_2DIGIT_CA_GRN_0.2INCH |7SEGMENT, 2DIGIT, common Anode |Kingbright | ACDA02-41SGWA-F01 |10~20mA, 2~2.2V, -40~85oC
14-
|7SEG_2DIGIT_CA_GRN_0.3INCH |7SEGMENT, 2DIGIT, common Anode |Kingbright | ACDA03-41SGWA-F01 |10~20mA, 2~2.2V, -40~85oC
15-
|7SEG_2DIGIT_CA_GRN_0.3INCH_10 |7SEGMENT, 2DIGIT, common cathode |Kingbright | DA03-11GWA |10~20mA, 2~2.2V, -40~85oC
16-
|7SEG_2DIGIT_CA_GRN_0.56inch |7SEGMENT, 2DIGIT, common Anode |Broadcom, Avago, Lite-On, Kingbright | HDSP-521G, LTD-6410G, DA56-11GWA |10~20mA, 2~2.2V, -35~85oC
17-
|7SEG_2DIGIT_CA_RED_0.2INCH |7SEGMENT, 2DIGIT, common cathode |Kingbright | ACDA02-41EWA-F01, ACDA02-41SURKWA-F01 |10~20mA, 2~2.2V, -40~85oC
18-
|7SEG_2DIGIT_CA_RED_0.3INCH |7SEGMENT, 2DIGIT, common Anode |Kingbright | ACDA03-41EWA-F01 |10~20mA, 2~2.2V, -40~85oC
19-
|7SEG_2DIGIT_CA_RED_0.56inch |7SEGMENT, 2DIGIT, common Anode |Broadcom, Avago, Lite-On | HDSP-521E, LTD-6910HR, LTD-6710P |10~20mA, 2~2.2V, -35~85oC
20-
|7SEG_2DIGIT_CA_YLW_0.3INCH |7SEGMENT, 2DIGIT, common Anode |Kingbright | ACDA03-41YWA-F01 |10~20mA, 2~2.2V, -40~85oC
21-
|7SEG_2DIGIT_CC |7SEGMENT, 2DIGIT, common cathode |manf | manf_p# |
22-
|7SEG_2DIGIT_CC_GRN_0.2INCH |7SEGMENT, 2DIGIT, common cathode |Kingbright | ACDC02-41SGWA-F01 |10~20mA, 2~2.2V, -40~85oC
23-
|7SEG_2DIGIT_CC_GRN_0.56inch |7SEGMENT, 2DIGIT, common cathode |Broadcom, Avago | HDSP-523G |10~20mA, 2~2.2V, -35~85oC
24-
|7SEG_2DIGIT_CC_RED_0.2INCH |7SEGMENT, 2DIGIT, common cathode |Kingbright | ACDC02-41SURKWA-F01 |10~20mA, 2~2.2V, -40~85oC
25-
|7SEG_2DIGIT_CC_RED_0.3INCH_10 |7SEGMENT, 2DIGIT, common cathode |Kingbright | DC03-11EWA |10~20mA, 2~2.2V, -40~85oC
26-
|7SEG_2DIGIT_CC_RED_0.56inch |7SEGMENT, 2DIGIT, common cathode |Broadcom, Avago | HDSP-523E |10~20mA, 2~2.2V, -35~85oC
27-
|7SEG_3DIGIT_CC |7SEGMENT, 3DIGIT, common cathode |manf | manf_p# |
28-
|7SEG_4DIGIT_CC |7SEGMENT, 4DIGIT, common cathode 5641 |manf | DPY-4CK |
29-
|LED_MATRIX8X8 | |manf | manf_p# |
1+
# Altium-library
2+
3+
| Statistics | Libraries | Components |
4+
|---|---|---|
5+
| Schematic | 205 | 5709 |
6+
| Pcb | 96 | 3504 |
7+
8+
## [Browse Libraries](https://s0hey1.github.io/Altium-Library)

0 commit comments

Comments
 (0)