aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2019-02-07 13:03:13 +0100
committerThomas "Cakeisalie5" Touhey <thomas@touhey.fr>2019-02-07 13:03:13 +0100
commit0b1c658563d3733d3342045d923f64334829442f (patch)
tree9625917712e7b381eef2f366d4f43d49b56421cb
parent464e337b4446f8d37a37218bb5f4a4d4f7463a5f (diff)
Added scripts.
-rw-r--r--.env.template11
-rwxr-xr-xfingerd/__init__.py71
-rwxr-xr-xfingerd/__main__.py70
-rwxr-xr-x[-rw-r--r--]fingerd/_binds.py2
-rwxr-xr-x[-rw-r--r--]fingerd/_exceptions.py0
-rwxr-xr-x[-rw-r--r--]fingerd/control/__init__.py (renamed from fingerd/client/__init__.py)2
-rwxr-xr-xfingerd/control/__main__.py16
-rwxr-xr-xscripts/fingerd15
-rwxr-xr-xscripts/fingerd-control16
-rw-r--r--setup.cfg5
10 files changed, 137 insertions, 71 deletions
diff --git a/.env.template b/.env.template
index 2d911a4..3192cf0 100644
--- a/.env.template
+++ b/.env.template
@@ -17,7 +17,7 @@ BIND=localhost:79
# - DUMMY: no users are connected.
# - NATIVE: the data is gathered from the system.
# - SCENARIO: the data is gathered from a scenario.
-# - LIVE: the data is gathered from a live source, e.g. an IPC endpoint.
+# - LIVE: the data is gathered from a live source, here a nanomsg endpoint.
#FINGER_TYPE=NATIVE
@@ -26,4 +26,13 @@ BIND=localhost:79
#FINGER_SCENARIO=actions.toml
+# For a live server receiving events, there must be an endpoint where
+# endpoints are received. This endpoint is using nanomsg's REQREP protocol,
+# so a nanomsg URI is expected, amongst:
+
+#FINGER_INCOMING=tcp://127.0.0.1:5560
+#FINGER_INCOMING=tcp://[::1]:5560
+#FINGER_INCOMING=tcp://localhost:5560
+#FINGER_INCOMING=ipc:///tmp/fingerd.sock
+
# That's it, your done with the finger server configuration! :-)
diff --git a/fingerd/__init__.py b/fingerd/__init__.py
index bcf392e..7b7c877 100755
--- a/fingerd/__init__.py
+++ b/fingerd/__init__.py
@@ -11,6 +11,12 @@
This Python module is a finger server implementation that allows you
to give out real information as well as fictional information. """
+import os.path as _path
+
+from os import environ as _environ
+from sys import stderr as _stderr
+from argparse import ArgumentParser as _ArgumentParser
+
from ._util import (ConfigurationError, BindError,
FingerUser, FingerSession, FingerFormatter,
FingerInterface, FingerLogger)
@@ -18,7 +24,7 @@ from ._fiction import (FingerFiction, FingerLiveInterface,
FingerFictionInterface)
from ._server import FingerServer
-__all__ = ["version",
+__all__ = ["run", "version",
"FingerUser", "FingerSession", "FingerFormatter",
"FingerInterface", "FingerLogger", "FingerServer", "FingerFiction",
"FingerNativeInterface", "FingerFictionInterface",
@@ -26,6 +32,10 @@ __all__ = ["version",
version = "0.1"
+# ---
+# Native interface definition.
+# ---
+
class _FingerNoNativeFoundInterface(FingerInterface):
""" Placeholder that doesn't initiate. """
@@ -40,4 +50,63 @@ except (ImportError, ModuleNotFoundError):
FingerNativeInterface = _FingerNoNativeFoundInterface
+# ---
+# Main function.
+# ---
+
+def _get_server():
+ """ Get the server through the configuration stored in the environment. """
+
+ # Load the .env file if present.
+
+ try:
+ import dotenv as _dotenv
+ _dotenv.load_dotenv()
+ except ImportError:
+ if _path.exists('.env'):
+ print("Warning: a `.env` file was found but `python-dotenv`",
+ file = _stderr)
+ print("didn't exist, consider installing it.",
+ file = _stderr)
+
+ # Load the environment variables.
+
+ bind = _environ.get('BIND', 'localhost:79')
+ host = _environ.get('FINGER_HOST', 'LOCALHOST')
+ iface = _environ.get('FINGER_TYPE', 'NATIVE').casefold()
+ scpt = _environ.get('FINGER_ACTIONS', 'actions.toml')
+ src = _environ.get('FINGER_INCOMING', '/var/run/fingerd.ipc')
+
+ if iface == 'native':
+ iface = _FingerNativeInterface()
+ elif iface in ('actions', 'scenario'):
+ fic = _FingerFiction()
+ fic.load(scpt)
+
+ iface = _FingerFictionInterface(fic)
+ elif iface == 'live':
+ iface = _FingerLiveInterface(src)
+ else:
+ if iface != 'dummy':
+ print("warning: unknown interface type, falling back on dummy",
+ file = _stderr)
+ iface = _FingerInterface()
+
+ return _FingerServer(bind = bind, host = host, interface = iface)
+
+def run():
+ """ Main function for the module. """
+
+ # Non-interactive command line interface.
+
+ ap = _ArgumentParser()
+ args = ap.parse_args()
+
+ # Get the server, run it.
+
+ server = _get_server()
+
+ server.serve_forever()
+ server.shutdown()
+
# End of file.
diff --git a/fingerd/__main__.py b/fingerd/__main__.py
index 2d8b442..97a3dbe 100755
--- a/fingerd/__main__.py
+++ b/fingerd/__main__.py
@@ -6,75 +6,11 @@
""" Main script of the module.
Runs the server depending on the configuration content. """
-import os.path as _path
-import string as _string
+from . import run as _run
-from os import environ as _environ
-from sys import stderr as _stderr
-from argparse import ArgumentParser as _ArgumentParser
-from configparser import ConfigParser as _ConfigParser
-
-from . import FingerServer as _FingerServer, \
- FingerInterface as _FingerInterface, \
- FingerFiction as _FingerFiction, \
- FingerFictionInterface as _FingerFictionInterface, \
- FingerLiveInterface as _FingerLiveInterface, \
- FingerNativeInterface as _FingerNativeInterface
-
-def get_server():
- """ Get the server through the configuration stored in the environment. """
-
- bind = _environ.get('BIND', 'localhost:79')
- host = _environ.get('FINGER_HOST', 'LOCALHOST')
- iface = _environ.get('FINGER_TYPE', 'NATIVE').casefold()
- scpt = _environ.get('FINGER_ACTIONS', 'actions.toml')
- src = _environ.get('FINGER_SOURCE', '/var/run/fingerd.ipc')
-
- if iface == 'native':
- iface = _FingerNativeInterface()
- elif iface in ('actions', 'scenario'):
- fic = _FingerFiction()
- fic.load(scpt)
-
- iface = _FingerFictionInterface(fic)
- elif iface == 'live':
- iface = _FingerLiveInterface(src)
- else:
- if iface != 'dummy':
- print("warning: unknown interface type, falling back on dummy",
- file = _stderr)
- iface = _FingerInterface()
-
- return _FingerServer(bind = bind, host = host, interface = iface)
-
-def main():
- """ Main function for the module. """
-
- # Load the .env file if present.
-
- try:
- import dotenv as _dotenv
- _dotenv.load_dotenv()
- except ImportError:
- if _path.exists('.env'):
- print("Warning: a `.env` file was found but `python-dotenv`",
- file = _stderr)
- print("didn't exist, consider installing it.",
- file = _stderr)
-
- # Non-interactive command line interface.
-
- ap = _ArgumentParser()
- args = ap.parse_args()
-
- # Get the server, run it.
-
- server = get_server()
-
- server.serve_forever()
- server.shutdown()
+__all__ = []
if __name__ == '__main__':
- main()
+ _run()
# End of file.
diff --git a/fingerd/_binds.py b/fingerd/_binds.py
index 1885ed0..5d0294b 100644..100755
--- a/fingerd/_binds.py
+++ b/fingerd/_binds.py
@@ -96,6 +96,8 @@ def _decode_tcp_host(x):
addrs = ()
addr = x
+ # TODO: manage the '*' case.
+
# Get the host part first, we'll decode it later.
if x[0] == '[':
diff --git a/fingerd/_exceptions.py b/fingerd/_exceptions.py
index 0d03e6f..0d03e6f 100644..100755
--- a/fingerd/_exceptions.py
+++ b/fingerd/_exceptions.py
diff --git a/fingerd/client/__init__.py b/fingerd/control/__init__.py
index a008005..7354054 100644..100755
--- a/fingerd/client/__init__.py
+++ b/fingerd/control/__init__.py
@@ -3,7 +3,7 @@
# Copyright (C) 2017-2019 Thomas Touhey <thomas@touhey.fr>
# This file is part of the fingerd Python 3.x module, which is MIT-licensed.
#******************************************************************************
-""" The `fingerd.client` submodule is a module for adding actions to the
+""" The `fingerd.control` submodule is a module for adding actions to the
fingerd live interface. """
__all__ = ["FingerLiveClient", "DELETE"]
diff --git a/fingerd/control/__main__.py b/fingerd/control/__main__.py
new file mode 100755
index 0000000..59a113a
--- /dev/null
+++ b/fingerd/control/__main__.py
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+#******************************************************************************
+# Copyright (C) 2017-2019 Thomas Touhey <thomas@touhey.fr>
+# This file is part of the fingerd Python 3.x module, which is MIT-licensed.
+#******************************************************************************
+""" Main script of the control client module.
+ Runs the client depending on the configuration content. """
+
+from . import run as _run
+
+__all__ = []
+
+if __name__ == '__main__':
+ _run()
+
+# End of file.
diff --git a/scripts/fingerd b/scripts/fingerd
new file mode 100755
index 0000000..5a6c3f9
--- /dev/null
+++ b/scripts/fingerd
@@ -0,0 +1,15 @@
+#!/usr/bin/env python3
+#******************************************************************************
+# Copyright (C) 2017-2019 Thomas Touhey <thomas@touhey.fr>
+# This file is part of the fingerd Python 3.x module, which is MIT-licensed.
+#******************************************************************************
+""" Run fingerd without calling the `fingerd` module directly. """
+
+from fingerd import run as _run
+
+__all__ = []
+
+if __name__ == '__main__':
+ _run()
+
+# End of file.
diff --git a/scripts/fingerd-control b/scripts/fingerd-control
new file mode 100755
index 0000000..39ac2b8
--- /dev/null
+++ b/scripts/fingerd-control
@@ -0,0 +1,16 @@
+#!/usr/bin/env python3
+#******************************************************************************
+# Copyright (C) 2017-2019 Thomas Touhey <thomas@touhey.fr>
+# This file is part of the fingerd Python 3.x module, which is MIT-licensed.
+#******************************************************************************
+""" Run the fingerd control client without calling the `fingerd.control`
+ module directly. """
+
+from fingerd.control import run as _run
+
+__all__ = []
+
+if __name__ == '__main__':
+ _run()
+
+# End of file.
diff --git a/setup.cfg b/setup.cfg
index 07c2894..7771fdb 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -20,7 +20,10 @@ classifiers =
[options]
zip_safe = False
include_package_data = True
-packages = fingerd
+packages = fingerd, fingerd.control
+scripts =
+ scripts/textout2html
+ scripts/textout2ls
install_requires =
toml