Split 'result' plugin type into 'location' and 'feedback'

> 'location' plugins generate locations the resource can be accessed
> 'feedback' plugins present that location in some way that's useful to the human user

Also don't user relative imports in default plugins
This commit is contained in:
Gnarwhal 2024-09-08 21:14:22 +00:00
parent 6a310b8ca9
commit 6d549d27c5
Signed by: Gnarwhal
GPG key ID: 0989A73D8C421174
8 changed files with 43 additions and 23 deletions

@ -1 +1 @@
Subproject commit 1466438938c98442aa6de55065b7e6a06a7e8d50
Subproject commit 92bb65a049942b127ee6108bff5812c110acfe12

View file

@ -26,7 +26,6 @@ from sshare.plugin import Plugin
from sshare.plugin import PluginManager
from sshare.version import version
def main():
arg_parser = argparse.ArgumentParser(
prog="sshare",
@ -63,7 +62,7 @@ def main():
command_line = Plugin.internal(INTERNAL_PLUGIN_LOCATION, "command_line", config.get("plugins", dict()))
logger = Logger(command_line=command_line)
plugins = PluginManager(
[ "logger", "source", "name", "upload", "result" ],
[ "logger", "source", "name", "upload", "location", "feedback" ],
logger,
config.get("plugins", dict()),
arg_parser,
@ -74,7 +73,8 @@ def main():
"current_time",
"append_type",
"ssh",
"log_result",
"uri",
"print_location",
)
sys.dont_write_bytecode = True
plugins.add_from(
@ -94,8 +94,6 @@ def main():
sources = []
for plugin in plugins.source.active:
sources.append(plugin.get_source())
if len(sources) == 0:
logger.error("Error: No sources provided. Must activate at least one source plugin.")
for index, source in enumerate(sources):
name = ""
@ -107,8 +105,12 @@ def main():
for plugin in plugins.upload.active:
plugin.upload(name, source)
for name, _ in sources:
for plugin in plugins.result.active:
plugin.result(name)
for index, (name, _) in enumerate(sources):
for plugin in plugins.location.active:
sources[index] = plugin.get_location(name)
for location in sources:
for plugin in plugins.feedback.active:
sources[index] = plugin.give_feedback(location)
sys.exit(0)

View file

@ -12,8 +12,8 @@
# You should have received a copy of the GNU General Public License along with
# SSHare. If not, see <https://www.gnu.org/licenses/>.
from ..source import File
from ..source import Raw
from sshare.plugins.source import File
from sshare.plugins.source import Raw
plugin_type = "name"

View file

@ -14,8 +14,8 @@
import time
from ..config import Argument
from ..source import File
from sshare.plugins.config import Argument
from sshare.plugins.source import File
plugin_type = "name"

View file

@ -12,9 +12,9 @@
# You should have received a copy of the GNU General Public License along with
# SSHare. If not, see <https://www.gnu.org/licenses/>.
from ..config import Argument
from ..config import NoDefault
from ..source import File
from sshare.plugins.config import Argument
from sshare.plugins.config import NoDefault
from sshare.plugins.source import File
plugin_type = "source"

View file

@ -0,0 +1,18 @@
# This file is part of SSHare.
#
# SSHare is free software: you can redistribute it and/or modify it under the terms of
# the GNU General Public License as published by the Free Software Foundation,
# either version 3 of the License, or (at your option) any later version.
#
# SSHare is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# SSHare. If not, see <https://www.gnu.org/licenses/>.
plugin_type = "feedback"
def give_feedback(location):
logger.info(f"Uploaded to '{location}'")

View file

@ -15,9 +15,9 @@
import getpass
import subprocess
from ..config import NoDefault
from ..source import File
from ..source import Raw
from sshare.plugins.config import NoDefault
from sshare.plugins.source import File
from sshare.plugins.source import Raw
plugin_type = "upload"

View file

@ -12,9 +12,9 @@
# You should have received a copy of the GNU General Public License along with
# SSHare. If not, see <https://www.gnu.org/licenses/>.
from ..config import NoDefault
from sshare.plugins.config import NoDefault
plugin_type = "result"
plugin_type = "location"
config = {
"protocol": "https",
@ -23,9 +23,9 @@ config = {
"path": "",
}
def result(name):
def get_location(name):
if config.port:
config.port = f":{config.port}"
else:
config.port = ""
logger.info(f"Uploaded to '{config.protocol}://{config.host}{config.port}{config.path}/{name}'")
return f"{config.protocol}://{config.host}{config.port}{config.path}/{name}"