-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from inetrg/pr/location_improvements
Some fixes for location and add location cache
- Loading branch information
Showing
10 changed files
with
209 additions
and
33 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
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
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import argparse | ||
|
||
import inet_nm.config as cfg | ||
import inet_nm.location as loc | ||
from inet_nm._helpers import nm_print | ||
|
||
|
||
def _main(): | ||
parser = argparse.ArgumentParser(description="Update the location cache") | ||
cfg.config_arg(parser) | ||
|
||
args = parser.parse_args() | ||
loc_mapping = cfg.LocationConfig(config_dir=args.config).load() | ||
nodes = cfg.NodesConfig(config_dir=args.config).load() | ||
loc_cache = cfg.LocationCache(config_dir=args.config) | ||
loc_cache.check_file(writable=True) | ||
|
||
cache = loc.get_location_cache(nodes, loc_mapping) | ||
|
||
loc_cache.save(cache) | ||
nm_print(f"Updated {loc_cache.file_path}") | ||
|
||
|
||
def main(): | ||
"""Updates the current state of board locations.""" | ||
try: | ||
_main() | ||
except KeyboardInterrupt: | ||
nm_print("\nUser aborted...") | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from typing import Dict, List | ||
|
||
import inet_nm.usb_ctrl as ucl | ||
from inet_nm.data_types import NmNode | ||
|
||
|
||
def get_location_cache(nodes: List[NmNode], id_paths: Dict): | ||
""" | ||
Get the location cache for a list of NmNode objects. | ||
Args: | ||
nodes: List of NmNode objects. | ||
id_paths: List of id_paths to check. | ||
Returns: | ||
The location cache. | ||
""" | ||
processed_id_paths = set() | ||
cache = [] | ||
node_uids = {node.uid for node in nodes if not node.ignore} | ||
for id_path in id_paths: | ||
node_uid = ucl.get_uid_from_id_path(id_path) | ||
if node_uid is not None and node_uid in node_uids: | ||
cache.append( | ||
{"id_path": id_path, "node_uid": node_uid, "state": "attached"} | ||
) | ||
else: | ||
cache.append({"id_path": id_path, "node_uid": node_uid, "state": "missing"}) | ||
processed_id_paths.add(id_path) | ||
|
||
for node in nodes: | ||
try: | ||
id_path = ucl.get_id_path_from_node(node) | ||
if id_path not in processed_id_paths: | ||
cache.append( | ||
{"id_path": id_path, "node_uid": node.uid, "state": "unassigned"} | ||
) | ||
processed_id_paths.add(id_path) | ||
except Exception: | ||
pass | ||
cache.sort(key=lambda x: x["id_path"]) | ||
return cache |
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
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