-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feta: add typing support for demo project
- Loading branch information
Showing
1 changed file
with
22 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# ------------------------------------------------------------------------------- | ||
# Copyright (c) 2019-2020 Siemens | ||
# Copyright (c) 2019-2023 Siemens | ||
# All Rights Reserved. | ||
# Author: [email protected] | ||
# | ||
|
@@ -37,6 +37,8 @@ | |
import argparse | ||
import os | ||
import sys | ||
from typing import Any, Dict, List, Optional | ||
|
||
from colorama import init, Fore, Style | ||
import requests | ||
import sw360 | ||
|
@@ -51,23 +53,26 @@ | |
|
||
class CheckProject(): | ||
"""Check a project on SW360, display component clearing status""" | ||
def __init__(self): | ||
def __init__(self) -> None: | ||
self.client = None | ||
self.project_id = "" | ||
self.project = None | ||
self.sw360_url = "https://sw360.siemens.com" | ||
|
||
@classmethod | ||
def get_clearing_state(cls, proj, href): | ||
def get_clearing_state(cls, proj: Dict[Any, Any], href: str) -> str | None: | ||
"""Returns the clearing state of the given component/release""" | ||
if "linkedReleases" not in proj: | ||
return None | ||
|
||
rel = proj["linkedReleases"] | ||
for key in rel: | ||
if key["release"] == href: | ||
return key["mainlineState"] | ||
|
||
return None | ||
|
||
def has_source_code(self, href): | ||
def has_source_code(self, href: str) -> bool: | ||
"""Returns true if a source code attachment is available""" | ||
rel = self.client.get_release_by_url(href) | ||
if "_embedded" not in rel: | ||
|
@@ -83,8 +88,11 @@ def has_source_code(self, href): | |
|
||
return False | ||
|
||
def show_linked_projects(self, project): | ||
def show_linked_projects(self, project: Dict[Any, Any]) -> None: | ||
"""Show linked projects of the given project""" | ||
if "_embedded" not in project: | ||
return | ||
|
||
if "sw360:projects" in project["_embedded"]: | ||
linked_projects = project["_embedded"]["sw360:projects"] | ||
if linked_projects: | ||
|
@@ -94,8 +102,11 @@ def show_linked_projects(self, project): | |
else: | ||
print("\n No linked projects") | ||
|
||
def show_linked_releases(self, project): | ||
def show_linked_releases(self, project: Dict[Any, Any]) -> None: | ||
"""Show linked releases of the given project""" | ||
if "_embedded" not in project: | ||
return | ||
|
||
if "sw360:releases" in project["_embedded"]: | ||
print("\n Components: ") | ||
releases = project["_embedded"]["sw360:releases"] | ||
|
@@ -117,7 +128,7 @@ def show_linked_releases(self, project): | |
else: | ||
print(" No linked releases") | ||
|
||
def show_project_status(self, project_id): | ||
def show_project_status(self, project_id: str) -> None: | ||
"""Retrieve and display project status""" | ||
try: | ||
project = self.client.get_project(project_id) | ||
|
@@ -134,7 +145,7 @@ def show_project_status(self, project_id): | |
self.show_linked_projects(project) | ||
self.show_linked_releases(project) | ||
|
||
def login(self, token=None, url=None): | ||
def login(self, token: Optional[str] = None, url: Optional[str] = None) -> bool | sw360.SW360Error: | ||
"""Login to SW360""" | ||
if token: | ||
sw360_api_token = token | ||
|
@@ -167,7 +178,7 @@ def login(self, token=None, url=None): | |
" Error authorizing user!" + | ||
Style.RESET_ALL) | ||
|
||
def find_project(self, name, version): | ||
def find_project(self, name: str, version: str) -> Optional[List[Dict[Any, Any]]]: | ||
"""Find the project with the matching name and version on SW360""" | ||
projects = self.client.get_projects_by_name(name) | ||
if not projects: | ||
|
@@ -199,7 +210,7 @@ def find_project(self, name, version): | |
return None | ||
|
||
@classmethod | ||
def parse_commandline(cls): | ||
def parse_commandline(cls) -> Any: | ||
"""Parse command line arguments""" | ||
parser = argparse.ArgumentParser( | ||
description="Check a project on SW360, display component clearing status" | ||
|
@@ -231,7 +242,7 @@ def parse_commandline(cls): | |
|
||
return args | ||
|
||
def main(self): | ||
def main(self) -> None: | ||
"""Main method""" | ||
print("\nCheck a project on SW360") | ||
|
||
|