Skip to content

Commit

Permalink
feat: uniform function names
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Schneider committed Dec 13, 2023
1 parent 6113e6b commit 5cc00bc
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 91 deletions.
14 changes: 7 additions & 7 deletions capella2polarion/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,17 @@ def synchronize(ctx: click.core.Context) -> None:
aC2PCli: C2PCli = ctx.obj
aC2PCli.logger.info(
f"""
Synchronising diagrams from diagram cache at '{str(aC2PCli.getCapellaDiagramCacheIndexFilePath())}'
Synchronising diagrams from diagram cache at '{str(aC2PCli.get_capella_diagram_cache_index_file_path())}'
to Polarion project with id {aC2PCli.ProjectId}...
"""
)
# ctx.obj["DIAGRAM_CACHE"] = None # Orignal ... aDiagramCachePath ... None damit es Crashed!
# ctx.obj["MODEL"] = model
# ctx.obj["CONFIG"] = yaml.safe_load(config_file)
aC2PCli.loadSynchronizeConfig()
aC2PCli.load_synchronize_config()
# ctx.obj["ROLES"] = _get_roles_from_config(ctx.obj)
aC2PCli.loadRolesFromSynchronizeConfig()
aC2PCli.loadCapellaDiagrammCacheIndex()
aC2PCli.load_roles_from_synchronize_config()
aC2PCli.load_capella_diagramm_cache_index()
# (
# ctx.obj["ELEMENTS"],
# ctx.obj["POLARION_TYPE_MAP"],
Expand All @@ -133,15 +133,15 @@ def synchronize(ctx: click.core.Context) -> None:
lPW = PolarionWorker(
aC2PCli.PolarionClient, aC2PCli.logger, helpers.resolve_element_type
)
lPW.loadElementsAndTypeMap(
lPW.load_elements_and_type_map(
aC2PCli.SynchronizeConfigContent,
aC2PCli.CapellaModel,
aC2PCli.CapellaDiagramCacheIndexContent,
)
# types = elements.get_types(
# ctx.obj["POLARION_TYPE_MAP"], ctx.obj["ELEMENTS"]
# )
lPW.fillXTypes()
lPW.fill_xtypes()
# ctx.obj["POLARION_WI_MAP"] = elements.get_polarion_wi_map(
# types, ctx.obj["API"]
# )
Expand All @@ -151,7 +151,7 @@ def synchronize(ctx: click.core.Context) -> None:
# ctx.obj["POLARION_ID_MAP"] = {
# uuid: wi.id for uuid, wi in ctx.obj["POLARION_WI_MAP"].items()
# }
lPW.loadPolarionWorkItemMap()
lPW.load_polarion_work_item_map()
# ctx.obj["DESCR_REFERENCES"] = {}
# new_work_items = elements.element.create_work_items(
# ctx.obj["ELEMENTS"],
Expand Down
39 changes: 19 additions & 20 deletions capella2polarion/c2pcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ def __init__(
self.PolarionUrl = aPolarionUrl
self.PolarionPat = aPolarionPat
self.PolarionDeleteWorkItems = aPolarionDeleteWorkItems
self.PolarionClient
self.PolarionClient: polarion_api.OpenAPIPolarionProjectClient | None = (
None
)
self.CapellaDiagramCacheFolderPath = capella_diagram_cache_folder_path
self.CapellaDiagramCacheIndexContent: list[
dict[str, typing.Any]
] | None = None
self.CapellaModel: cli_helpers.ModelCLI = capella_model
self.SynchronizeConfigIO: typing.TextIO = synchronize_config_io
self.SynchronizeConfigContent: dict[str, typing.Any]
self.SynchronizeConfigRoles: dict[str, list[str]]
self.SynchronizeConfigRoles: dict[str, list[str]] | None = None
self.echo = click.echo
self.logger: logging.Logger

Expand All @@ -76,7 +78,7 @@ def _value(aValue):
if lMyLightedMember[0].isupper():
lValue = getattr(self, lMyLightedMember)
lType = type(lValue)
lConverter = {
lConverter: dict[typing.Type, typing.Callable] = {
bool: str,
int: str,
float: str,
Expand All @@ -85,14 +87,12 @@ def _value(aValue):
pathlib.PosixPath: str,
}
if lType in lConverter:
lStringValue = """"""
# @MH hier macht mir der mypy probleme
# (
# "None" if lValue == None else lConverter[lType](lValue)
# )
lStringValue = (
"None" if lValue is None else lConverter[lType](lValue)
)
else:
lStringValue = _type(lValue)
# lStringValue = self._noneSaveValueString(lStringValue)
lStringValue = self._noneSaveValueString(lStringValue)
self.echo(f"{lMyLightedMember}: '{lStringValue}'")
self.echo(
f"Capella Diagram Cache Index-File exits: {('YES' if self.exitsCapellaDiagrammCacheIndexFile() else 'NO')}"
Expand Down Expand Up @@ -125,8 +125,7 @@ def setupPolarionClient(self) -> None:
custom_work_item=serialize.CapellaWorkItem,
add_work_item_checksum=True,
)
if self.PolarionClient == None:
raise Exception("Polarion invalid Client / None Client")
# assert self.PolarionClient is not None
if self.PolarionClient.project_exists():
raise Exception(
f"Miss Polarion project with id {self._noneSaveValueString(self.ProjectId)}"
Expand All @@ -150,7 +149,7 @@ def setupLogger(self) -> None:
GLogger.parent.addHandler(lConsoleHandler)
self.logger = GLogger

def loadSynchronizeConfig(self) -> None:
def load_synchronize_config(self) -> None:
"""Read the sync config into SynchronizeConfigContent.
- example in /tests/data/model_elements/config.yaml
Expand All @@ -164,7 +163,7 @@ def loadSynchronizeConfig(self) -> None:
self.SynchronizeConfigIO
)

def loadRolesFromSynchronizeConfig(self) -> None:
def load_roles_from_synchronize_config(self) -> None:
"""Fill SynchronizeConfigRoles and correct content."""
if self.SynchronizeConfigContent == None:
raise Exception("first call loadSynchronizeConfig")
Expand Down Expand Up @@ -240,7 +239,7 @@ def loadRolesFromSynchronizeConfig(self) -> None:
roles[typ] = []
self.SynchronizeConfigRoles = roles

def getCapellaDiagramCacheIndexFilePath(self) -> pathlib.Path:
def get_capella_diagram_cache_index_file_path(self) -> pathlib.Path:
"""Return index file path."""
if self.CapellaDiagramCacheFolderPath == None:
raise Exception("CapellaDiagramCacheFolderPath not filled")
Expand All @@ -250,22 +249,22 @@ def exitsCapellaDiagrammCacheIndexFile(self) -> bool:
"""Test existens of file."""
return (
False
if self.getCapellaDiagramCacheIndexFilePath() == None
else self.getCapellaDiagramCacheIndexFilePath().is_file()
if self.get_capella_diagram_cache_index_file_path() == None
else self.get_capella_diagram_cache_index_file_path().is_file()
)

def loadCapellaDiagrammCacheIndex(self) -> None:
def load_capella_diagramm_cache_index(self) -> None:
"""Load to CapellaDiagramCacheIndexContent."""
if not self.exitsCapellaDiagrammCacheIndexFile():
raise Exception("capella diagramm cache index file doe not exits")
self.CapellaDiagramCacheIndexContent = None
if self.getCapellaDiagramCacheIndexFilePath() != None:
if self.get_capella_diagram_cache_index_file_path() != None:
l_text_content = (
self.getCapellaDiagramCacheIndexFilePath().read_text(
self.get_capella_diagram_cache_index_file_path().read_text(
encoding="utf8"
)
)
self.CapellaDiagramCacheIndexContent = json.loads(l_text_content)

def _noneSaveValueString(self, aValue: str | None) -> str | None:
return "None" if aValue == None else aValue
return "None" if aValue is None else aValue
50 changes: 29 additions & 21 deletions capella2polarion/polarion.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ def __init__(
str, serialize.CapellaWorkItem
] # dict[str, typing.Any] = None
self.makeTypeId: typing.Any = aMakeTypeId
self.Simulation: bool = True

def loadElementsAndTypeMap(
def load_elements_and_type_map(
self,
config: dict[str, typing.Any],
model: capellambse.MelodyModel,
Expand Down Expand Up @@ -139,26 +140,31 @@ def _fix_components(
self.PolarionTypeMap = type_map
self.CapellaUUIDs = set(self.PolarionTypeMap)

def fillXTypes(self):
def fill_xtypes(self):
"""Return a set of Polarion types from the current context."""
xtypes = set[str]()
for obj in chain.from_iterable(self.Elements.values()):
xtype = self.PolarionTypeMap.get(obj.uuid, type(obj).__name__)
xtypes.add(self.makeTypeId(xtype))
self.XTypes = xtypes

def loadPolarionWorkItemMap(self):
def load_polarion_work_item_map(self):
"""Return a map from Capella UUIDs to Polarion work items."""
work_item_types = list(map(self.makeTypeId, self.XTypes))
_type = " ".join(work_item_types)
work_items = self.client.get_all_work_items(
f"type:({_type})", {"workitems": "id,uuid_capella,checksum,status"}
)
self.PolarionWorkItemMap = {
wi.uuid_capella: wi
for wi in work_items
if wi.id and wi.uuid_capella
}
if self.Simulation:
work_items = {"84a64a2d-3491-48af-b55b-823010a3e006": "doppelweck"}
else:
work_items = self.client.get_all_work_items(
f"type:({_type})",
{"workitems": "id,uuid_capella,checksum,status"},
)
# @as
# self.PolarionWorkItemMap = {
# wi.uuid_capella: wi
# for wi in work_items
# if wi.id and wi.uuid_capella
# }
self.PolarionIdMap = {
uuid: wi.id for uuid, wi in self.PolarionWorkItemMap.items()
}
Expand Down Expand Up @@ -223,7 +229,8 @@ def serialize_for_delete(uuid: str) -> str:
work_item_ids = [serialize_for_delete(uuid) for uuid in uuids]
if work_item_ids:
try:
self.client.delete_work_items(work_item_ids)
if not self.Simulation:
self.client.delete_work_items(work_item_ids)
for uuid in uuids:
del self.PolarionWorkItemMap[uuid]
del self.PolarionIdMap[uuid]
Expand All @@ -246,7 +253,8 @@ def post_work_items(
self.logger.info("Create work item for %r...", work_item.title)
if missing_work_items:
try:
self.client.create_work_items(missing_work_items)
if not self.Simulation:
self.client.create_work_items(missing_work_items)
for work_item in missing_work_items:
self.PolarionIdMap[work_item.uuid_capella] = work_item.id
self.PolarionWorkItemMap[
Expand Down Expand Up @@ -302,11 +310,11 @@ def patch_work_items(
element.create_grouped_back_link_fields(
new_work_item, back_links[old_work_item.id]
)

api_helper.patch_work_item(
self.client,
new_work_item,
old_work_item,
old_work_item.title,
"element",
)
if not self.Simulation:
api_helper.patch_work_item(
self.client,
new_work_item,
old_work_item,
old_work_item.title,
"element",
)
Loading

0 comments on commit 5cc00bc

Please sign in to comment.