Skip to content

Commit c8aff40

Browse files
committed
Add -v (--version) to cammer.py
1 parent e07f1b4 commit c8aff40

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

SparkFunKiCadCAMmer/cammer/cammer.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,38 @@
88

99
from pcbnew import *
1010

11+
# sub folder for our resource files
12+
_RESOURCE_DIRECTORY = os.path.join("..", "resource")
13+
14+
#https://stackoverflow.com/a/50914550
15+
def resource_path(relative_path):
16+
""" Get absolute path to resource, works for dev and for PyInstaller """
17+
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
18+
return os.path.join(base_path, _RESOURCE_DIRECTORY, relative_path)
19+
20+
def get_version(rel_path: str) -> str:
21+
try:
22+
with open(resource_path(rel_path), encoding='utf-8') as fp:
23+
for line in fp.read().splitlines():
24+
if line.startswith("__version__"):
25+
delim = '"' if '"' in line else "'"
26+
return line.split(delim)[1]
27+
raise RuntimeError("Unable to find version string.")
28+
except:
29+
raise RuntimeError("Unable to find _version.py.")
30+
31+
_APP_VERSION = get_version("_version.py")
32+
1133
class CAMmer():
1234
def __init__(self):
1335
pass
1436

1537
def args_parse(self, args):
1638
# set up command-line arguments parser
1739
parser = ArgumentParser(description="A script to generate and zip PCB Gerber and drill files.")
40+
parser.add_argument(
41+
"-v", "--version", action="version", version="%(prog)s " + _APP_VERSION
42+
)
1843
parser.add_argument(
1944
"-p", "--path", help="Path to the *.kicad_pcb file"
2045
)

0 commit comments

Comments
 (0)