Compare commits
2 commits
349a9cbd0e
...
12dbe87134
Author | SHA1 | Date | |
---|---|---|---|
12dbe87134 | |||
fb79537707 |
5 changed files with 49 additions and 12 deletions
|
@ -18,15 +18,12 @@ from sshare.plugin import Plugin
|
|||
|
||||
class Logger:
|
||||
def __init__(self, *args, **kwargs):
|
||||
if kwargs.get("command_line"):
|
||||
self._loggers = [ kwargs["command_line"] ]
|
||||
else:
|
||||
self._loggers = []
|
||||
self._loggers = []
|
||||
self.add(*args)
|
||||
|
||||
def add(self, *args, **kwargs):
|
||||
for logger in args:
|
||||
self._loggers.append()
|
||||
self._loggers.append(logger)
|
||||
|
||||
def info(self, message):
|
||||
for logger in self._loggers:
|
||||
|
|
|
@ -67,9 +67,10 @@ def main():
|
|||
config["config"],
|
||||
config["flags"],
|
||||
)
|
||||
logger = Logger(command_line=command_line)
|
||||
logger = Logger(command_line)
|
||||
plugin_types = [ "logger", "source", "name", "upload", "location", "feedback" ]
|
||||
plugins = PluginManager(
|
||||
[ "logger", "source", "name", "upload", "location", "feedback" ],
|
||||
plugin_types,
|
||||
logger,
|
||||
config["config"],
|
||||
config["flags"],
|
||||
|
@ -78,6 +79,7 @@ def main():
|
|||
plugins.add_from(
|
||||
Plugin.internal(INTERNAL_PLUGIN_LOCATION),
|
||||
"file",
|
||||
"stdin",
|
||||
"current_time",
|
||||
"append_type",
|
||||
"ssh",
|
||||
|
@ -99,6 +101,16 @@ def main():
|
|||
logger.add(*plugins.logger.active)
|
||||
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 = []
|
||||
for plugin in plugins.source.active:
|
||||
sources.append(plugin.get_source())
|
||||
|
|
|
@ -75,8 +75,8 @@ class Argument:
|
|||
|
||||
def add(self, arg_parser):
|
||||
flags = []
|
||||
if self._short: flags.append(f"-{self._short}")
|
||||
if self._long: flags.append(f"--{self._long}")
|
||||
if self._short != None: flags.append(f"-{self._short}")
|
||||
if self._long != None: flags.append(f"--{self._long}")
|
||||
kwargs = self._kwargs | {
|
||||
"dest": self.dest()
|
||||
}
|
||||
|
|
|
@ -22,9 +22,6 @@ plugin_type = "name"
|
|||
config = {
|
||||
"base": 62,
|
||||
}
|
||||
args = {
|
||||
"base": Argument(help="Set the numeric base to use for the current time"),
|
||||
}
|
||||
|
||||
def init():
|
||||
if not isinstance(config.base, int):
|
||||
|
|
31
src/sshare/plugins/default/stdin.py
Normal file
31
src/sshare/plugins/default/stdin.py
Normal 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())
|
Loading…
Reference in a new issue