Skip to content

Commit d891323

Browse files
anskhansonkhansonjmoodydependabot[bot]ansjmoody
authored
Keith/api/update parts from avl (#162)
Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Keith Hanson <[email protected]> Co-authored-by: Keith Hanson <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jeff Moody <[email protected]> Co-authored-by: Jeff Moody <[email protected]> Co-authored-by: ansys-pwalters <[email protected]>
1 parent 896c58e commit d891323

File tree

6 files changed

+280
-28
lines changed

6 files changed

+280
-28
lines changed

doc/source/api/parts.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ The ``parts`` module contains all parts management capabilities.
1616
ansys.sherlock.core.parts.Parts.update_parts_list
1717
ansys.sherlock.core.parts.Parts.update_parts_locations
1818
ansys.sherlock.core.parts.Parts.update_parts_locations_by_file
19-
ansys.sherlock.core.parts.Parts.get_part_location
19+
ansys.sherlock.core.parts.Parts.get_part_location
20+
ansys.sherlock.core.parts.Parts.update_parts_from_AVL

doc/source/api/parts_types.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,7 @@ Constants and classes used for the Parts API.
1111
:toctree: _autosummary
1212

1313
PartLocation
14+
PartsListSearchMatchingMode
15+
PartsListSearchDuplicationMode
16+
AVLPartNum
17+
AVLDescription

src/ansys/sherlock/core/errors.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,3 +892,20 @@ def __init__(self, message):
892892
def __str__(self):
893893
"""Format error message."""
894894
return f"Update part modeling props error: {self.message}"
895+
896+
897+
class SherlockUpdatePartsFromAVLError(Exception):
898+
"""Contains the error raised when parts list cannot be updated by AVL."""
899+
900+
def __init__(self, message=None, error_array=None):
901+
"""Initialize error message."""
902+
self.message = message
903+
self.error_array = error_array
904+
905+
def str_itr(self):
906+
"""Create list of error messages."""
907+
if self.message is None:
908+
return [f"Update part from AVL error: {error}" for error in self.error_array]
909+
910+
assert self.error_array is None
911+
return [f"Update part from AVL error: {self.message}"]

src/ansys/sherlock/core/parts.py

Lines changed: 120 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,19 @@
1515
SherlockExportPartsListError,
1616
SherlockGetPartLocationError,
1717
SherlockImportPartsListError,
18+
SherlockUpdatePartsFromAVLError,
1819
SherlockUpdatePartsListError,
1920
SherlockUpdatePartsLocationsByFileError,
2021
SherlockUpdatePartsLocationsError,
2122
)
2223
from ansys.sherlock.core.grpc_stub import GrpcStub
23-
from ansys.sherlock.core.types.parts_types import PartLocation
24+
from ansys.sherlock.core.types.parts_types import (
25+
AVLDescription,
26+
AVLPartNum,
27+
PartLocation,
28+
PartsListSearchDuplicationMode,
29+
PartsListSearchMatchingMode,
30+
)
2431

2532

2633
class Parts(GrpcStub):
@@ -34,6 +41,12 @@ def __init__(self, channel):
3441
self.BOARD_SIDES = None
3542
self.MATCHING_ARGS = ["Both", "Part"]
3643
self.DUPLICATION_ARGS = ["First", "Error", "Ignore"]
44+
self.AVL_PART_NUM_ARGS = [
45+
"AssignInternalPartNum",
46+
"AssignVendorAndPartNum",
47+
"DoNotChangeVendorOrPartNum",
48+
]
49+
self.AVL_DESCRIPTION_ARGS = ["AssignApprovedDescription", "DoNotChangeDescription"]
3750

3851
@staticmethod
3952
def _add_matching_duplication(request, matching, duplication):
@@ -155,8 +168,8 @@ def update_parts_list(
155168
project,
156169
cca_name,
157170
part_library,
158-
matching,
159-
duplication,
171+
matching_mode,
172+
duplication_mode,
160173
):
161174
"""Update a parts list based on matching and duplication preferences.
162175
@@ -168,9 +181,9 @@ def update_parts_list(
168181
Name of the CCA.
169182
part_library : str
170183
Name of the parts library.
171-
matching : UpdatesPartsListRequestMatchingMode
184+
matching_mode : PartsListSearchMatchingMode
172185
Matching mode for updates.
173-
duplication : UpdatesPartsListRequestDuplicationMode
186+
duplication_mode : PartsListSearchDuplicationMode
174187
How to handle duplication during the update.
175188
176189
Returns
@@ -219,7 +232,7 @@ def update_parts_list(
219232
project=project, ccaName=cca_name, partLibrary=part_library
220233
)
221234

222-
self._add_matching_duplication(request, matching, duplication)
235+
self._add_matching_duplication(request, matching_mode, duplication_mode)
223236

224237
response = self.stub.updatePartsList(request)
225238

@@ -690,3 +703,104 @@ def get_part_location(self, project, cca_name, ref_des, location_units):
690703
except SherlockGetPartLocationError as e:
691704
LOG.error(str(e))
692705
raise e
706+
707+
def update_parts_from_AVL(
708+
self,
709+
project: str,
710+
cca_name: str,
711+
matching_mode: PartsListSearchMatchingMode,
712+
duplication_mode: PartsListSearchDuplicationMode,
713+
avl_part_num: AVLPartNum,
714+
avl_description: AVLDescription,
715+
) -> SherlockPartsService_pb2.UpdatePartsListFromAVLResponse:
716+
r"""Update the parts list from the Approved Vendor List (AVL).
717+
718+
Parameters
719+
----------
720+
project : str
721+
Name of the Sherlock project.
722+
cca_name : str
723+
Name of the CCA.
724+
matching_mode: PartsListSearchMatchingMode
725+
Determines how parts are matched against the AVL
726+
duplication_mode: PartsListSearchDuplicationMode
727+
Determines how duplicate part matches are handled when found
728+
avl_part_num: AVLPartNum
729+
Determines what part number info in the parts list is updated from the AVL
730+
avl_description: AVLDescription
731+
Determines if the part description is updated or not
732+
733+
Returns
734+
-------
735+
UpdatePartsListFromAVLResponse
736+
- returnCode : ReturnCode
737+
- value : int
738+
Status code of the response. 0 for success.
739+
- message : str
740+
indicates general errors that occurred while attempting to update parts
741+
- numPartsUpdated : int
742+
Number of parts updated
743+
- updateErrors : list<str>
744+
Errors found when updating part
745+
746+
Examples
747+
--------
748+
>>> from ansys.sherlock.core.launcher import launch_sherlock
749+
>>> from ansys.sherlock.core.types.parts_types import (
750+
AVLDescription,
751+
AVLPartNum,
752+
UpdatesPartsListRequestDuplicationMode,
753+
UpdatesPartsListRequestMatchingMode
754+
)
755+
>>> sherlock = launch_sherlock()
756+
>>> sherlock.project.import_odb_archive(
757+
"C:\\Program Files\\ANSYS Inc\\v241\\sherlock\\tutorial\\ODB++ Tutorial.tgz",
758+
True,
759+
True,
760+
True,
761+
True,
762+
project="Test",
763+
cca_name="Card",
764+
)
765+
>>> sherlock.parts.update_parts_from_AVL(
766+
project="Test",
767+
cca_name="Card",
768+
matching_mode=UpdatesPartsListRequestMatchingMode.BOTH,
769+
duplication=UpdatesPartsListRequestDuplicationMode.FIRST,
770+
avl_part_num=AVLPartNum.ASSIGN_INTERNAL_PART_NUM,
771+
avl_description=AVLDescription.ASSIGN_APPROVED_DESCRIPTION
772+
)
773+
"""
774+
try:
775+
if project == "":
776+
raise SherlockUpdatePartsFromAVLError(message="Project name is invalid.")
777+
if cca_name == "":
778+
raise SherlockUpdatePartsFromAVLError(message="CCA name is invalid.")
779+
780+
request = SherlockPartsService_pb2.UpdatePartsListFromAVLRequest(
781+
project=project,
782+
ccaName=cca_name,
783+
matching=matching_mode,
784+
duplication=duplication_mode,
785+
avlPartNum=avl_part_num,
786+
avlDesc=avl_description,
787+
)
788+
789+
if not self._is_connection_up():
790+
LOG.error("Not connected to a gRPC service.")
791+
return
792+
793+
# Call method on server
794+
response = self.stub.updatePartsListFromAVL(request)
795+
796+
return_code = response.returnCode
797+
798+
if return_code.value == -1:
799+
if return_code.message == "":
800+
raise SherlockUpdatePartsFromAVLError(error_array=response.updateErrors)
801+
raise SherlockUpdatePartsFromAVLError(message=return_code.message)
802+
803+
return response
804+
except SherlockUpdatePartsFromAVLError as e:
805+
LOG.error(str(e))
806+
raise e

src/ansys/sherlock/core/types/parts_types.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,36 @@
88
from ansys.api.sherlock.v0 import SherlockPartsService_pb2
99

1010

11-
class UpdatesPartsListRequestMatchingMode:
12-
"""Constants for Matching Mode in the Update Parts List request."""
11+
class PartsListSearchMatchingMode:
12+
"""Constants for Matching Mode in the Update Parts List and Update Parts from AVL request."""
1313

14-
BOTH = SherlockPartsService_pb2.UpdatePartsListRequest.MatchingMode.Both
15-
PART = SherlockPartsService_pb2.UpdatePartsListRequest.MatchingMode.Part
14+
BOTH = SherlockPartsService_pb2.MatchingMode.Both
15+
PART = SherlockPartsService_pb2.MatchingMode.Part
1616

1717

18-
class UpdatesPartsListRequestDuplicationMode:
19-
"""Constants for Duplication Mode in the Update Parts List request."""
18+
class PartsListSearchDuplicationMode:
19+
"""Constants for Duplication Mode in the Update Parts List and Update Parts from AVL request."""
2020

21-
FIRST = SherlockPartsService_pb2.UpdatePartsListRequest.DuplicationMode.First
22-
ERROR = SherlockPartsService_pb2.UpdatePartsListRequest.DuplicationMode.Error
23-
IGNORE = SherlockPartsService_pb2.UpdatePartsListRequest.DuplicationMode.Ignore
21+
FIRST = SherlockPartsService_pb2.DuplicationMode.First
22+
ERROR = SherlockPartsService_pb2.DuplicationMode.Error
23+
IGNORE = SherlockPartsService_pb2.DuplicationMode.Ignore
24+
25+
26+
class AVLPartNum:
27+
"""Constants for AVLPartNum in the Update Parts List from AVL request."""
28+
29+
ASSIGN_INTERNAL_PART_NUM = SherlockPartsService_pb2.AVLPartNum.AssignInternalPartNum
30+
ASSIGN_VENDOR_AND_PART_NUM = SherlockPartsService_pb2.AVLPartNum.AssignVendorAndPartNum
31+
DO_NOT_CHANGE_VENDOR_OR_PART_NUM = (
32+
SherlockPartsService_pb2.AVLPartNum.DoNotChangeVendorOrPartNum
33+
)
34+
35+
36+
class AVLDescription:
37+
"""Constants for AVLDescription in the Update Parts List from AVL request."""
38+
39+
ASSIGN_APPROVED_DESCRIPTION = SherlockPartsService_pb2.AVLDescription.AssignApprovedDescription
40+
DO_NOT_CHANGE_DESCRIPTION = SherlockPartsService_pb2.AVLDescription.DoNotChangeDescription
2441

2542

2643
class PartLocation:

0 commit comments

Comments
 (0)