Automate installation process;

Add command line prompt to set configurations;
Update document README.
This commit is contained in:
Schimon Jehudah, Adv. 2024-11-20 17:21:26 +02:00
parent 2cdba527f6
commit 5fd6a6c710
8 changed files with 136 additions and 22 deletions

View file

@ -15,8 +15,9 @@ PubSub nodes into static XHTML journal sites.
Rivista was inspired from Tigase and was motivated by Movim.
## Home site
- https://schapps.woodpeckersnest.eu/rivista/
- gemini://woodpeckersnest.space/~schapps/rivista.gmi
- https://schapps.woodpeckersnest.eu/rivista/
## Instances
@ -92,23 +93,14 @@ $ pipx uninstall rivista
$ pipx install git+https://git.xmpp-it.net/sch/Rivista
```
### Configure
Add account credentials to file `settings.toml`.
Copy file`settings.toml` to `~/.config/rivista/`.
Copy directories `css`, `graphics`, `img`, `script`, and `xsl` to
`~/.local/share/rivista/`.
Copy directory `json` to `~/.cache/rivista/`.
### Start
```
$ rivista
```
Open URL http://localhost:8000
## Usage
It is possible to view a complete node and even a single item, which means, that

View file

@ -37,6 +37,7 @@ keywords = [
dependencies = [
"beautifulsoup4",
"fastapi",
"gmcapsule",
"lxml",
"markdown",
# "markdown-text-clean",
@ -59,4 +60,4 @@ rivista = "rivista.__main__:main"
platforms = ["any"]
[tool.setuptools.package-data]
"*" = ["*.toml"]
"*" = ["*.css", "*.js", "*.ico", "*.png", "*.svg", "*.toml", "*.xsl"]

View file

@ -3,12 +3,112 @@
#import importlib.resources
import os
from rivista.config import Cache, Data, Settings
from rivista.utilities import Toml
from rivista.http.instance import HttpInstance
import shutil
import uvicorn
def main():
http_instance = HttpInstance()
return http_instance.app
app = main()
uvicorn.run(app, host='localhost', port=8000, reload=False)
if __name__ == 'rivista.__main__':
directory = os.path.dirname(__file__)
# Copy data files
# FIXME File settins.toml is copied too.
directory_data = Data.get_directory()
if not os.path.exists(directory_data):
directory_assets = os.path.join(directory, 'assets')
directory_assets_new = shutil.copytree(directory_assets, directory_data)
print(f'Data directory {directory_assets_new} has been created and populated.')
# Copy settings files
directory_settings = Settings.get_directory()
if not os.path.exists(directory_settings):
directory_configs = os.path.join(directory, 'configs')
directory_settings_new = shutil.copytree(directory_configs, directory_settings)
print(f'Settings directory {directory_settings_new} has been created and populated.')
# Create cache directories
directory_cache = Cache.get_directory()
if not os.path.exists(directory_cache):
print(f'Creating a cache directory at {directory_cache}.')
os.mkdir(directory_cache)
# TODO Add more cache directories (see JabberCard).
# TODO Remove json (indices is the new name)
for subdirectory in ('json', 'indices', 'pubsub'):
subdirectory_cache = os.path.join(directory_cache, subdirectory)
if not os.path.exists(subdirectory_cache):
print(f'Creating a cache subdirectory at {subdirectory_cache}.')
os.mkdir(subdirectory_cache)
# Configure settings file
file_settings = os.path.join(directory_settings, 'settings.toml')
if not os.path.exists(file_settings):
directory_configs = os.path.join(directory, 'configs')
file_settings_empty = os.path.join(directory_configs, 'settings.toml')
shutil.copyfile(file_settings_empty, file_settings)
data_settings = Toml.open_file_toml(file_settings)
# Configure account
data_settings_account = data_settings['account']
settings_account = {
'xmpp': 'Set a Jabber ID',
'pass': 'Input Password'
}
for key in settings_account:
data_settings_account_value = data_settings_account[key]
if not data_settings_account_value:
settings_account_message = settings_account[key]
while not data_settings_account_value:
data_settings_account_value = input(f'{settings_account_message}: ')
data_settings_account[key] = data_settings_account_value
# Configure default PubSub Service and Node Name
data_settings_default = data_settings['default']
settings_default_default = {
'pubsub': 'pubsub.woodpeckersnest.space',
'nodeid': 'PlanetJabber'
}
for key in settings_default_default:
data_settings_default_value = data_settings_default[key]
if not data_settings_default_value:
settings_default_default_value = settings_default_default[key]
data_settings_default_value = input(f'Set brand {key} (default: "{settings_default_default_value}"): ')
if not data_settings_default_value: data_settings_default_value = settings_default_default_value
data_settings_default[key] = data_settings_default_value
# Configure Settings
data_settings_settings = data_settings['settings']
data_settings_settings_service = data_settings_settings['service']
if data_settings_settings_service is '':
while data_settings_settings_service not in ('n', 'N', 'no', 'No', 'y', 'Y', 'yes', 'Yes'):
data_settings_settings_service = input(f'Run as service? [Y/n] ')
if data_settings_settings_service in ('y', 'Y', 'yes', 'Yes'):
data_settings_settings['service'] = 1
else:
data_settings_settings['service'] = 0
data_settings_settings_include = data_settings_settings['include']
if data_settings_settings_include is '':
data_settings_settings_include = input(f'Limit service to included domains? (comma separated. remain empty for no limit) ')
data_settings_settings['include'] = data_settings_settings_include if data_settings_settings_include else 0
data_settings_settings_operator = data_settings_settings['operator']
if data_settings_settings_operator is '':
data_settings_settings['operator'] = input(f'Set a Jabber ID of an operator to contact with: ')
Toml.save_to_toml(file_settings, data_settings)
# Start JabberCard
app = main()
uvicorn.run(app, host='localhost', port=8000, reload=False)

View file

@ -1 +0,0 @@
This directory caches lists of PubSub nodes.

View file

@ -239,7 +239,7 @@ window.onload = async function(){
elementDiv.appendChild(elementP2);
let elementSpan = document.createElement('span');
elementSpan.id = 'return';
elementSpan.textContent = 'Return';
elementSpan.textContent = 'Continue Reading';
elementSpan.addEventListener ('click', function() {
document.querySelector('#selection-page').remove();
});

View file

@ -5,11 +5,11 @@ pass = "" # Password.
# A default node, when no arguments are set.
[default]
pubsub = "pubsub.woodpeckersnest.space" # Jabber ID.
nodeid = "PlanetJabber" # Node ID.
pubsub = "" # Jabber ID.
nodeid = "" # Node ID.
# Settings
[settings]
service = 1 # Enable server as a service.
service = "" # Enable server as a service.
include = "" # Limit service to a given domain.
operator = "" # A Jabber ID to contact with, in case of an error.

22
rivista/utilities.py Normal file
View file

@ -0,0 +1,22 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
import tomli_w
try:
import tomllib
except:
import tomli as tomllib
class Toml:
def open_file_toml(filename: str) -> dict:
with open(filename, mode="rb") as fn:
data = tomllib.load(fn)
return data
def save_to_toml(filename: str, data: dict) -> None:
with open(filename, 'w') as fn:
data_as_string = tomli_w.dumps(data)
fn.write(data_as_string)

View file

@ -1,2 +1,2 @@
__version__ = '1.0'
__version_info__ = (1, 0)
__version__ = '0.1'
__version_info__ = (0, 1)