Compare commits
No commits in common. "c02f713ad2462c174239b6ef9dc31b31069d89d4" and "fda30e7f9ed232d7a448a5456c07b27c10c5007a" have entirely different histories.
c02f713ad2
...
fda30e7f9e
@ -29,25 +29,6 @@ class BBSArgumentParser(argparse.ArgumentParser):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class SortedHelpFormatter(argparse.HelpFormatter):
|
|
||||||
def _iter_indented_subactions(self, action):
|
|
||||||
try:
|
|
||||||
get_subactions = action._get_subactions
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self._indent()
|
|
||||||
if isinstance(action, argparse._SubParsersAction):
|
|
||||||
for subaction in sorted(
|
|
||||||
get_subactions(),
|
|
||||||
key=lambda x: x.dest):
|
|
||||||
yield subaction
|
|
||||||
else:
|
|
||||||
for subaction in get_subactions():
|
|
||||||
yield subaction
|
|
||||||
self._dedent()
|
|
||||||
|
|
||||||
|
|
||||||
class Parser(BBSArgumentParser):
|
class Parser(BBSArgumentParser):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -62,15 +43,12 @@ class Parser(BBSArgumentParser):
|
|||||||
return getattr(self.parser, attr)
|
return getattr(self.parser, attr)
|
||||||
|
|
||||||
def _init_parser(self):
|
def _init_parser(self):
|
||||||
self.sort_actions = True
|
|
||||||
|
|
||||||
# Root parser for BBS commands
|
# Root parser for BBS commands
|
||||||
self.parser = BBSArgumentParser(
|
self.parser = BBSArgumentParser(
|
||||||
description='BBS Main Menu',
|
description='BBS Main Menu',
|
||||||
prog='',
|
prog='',
|
||||||
add_help=False,
|
add_help=False,
|
||||||
usage=argparse.SUPPRESS,
|
usage=argparse.SUPPRESS,
|
||||||
formatter_class=SortedHelpFormatter,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# We will create a subparser for each individual command
|
# We will create a subparser for each individual command
|
||||||
|
|||||||
@ -1,65 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
#
|
|
||||||
# Really Simple BBS - a really simple BBS for ax.25 packet radio.
|
|
||||||
# Copyright (C) 2023 John Burwell <john@atatdotdot.com>
|
|
||||||
#
|
|
||||||
# This program 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.
|
|
||||||
#
|
|
||||||
# This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
import logging
|
|
||||||
import sqlalchemy
|
|
||||||
import sqlalchemy.orm
|
|
||||||
import subprocess
|
|
||||||
|
|
||||||
from rsbbs import __version__
|
|
||||||
from rsbbs import Console, Parser
|
|
||||||
from rsbbs.models import Message
|
|
||||||
|
|
||||||
|
|
||||||
class Plugin():
|
|
||||||
|
|
||||||
def __init__(self, api: Console) -> None:
|
|
||||||
self.api = api
|
|
||||||
self.init_parser(api.parser)
|
|
||||||
logging.info(f"Plugin {__name__} loaded")
|
|
||||||
|
|
||||||
def init_parser(self, parser: Parser) -> None:
|
|
||||||
subparser = parser.subparsers.add_parser(
|
|
||||||
name='stats',
|
|
||||||
aliases=['st'],
|
|
||||||
help='Report some statistics about this BBS.')
|
|
||||||
subparser.set_defaults(func=self.run)
|
|
||||||
|
|
||||||
def get_message_count(self) -> int:
|
|
||||||
with self.api.controller.session() as session:
|
|
||||||
try:
|
|
||||||
count = session.execute(sqlalchemy.select(
|
|
||||||
sqlalchemy.func.count(Message.id))).scalar_one()
|
|
||||||
return int(count)
|
|
||||||
except Exception as e:
|
|
||||||
logging.error(e)
|
|
||||||
|
|
||||||
def get_uptime(self) -> str:
|
|
||||||
result = subprocess.run(
|
|
||||||
['uptime'], capture_output=True, text=True)
|
|
||||||
return result.stdout
|
|
||||||
|
|
||||||
def run(self, args) -> None:
|
|
||||||
"""Show some stats."""
|
|
||||||
response = []
|
|
||||||
response.append(f"[RSBBS-{__version__}] listening on "
|
|
||||||
f"{self.api.config.callsign} ")
|
|
||||||
response.append(f"Messages: {self.get_message_count()}")
|
|
||||||
response.append(f"Uptime: {self.get_uptime()}")
|
|
||||||
self.api.write_output('\r\n'.join(response))
|
|
||||||
logging.info(f"report stats")
|
|
||||||
Loading…
Reference in New Issue
Block a user