-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add logical plugin example to tutorial fix #122
- Loading branch information
Showing
29 changed files
with
397 additions
and
52 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
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
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
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
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
Empty file.
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.apps import AppConfig | ||
|
||
from django_typer.utils import register_command_plugins | ||
|
||
|
||
class BackupFilesConfig(AppConfig): | ||
name = "tests.apps.examples.plugins.backup_files" | ||
label = name.replace(".", "_") |
Empty file.
Empty file.
41 changes: 41 additions & 0 deletions
41
examples/plugins/backup_files/management/commands/backup.py
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import sys | ||
import typing as t | ||
from pathlib import Path | ||
|
||
import typer | ||
import pluggy | ||
|
||
from tests.apps.examples.plugins.media1.management.commands.backup import ( | ||
Command as Backup, | ||
) | ||
|
||
|
||
class Command(Backup): # inherit from the extended media backup command | ||
plugins = pluggy.PluginManager("backup") | ||
hookspec = pluggy.HookspecMarker("backup") | ||
hookimpl = pluggy.HookimplMarker("backup") | ||
|
||
# add a new command called files that delegates file backups to plugins | ||
@Backup.command() | ||
def files(self): | ||
""" | ||
Backup app specific non-media files. | ||
""" | ||
for archive in self.plugins.hook.backup_files(command=self): | ||
if archive: | ||
typer.echo(f"Backed up files to {archive}") | ||
|
||
|
||
@Command.hookspec | ||
def backup_files(command: Command) -> t.Optional[Path]: | ||
""" | ||
A hook for backing up app specific files. | ||
Must return the path to the archive file or None if no files were backed up. | ||
:param command: the backup command instance | ||
:return: The path to the archived backup file | ||
""" | ||
|
||
|
||
Command.plugins.add_hookspecs(sys.modules[__name__]) |
Oops, something went wrong.