Compare commits

..

2 commits

5 changed files with 49 additions and 12 deletions

View file

@ -18,15 +18,12 @@ from sshare.plugin import Plugin
class Logger: class Logger:
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if kwargs.get("command_line"): self._loggers = []
self._loggers = [ kwargs["command_line"] ]
else:
self._loggers = []
self.add(*args) self.add(*args)
def add(self, *args, **kwargs): def add(self, *args, **kwargs):
for logger in args: for logger in args:
self._loggers.append() self._loggers.append(logger)
def info(self, message): def info(self, message):
for logger in self._loggers: for logger in self._loggers:

View file

@ -67,9 +67,10 @@ def main():
config["config"], config["config"],
config["flags"], config["flags"],
) )
logger = Logger(command_line=command_line) logger = Logger(command_line)
plugin_types = [ "logger", "source", "name", "upload", "location", "feedback" ]
plugins = PluginManager( plugins = PluginManager(
[ "logger", "source", "name", "upload", "location", "feedback" ], plugin_types,
logger, logger,
config["config"], config["config"],
config["flags"], config["flags"],
@ -78,6 +79,7 @@ def main():
plugins.add_from( plugins.add_from(
Plugin.internal(INTERNAL_PLUGIN_LOCATION), Plugin.internal(INTERNAL_PLUGIN_LOCATION),
"file", "file",
"stdin",
"current_time", "current_time",
"append_type", "append_type",
"ssh", "ssh",
@ -99,6 +101,16 @@ def main():
logger.add(*plugins.logger.active) logger.add(*plugins.logger.active)
plugins.activate() plugins.activate()
for plugin_type in [ "source", "name", "upload" ]:
plugins_of_type = getattr(plugins, plugin_type)
if len(plugins_of_type.active) == 0:
logger.error(f"Error: No '{plugin_type}' plugins activated. Available plugins:")
for plugin in plugins_of_type.inactive:
logger.error(f" => {plugin.name}")
sys.exit(1)
if len(plugins.location.active) == 0 and len(plugins.feedback.active) > 0:
logger.warn("Warning: 'feedback' plugins activated with no active 'location' plugins")
sources = [] sources = []
for plugin in plugins.source.active: for plugin in plugins.source.active:
sources.append(plugin.get_source()) sources.append(plugin.get_source())

View file

@ -75,8 +75,8 @@ class Argument:
def add(self, arg_parser): def add(self, arg_parser):
flags = [] flags = []
if self._short: flags.append(f"-{self._short}") if self._short != None: flags.append(f"-{self._short}")
if self._long: flags.append(f"--{self._long}") if self._long != None: flags.append(f"--{self._long}")
kwargs = self._kwargs | { kwargs = self._kwargs | {
"dest": self.dest() "dest": self.dest()
} }

View file

@ -22,9 +22,6 @@ plugin_type = "name"
config = { config = {
"base": 62, "base": 62,
} }
args = {
"base": Argument(help="Set the numeric base to use for the current time"),
}
def init(): def init():
if not isinstance(config.base, int): if not isinstance(config.base, int):

View file

@ -0,0 +1,31 @@
# 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/>.
import sys
from sshare.plugins.config import Flag
from sshare.plugins.source import Raw
plugin_type = "source"
activate = { "stdin" }
config = {
"suffix": "txt"
}
args = {
"stdin": Flag(help="Upload from stdin")
}
def get_source():
return Raw(config.suffix, sys.stdin.buffer.read())