-
Notifications
You must be signed in to change notification settings - Fork 806
Double down on hooks, remove app plugin in favour of individual hooks for individual capabilities #12879
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
Draft
rtibbles
wants to merge
7
commits into
learningequality:develop
Choose a base branch
from
rtibbles:hooked_on_plugins
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+583
−558
Draft
Double down on hooks, remove app plugin in favour of individual hooks for individual capabilities #12879
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7c25ca8
Remove use of deprecated abstractproperty.
rtibbles ad43f28
Add hook to add magicbus plugins to the processbus.
rtibbles c78c337
Add class property to check if any hooks are registered.
rtibbles 5b952e6
Delete app plugin - transfer all functionality to core hooks.
rtibbles 7d94bc5
Move auto reloader attachment into development plugin.
rtibbles 0a923cf
Remove use of checkCapability function in favour of more explicit che…
rtibbles 43cef82
Re-implement share file functionality.
rtibbles 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 |
---|---|---|
@@ -1,11 +1,9 @@ | ||
Testing Kolibri with app plugin enabled | ||
======================================= | ||
Testing Kolibri in app mode | ||
=========================== | ||
|
||
The Kolibri app plugin | ||
---------------------- | ||
App mode | ||
-------- | ||
|
||
The Kolibri app plugin is designed to provide features and behavior with the mobile app user in mind. In order to test or develop Kolibri in this mode, there are commands that can be used to initialize Kolibri as needed. | ||
Kolibri app mode is designed to provide features and behavior with the mobile app user in mind. In order to test or develop Kolibri in this mode, a browser session can be set to app mode. | ||
|
||
By running the command: `yarn app-python-devserver` you will start Kolibri in development mode. You can also run `yarn app-devserver` to run the frontend devserver in parallel. | ||
|
||
When you start the server with these commands, you will see a message with a URL pointing to `http://127.0.0.1:8000/app/api/initialize/<some token>` - visiting this URL will set your browser so that it can interact with Kolibri as it runs with the app plugin. **You will only have to do this once unless you clear your browser storage.** | ||
When you start the server, you will see a message with a URL pointing to `http://127.0.0.1:8000/app/api/initialize/<some token>` - visiting this URL will set your browser so that it can interact with Kolibri in app mode. **You will only have to do this once unless you clear your browser storage.** |
File renamed without changes.
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,90 @@ | ||
import logging | ||
import os | ||
|
||
from magicbus.plugins import SimplePlugin | ||
from magicbus.plugins.tasks import Autoreloader | ||
|
||
from kolibri.core.content.hooks import ShareFileHook | ||
from kolibri.core.device.hooks import CheckIsMeteredHook | ||
from kolibri.core.device.hooks import GetOSUserHook | ||
from kolibri.core.tasks.hooks import JobHook | ||
from kolibri.plugins import KolibriPluginBase | ||
from kolibri.plugins.hooks import register_hook | ||
from kolibri.utils.server.hooks import KolibriProcessHook | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ExampleAppPlugin(KolibriPluginBase): | ||
pass | ||
|
||
|
||
@register_hook | ||
class ExampleAppGetOSUserHook(GetOSUserHook): | ||
def get_os_user(self, auth_token): | ||
return "os_user", True | ||
|
||
|
||
@register_hook | ||
class ExampleAppCheckIsMeteredHook(CheckIsMeteredHook): | ||
def check_is_metered(self): | ||
return True | ||
|
||
|
||
@register_hook | ||
class ExampleAppShareFileHook(ShareFileHook): | ||
def share_file(self, file_path, message): | ||
logger.debug(f"Sharing file {file_path} with message {message}") | ||
|
||
|
||
@register_hook | ||
class ExampleAppJobHook(JobHook): | ||
def schedule(self, job, orm_job): | ||
logger.debug(f"Scheduling job {job} with ORM job {orm_job}") | ||
|
||
def update(self, job, orm_job, state=None, **kwargs): | ||
from kolibri.core.tasks.job import log_status | ||
|
||
log_status(job, orm_job, state=state, **kwargs) | ||
|
||
def clear(self, job, orm_job): | ||
logger.debug(f"Clearing job {job} with ORM job {orm_job}") | ||
|
||
|
||
class AppUrlLoggerPlugin(SimplePlugin): | ||
def SERVING(self, port): | ||
self.port = port | ||
|
||
def RUN(self): | ||
from kolibri.core.device.utils import app_initialize_url | ||
|
||
start_url = "http://127.0.0.1:{port}".format( | ||
port=self.port | ||
) + app_initialize_url(auth_token="1234") | ||
# Use warning to make sure this message stands out in the console | ||
logger.warning( | ||
"Open this URL to activate app mode: {start_url}".format( | ||
start_url=start_url | ||
) | ||
) | ||
|
||
|
||
@register_hook | ||
class DeveloperAppUrlLogger(KolibriProcessHook): | ||
MagicBusPluginClass = AppUrlLoggerPlugin | ||
|
||
|
||
class KolibriAutoReloader(Autoreloader): | ||
def __init__(self, bus): | ||
super().__init__(bus) | ||
from kolibri.utils import conf | ||
|
||
plugins = os.path.join(conf.KOLIBRI_HOME, "plugins.json") | ||
options = os.path.join(conf.KOLIBRI_HOME, "options.ini") | ||
self.files.add(plugins) | ||
self.files.add(options) | ||
|
||
|
||
@register_hook | ||
class KolibriAutoReloadHook(KolibriProcessHook): | ||
MagicBusPluginClass = KolibriAutoReloader |
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.