From f665815747e427ddb4fefc10c00f2899a08cbec0 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 21 Nov 2024 00:28:17 +0000 Subject: [PATCH 1/3] Update release badge and version file --- README.md | 2 +- osbot_utils/version | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 86fbc7ba..733f2bf6 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Powerful Python util methods and classes that simplify common apis and tasks. -![Current Release](https://img.shields.io/badge/release-v1.81.0-blue) +![Current Release](https://img.shields.io/badge/release-v1.81.1-blue) [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils) diff --git a/osbot_utils/version b/osbot_utils/version index acacdbdf..17f03daa 100644 --- a/osbot_utils/version +++ b/osbot_utils/version @@ -1 +1 @@ -v1.81.0 +v1.81.1 diff --git a/pyproject.toml b/pyproject.toml index 12fdd5df..38962501 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "osbot_utils" -version = "v1.81.0" +version = "v1.81.1" description = "OWASP Security Bot - Utils" authors = ["Dinis Cruz "] license = "MIT" From 2e43488c2bc594007f679a410d87d18b7ecfd9fd Mon Sep 17 00:00:00 2001 From: Dinis Cruz Date: Thu, 21 Nov 2024 17:00:08 +0000 Subject: [PATCH 2/3] added helper status method to Generator_Manager --- osbot_utils/base_classes/Type_Safe.py | 2 ++ .../helpers/generators/Generator_Manager.py | 16 ++++++++++++++++ .../helpers/generators/test_Generator_Manager.py | 6 ++++++ 3 files changed, 24 insertions(+) diff --git a/osbot_utils/base_classes/Type_Safe.py b/osbot_utils/base_classes/Type_Safe.py index 215c06ef..16ce67eb 100644 --- a/osbot_utils/base_classes/Type_Safe.py +++ b/osbot_utils/base_classes/Type_Safe.py @@ -361,3 +361,5 @@ def serialize_to_dict(obj): return data else: raise TypeError(f"Type {type(obj)} not serializable") + #return f"UNSERIALIZABLE({type(obj).__name__})" # todo: see if there are valid use cases for this + diff --git a/osbot_utils/helpers/generators/Generator_Manager.py b/osbot_utils/helpers/generators/Generator_Manager.py index 90983eb3..e96ff0db 100644 --- a/osbot_utils/helpers/generators/Generator_Manager.py +++ b/osbot_utils/helpers/generators/Generator_Manager.py @@ -8,6 +8,7 @@ from osbot_utils.helpers.generators.Generator_Context_Manager import Generator_Context_Manager from osbot_utils.helpers.generators.Model__Generator_State import Model__Generator_State from osbot_utils.helpers.generators.Model__Generator_Target import Model__Generator_Target +from osbot_utils.utils.Lists import list_group_by class Generator_Manager(Type_Safe): # Class for managing multiple generator targets @@ -92,6 +93,21 @@ def stop_all(self) -> int: stopped_count += 1 # Increment the stopped count if successful return stopped_count # Return the total number of stopped generators + def status(self): + items = [] + for _, generator in self.generators.items(): + item = dict(target_method_name = generator.target.__name__, + target_state = generator.state.value, + target_id = generator.target_id ) + items.append(item) + items__by_state = list_group_by(items, 'target_state') + result = {} + for state, items in items__by_state.items(): + result[state] = len(items) + result['data'] = items__by_state + return result + + def target_id(self, target: GeneratorType) -> Union[Random_Guid, None]: # Method to get the ID of a specific generator with self.lock: # Acquire the lock for thread-safe access for generator in list(self.generators.values()): # Iterate over the generator targets diff --git a/tests/unit/helpers/generators/test_Generator_Manager.py b/tests/unit/helpers/generators/test_Generator_Manager.py index ec7c7934..84b90c71 100644 --- a/tests/unit/helpers/generators/test_Generator_Manager.py +++ b/tests/unit/helpers/generators/test_Generator_Manager.py @@ -38,6 +38,12 @@ def sample_generator(): self.assertEqual(generator.target, gen) self.assertEqual(generator.state, Model__Generator_State.RUNNING) + + assert self.manager.status() == { 'data': { 'running': [{ 'target_id' : target_id , + 'target_state' : 'running' , + 'target_method_name': 'sample_generator'}]}, + 'running': 1} + def test_add_duplicate_generator(self): def sample_generator(): yield 1 From b5357157140e52ff9aceebe633500c86bb2d84cd Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 21 Nov 2024 17:01:46 +0000 Subject: [PATCH 3/3] Update release badge and version file --- README.md | 2 +- osbot_utils/version | 2 +- pyproject.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 733f2bf6..6ab203f8 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ Powerful Python util methods and classes that simplify common apis and tasks. -![Current Release](https://img.shields.io/badge/release-v1.81.1-blue) +![Current Release](https://img.shields.io/badge/release-v1.81.2-blue) [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils) diff --git a/osbot_utils/version b/osbot_utils/version index 17f03daa..494f9579 100644 --- a/osbot_utils/version +++ b/osbot_utils/version @@ -1 +1 @@ -v1.81.1 +v1.81.2 diff --git a/pyproject.toml b/pyproject.toml index 38962501..9573526d 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "osbot_utils" -version = "v1.81.1" +version = "v1.81.2" description = "OWASP Security Bot - Utils" authors = ["Dinis Cruz "] license = "MIT"