-
Notifications
You must be signed in to change notification settings - Fork 79
stdlib: Actor API convenience library #405
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,163 @@ | ||
| """ | ||
| This module implements a convenience API for actions that are accessible to actors. | ||
|
|
||
| Any code that wants use this convenience library has to be called from within the actors context. | ||
| This is true for actors, actor private libraries and repository libraries. | ||
| """ | ||
| from leapp.actors import Actor | ||
|
|
||
|
|
||
| ErrorSeverity = Actor.ErrorSeverity | ||
|
|
||
|
|
||
| def current_actor(): | ||
| """ | ||
| Retrieve the Actor class instance of the current active actor. | ||
| :return: Instance of the currently instantiated actor. | ||
| :rtype: leapp.actors.Actor | ||
| """ | ||
| return Actor.current_instance | ||
|
|
||
|
|
||
| def report_error(message, severity=ErrorSeverity.ERROR, details=None): | ||
| """ | ||
| Reports an execution error | ||
|
|
||
| :param message: A message to print the possible error | ||
| :type message: str | ||
| :param severity: Severity of the error default :py:attr:`leapp.messaging.errors.ErrorSeverity.ERROR` | ||
| :type severity: str with defined values from :py:attr:`leapp.messaging.errors.ErrorSeverity.ERROR` | ||
| :param details: A dictionary where additional context information is passed along with the error | ||
| :type details: dict | ||
| :return: None | ||
| """ | ||
| return current_actor().report_error(message=message, severity=severity, details=details) | ||
|
|
||
|
|
||
| def current_logger(): | ||
| """ | ||
| Retrieve the logger of the current active actor. | ||
| :return: Logger instance for the current actor. | ||
| :rtype: logging.Logger | ||
| """ | ||
| return current_actor().log | ||
|
|
||
|
|
||
| def produce(*model_instances): | ||
| """ | ||
| By calling produce, model instances are stored as messages. Those messages can be then consumed by other actors. | ||
|
|
||
| :param model_instances: Messages to be sent (those model types have to be specified in :py:attr:`produces` | ||
| :type model_instances: Variable number of instances of derived classes from :py:class:`leapp.models.Model` | ||
| """ | ||
| return current_actor().produce(*model_instances) | ||
|
|
||
|
|
||
| def consume(*models): | ||
| """ | ||
| Retrieve messages specified in the actors :py:attr:`consumes` attribute, and filter message types by | ||
| models. | ||
|
|
||
| :param models: Models to use as a filter for the messages to return | ||
| :type models: Variable number of the derived classes from :py:class:`leapp.models.Model` | ||
| """ | ||
| return current_actor().consume(*models) | ||
|
|
||
|
|
||
| def request_answers(dialog): | ||
| """ | ||
| Requests the answers for a dialog. The dialog needs be predefined in :py:attr:`dialogs` of the actor. | ||
|
|
||
| :param dialog: Dialog instance to show | ||
| :return: dictionary with the requested answers, None if not a defined dialog | ||
| """ | ||
| return current_actor().request_answers(dialog) | ||
|
|
||
|
|
||
| def actor_files_paths(): | ||
| """ | ||
| Returns the file paths that are bundled with the actor. (Path to the content of the actor's file directory). | ||
| """ | ||
| return current_actor().actor_files_paths | ||
|
|
||
|
|
||
| def files_paths(): | ||
| """ Returns all actor file paths related to the actor and common actors file paths. """ | ||
| return current_actor().files_paths | ||
|
|
||
|
|
||
| def common_files_paths(): | ||
| """ Returns all common repository file paths. """ | ||
| return current_actor().common_files_paths | ||
|
|
||
|
|
||
| def get_common_folder_path(name): | ||
| """ | ||
| Finds the first matching folder path within :py:attr:`files_paths`. | ||
|
|
||
| :param name: Name of the folder | ||
| :type name: str | ||
| :return: Found folder path | ||
| :rtype: str or None | ||
| """ | ||
| return current_actor().get_common_folder_path(name) | ||
|
|
||
|
|
||
| def get_actor_folder_path(name): | ||
| """ | ||
| Finds the first matching folder path within :py:attr:`files_paths`. | ||
|
|
||
| :param name: Name of the folder | ||
| :type name: str | ||
| :return: Found folder path | ||
| :rtype: str or None | ||
| """ | ||
| return current_actor().get_actor_folder_path(name) | ||
|
|
||
|
|
||
| def get_folder_path(name): | ||
| """ | ||
| Finds the first matching folder path within :py:attr:`files_paths`. | ||
|
|
||
| :param name: Name of the folder | ||
| :type name: str | ||
| :return: Found folder path | ||
| :rtype: str or None | ||
| """ | ||
| return current_actor().get_folder_path(name) | ||
|
|
||
|
|
||
| def get_common_file_path(name): | ||
| """ | ||
| Finds the first matching file path within :py:attr:`files_paths`. | ||
|
|
||
| :param name: Name of the file | ||
| :type name: str | ||
| :return: Found file path | ||
| :rtype: str or None | ||
| """ | ||
| return current_actor().get_common_file_path(name) | ||
|
|
||
|
|
||
| def get_actor_file_path(name): | ||
| """ | ||
| Finds the first matching file path within :py:attr:`files_paths`. | ||
|
|
||
| :param name: Name of the file | ||
| :type name: str | ||
| :return: Found file path | ||
| :rtype: str or None | ||
| """ | ||
| return current_actor().get_actor_file_path(name) | ||
|
|
||
|
|
||
| def get_file_path(name): | ||
| """ | ||
| Finds the first matching file path within :py:attr:`files_paths`. | ||
|
|
||
| :param name: Name of the file | ||
| :type name: str | ||
| :return: Found file path | ||
| :rtype: str or None | ||
| """ | ||
| return current_actor().get_file_path(name) |
This file contains hidden or 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 hidden or 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 @@ | ||
| {"name": "actor-api-tests", "id": "e2b55c03-1c07-4cb6-bab8-cca7315f86f0"} |
This file contains hidden or 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,6 @@ | ||
|
|
||
| [repositories] | ||
| repo_path=${repository:root_dir} | ||
|
|
||
| [database] | ||
| path=${repository:state_dir}/leapp.db |
This file contains hidden or 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,14 @@ | ||
| from leapp.actors import Actor | ||
| from leapp.tags import ActorFileApiTag | ||
| from leapp.models import ApiTestConsume, ApiTestProduce | ||
|
|
||
|
|
||
| class First(Actor): | ||
| name = 'first' | ||
| description = 'No description has been provided for the first actor.' | ||
| consumes = (ApiTestConsume,) | ||
| produces = (ApiTestProduce,) | ||
| tags = (ActorFileApiTag,) | ||
|
|
||
| def process(self): | ||
| pass |
Empty file.
This file contains hidden or 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 @@ | ||
| first-actor |
This file contains hidden or 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,14 @@ | ||
| from leapp.actors import Actor | ||
| from leapp.tags import ActorFileApiTag | ||
| from leapp.models import ApiTestConsume, ApiTestProduce | ||
|
|
||
|
|
||
| class Second(Actor): | ||
| name = 'second' | ||
| description = 'No description has been provided for the second actor.' | ||
| consumes = (ApiTestConsume,) | ||
| produces = (ApiTestProduce,) | ||
| tags = (ActorFileApiTag,) | ||
|
|
||
| def process(self): | ||
| pass |
Empty file.
This file contains hidden or 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 @@ | ||
| second-actor |
Empty file.
This file contains hidden or 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 @@ | ||
| repository |
This file contains hidden or 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,16 @@ | ||
| from leapp.models import Model, fields | ||
| from leapp.topics import ApiTestTopic | ||
|
|
||
|
|
||
| class ApiTest(Model): | ||
| topic = ApiTestTopic | ||
|
|
||
| data = fields.String() | ||
|
|
||
|
|
||
| class ApiTestProduce(ApiTest): | ||
| pass | ||
|
|
||
|
|
||
| class ApiTestConsume(ApiTest): | ||
| pass |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we are mixing
folderanddirectory(not only here)? I prefer to use directory equivalent everywhere. So_get_dir_path, ....