-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
424 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,12 @@ | ||
__version__ = '0.7.4' | ||
#!/usr/bin/python | ||
# -*- coding: ascii -*- | ||
""" | ||
Embutils module. | ||
:date: 2021 | ||
:author: Christian Wiche | ||
:contact: [email protected] | ||
:license: The MIT License (MIT) | ||
""" | ||
# ------------------------------------- | ||
__version__ = '0.7.5' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,13 @@ | ||
from .build import build_cubeide, build_iar | ||
from .version import ( | ||
VersionHandler, | ||
AbstractVersionUpdater, AbstractVersionExporter, AbstractVersionStorage, | ||
GitBuildVersionUpdater, CCppVersionExporter, SimpleVersionStorage, | ||
) | ||
#!/usr/bin/python | ||
# -*- coding: ascii -*- | ||
""" | ||
Embutils repository utilities. | ||
:date: 2021 | ||
:author: Christian Wiche | ||
:contact: [email protected] | ||
:license: The MIT License (MIT) | ||
""" | ||
# ------------------------------------- | ||
from .build import * | ||
from .version import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,11 +8,14 @@ | |
:contact: [email protected] | ||
:license: The MIT License (MIT) | ||
""" | ||
|
||
# ------------------------------------- | ||
from ..utils.path import TPPath, Path | ||
from ..utils.subprocess import execute | ||
|
||
|
||
# -->> Tunables <<--------------------- | ||
|
||
|
||
# -->> Definitions <<------------------ | ||
|
||
|
||
|
@@ -76,3 +79,10 @@ def build_iar(config: str, project: TPPath, | |
res = execute(cmd=cmd, pipe=pipe, log=log) | ||
if not pipe and res.returncode: | ||
print(f"Command:\n{cmd}\nFailed with error:\n{res.stderr}") | ||
|
||
|
||
# -->> Export <<----------------------- | ||
__all__ = [ | ||
"build_cubeide", | ||
"build_iar", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
:contact: [email protected] | ||
:license: The MIT License (MIT) | ||
""" | ||
# ------------------------------------- | ||
|
||
import abc | ||
import datetime as dt | ||
|
@@ -22,6 +23,9 @@ | |
from ..utils.version import Version | ||
|
||
|
||
# -->> Tunables <<--------------------- | ||
|
||
|
||
# -->> Definitions <<------------------ | ||
#: Source path | ||
PATH_THIS = Path(os.path.abspath(os.path.dirname(__file__))) | ||
|
@@ -149,6 +153,59 @@ def export(self, path: TPPath = os.getcwd(), author: str = "Unknown") -> None: | |
self.exporter.export(version=self, path=path, author=author) | ||
|
||
|
||
class CCppVersionExporter(AbstractVersionExporter): | ||
""" | ||
C/C++ Version Exporter. | ||
Implements the logic to export the version number to a C/C++ header file | ||
""" | ||
#: Item print size. | ||
ITEMSIZE = 20 | ||
#: Default exported version filename. | ||
FILENAME = "version.h" | ||
#: Supported header file extensions. | ||
SUFFIXES = [".h", ".hpp"] | ||
#: C/C++ header template. | ||
TEMPLATE = PATH_TMPL / "template_version_c.h" | ||
|
||
def export(self, version: Version, path: TPPath, author: str = "Unknown") -> None: | ||
""" | ||
Exports the version number to a C/C++ header using a header template. | ||
:param Version version: Version to be exported. | ||
:param TPPath path: Target file path. | ||
:param str author: Exported file owner. | ||
""" | ||
# Check file | ||
path = Path.validate_file(path=path, none_ok=False, default=self.FILENAME) | ||
if path.suffix.lower() not in self.SUFFIXES: | ||
raise FileTypeError(f"Header path doesnt have the right suffix ({self.SUFFIXES}): {path}.") | ||
|
||
# Generate header | ||
with path.open(mode="w", encoding="utf-8") as file: | ||
tmpl = self.TEMPLATE.open(mode="r", encoding="utf-8").read() | ||
file.write(tmpl.format( | ||
file=path.name, author=author, | ||
guard=f"_{path.stem}_H_".upper(), | ||
date=f"{dt.datetime.now().strftime('%m/%d/%Y %H:%M:%S')}", | ||
major=self._format(item=version.major), | ||
minor=self._format(item=version.minor), | ||
build=self._format(item=version.build), | ||
version=f"{version}" | ||
)) | ||
|
||
def _format(self, item: int) -> str: | ||
""" | ||
Formats the version number item. | ||
:param int item: Version item value. | ||
:return: Item entry. | ||
:rtype: str | ||
""" | ||
hexval = f"0x{item:0{closest_multi(ref=len(hex(item)[2:]), base=2)}X}U" | ||
return f"{hexval:{self.ITEMSIZE}s} /* DEC: {str(item):<{self.ITEMSIZE}s} */" | ||
|
||
|
||
class SimpleVersionStorage(AbstractVersionStorage): | ||
""" | ||
Simple Version Storage. | ||
|
@@ -205,59 +262,18 @@ def update(self, version: Version, path: TPPath) -> None: | |
:param TPPath path: Path in which the repository is initialized. | ||
""" | ||
# Update the build number with the commit number | ||
ret = execute(cmd="git rev-parse --short HEAD", cwd=f"{path}", pipe=False) | ||
ret = execute(cmd="git rev-parse --short HEAD", cwd=path, pipe=False) | ||
ret = (ret.stderr + ret.stdout).lower().strip() | ||
version.build = self.NO_BUILD if ("not a git" in ret) else int(ret, 16) | ||
|
||
|
||
class CCppVersionExporter(AbstractVersionExporter): | ||
""" | ||
C/C++ Version Exporter. | ||
Implements the logic to export the version number to a C/C++ header file | ||
""" | ||
#: Item print size. | ||
ITEMSIZE = 20 | ||
#: Default exported version filename. | ||
FILENAME = "version.h" | ||
#: Supported header file extensions. | ||
SUFFIXES = [".h", ".hpp"] | ||
#: C/C++ header template. | ||
TEMPLATE = PATH_TMPL / "template_version_c.h" | ||
|
||
def export(self, version: Version, path: TPPath, author: str = "Unknown") -> None: | ||
""" | ||
Exports the version number to a C/C++ header using a header template. | ||
:param Version version: Version to be exported. | ||
:param TPPath path: Target file path. | ||
:param str author: Exported file owner. | ||
""" | ||
# Check file | ||
path = Path.validate_file(path=path, none_ok=False, default=self.FILENAME) | ||
if path.suffix.lower() not in self.SUFFIXES: | ||
raise FileTypeError(f"Header path doesnt have the right suffix ({self.SUFFIXES}): {path}.") | ||
|
||
# Generate header | ||
with path.open(mode="w", encoding="utf-8") as file: | ||
tmpl = self.TEMPLATE.open(mode="r", encoding="utf-8").read() | ||
file.write(tmpl.format( | ||
file=path.name, author=author, | ||
guard=f"_{path.stem}_H_".upper(), | ||
date=f"{dt.datetime.now().strftime('%m/%d/%Y %H:%M:%S')}", | ||
major=self._format(item=version.major), | ||
minor=self._format(item=version.minor), | ||
build=self._format(item=version.build), | ||
version=f"{version}" | ||
)) | ||
|
||
def _format(self, item: int) -> str: | ||
""" | ||
Formats the version number item. | ||
:param int item: Version item value. | ||
:return: Item entry. | ||
:rtype: str | ||
""" | ||
hexval = f"0x{item:0{closest_multi(ref=len(hex(item)[2:]), base=2)}X}U" | ||
return f"{hexval:{self.ITEMSIZE}s} /* DEC: {str(item):<{self.ITEMSIZE}s} */" | ||
# -->> Export <<----------------------- | ||
__all__ = [ | ||
"AbstractVersionExporter", | ||
"AbstractVersionStorage", | ||
"AbstractVersionUpdater", | ||
"VersionHandler", | ||
"CCppVersionExporter", | ||
"SimpleVersionStorage", | ||
"GitBuildVersionUpdater", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,14 @@ | ||
from .device import Device, DeviceList, DeviceScanner | ||
from .stream import Stream, AbstractSerializedStreamCodec | ||
from .interface import Interface | ||
#!/usr/bin/python | ||
# -*- coding: ascii -*- | ||
""" | ||
Embutils serial utilities. | ||
:date: 2021 | ||
:author: Christian Wiche | ||
:contact: [email protected] | ||
:license: The MIT License (MIT) | ||
""" | ||
# ------------------------------------- | ||
from .device import * | ||
from .stream import * | ||
from .interface import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
:contact: [email protected] | ||
:license: The MIT License (MIT) | ||
""" | ||
# ------------------------------------- | ||
|
||
import threading as th | ||
import typing as tp | ||
|
@@ -22,6 +23,9 @@ | |
from ..utils.time import Timer | ||
|
||
|
||
# -->> Tunables <<--------------------- | ||
|
||
|
||
# -->> Definitions <<------------------ | ||
|
||
|
||
|
@@ -267,10 +271,10 @@ def filter(self, port: str = None, dev_id: int = None) -> "DeviceList": | |
""" | ||
dev_list = self | ||
# Filter by port | ||
if isinstance(port, str): | ||
if port is not None: | ||
dev_list = DeviceList([dev for dev in dev_list if dev.port == port]) | ||
# Filter by ID | ||
if isinstance(dev_id, int): | ||
if dev_id is not None: | ||
dev_list = DeviceList([dev for dev in dev_list if dev.id == dev_id]) | ||
return dev_list | ||
|
||
|
@@ -444,3 +448,11 @@ def _scan(self) -> None: | |
name=f"{self.__class__.__name__}.on_scan_period", | ||
task=self.on_scan_period.emit | ||
)) | ||
|
||
|
||
# -->> Export <<----------------------- | ||
__all__ = [ | ||
"Device", | ||
"DeviceList", | ||
"DeviceScanner", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ | |
:contact: [email protected] | ||
:license: The MIT License (MIT) | ||
""" | ||
# ------------------------------------- | ||
|
||
import time | ||
import typing as tp | ||
|
@@ -20,6 +21,9 @@ | |
from .stream import Stream | ||
|
||
|
||
# -->> Tunables <<--------------------- | ||
|
||
|
||
# -->> Definitions <<------------------ | ||
#: CallBack definition. AbstractSerialized -> bool | ||
CBSerialized2Bool = tp.Callable[[AbstractSerialized], bool] | ||
|
@@ -195,3 +199,10 @@ def on_received(item: AbstractSerialized) -> None: | |
state = "Received" if recv else "Timeout" | ||
SDK_LOG.debug(f"Item response: {state} after {tim.elapsed():.03f}[s]") | ||
return recv | ||
|
||
|
||
# -->> Export <<----------------------- | ||
__all__ = [ | ||
"CBSerialized2Bool", | ||
"Interface", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
:contact: [email protected] | ||
:license: The MIT License (MIT) | ||
""" | ||
# ------------------------------------- | ||
|
||
import abc | ||
import time | ||
|
@@ -21,6 +22,9 @@ | |
from .device import Device | ||
|
||
|
||
# -->> Tunables <<--------------------- | ||
|
||
|
||
# -->> Definitions <<------------------ | ||
|
||
|
||
|
@@ -242,3 +246,10 @@ def _transfer_debug(item: AbstractSerialized, received: bool) -> None: | |
""" | ||
action = "recv" if received else "sent" | ||
SDK_LOG.debug(f"Item {action}: {item}") | ||
|
||
|
||
# -->> Export <<----------------------- | ||
__all__ = [ | ||
"AbstractSerializedStreamCodec", | ||
"Stream", | ||
] |
Oops, something went wrong.