From 4be8dad8236472bca72f97d479887e2a7125396c Mon Sep 17 00:00:00 2001 From: "Schimon Jehudah, Adv." Date: Wed, 20 Nov 2024 15:08:30 +0200 Subject: [PATCH] Add a prompt dialog; Automate installation process; Minor changes to HTML templates; Thank you to LeXofLeviafan. --- jabbercard/__main__.py | 73 ++++++++++++++++++- jabbercard/assets/template/conference.xhtml | 2 +- jabbercard/assets/template/disco.xhtml | 2 +- jabbercard/assets/template/download.xhtml | 2 +- jabbercard/assets/template/jid.xhtml | 2 +- jabbercard/assets/template/main.xhtml | 2 +- jabbercard/assets/template/node.xhtml | 2 +- jabbercard/assets/template/result.xhtml | 2 +- jabbercard/assets/template/software.xhtml | 2 +- jabbercard/assets/template/vcard.xhtml | 2 +- .../configs/settings.toml | 0 pyproject.toml | 2 +- 12 files changed, 80 insertions(+), 13 deletions(-) rename settings.toml => jabbercard/configs/settings.toml (100%) diff --git a/jabbercard/__main__.py b/jabbercard/__main__.py index 7a70135..6f07125 100644 --- a/jabbercard/__main__.py +++ b/jabbercard/__main__.py @@ -1,12 +1,14 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from jabbercard.config import Cache +from jabbercard.utilities.toml import Toml +from jabbercard.config import Cache, Data, Settings from jabbercard.http.instance import HttpInstance #import logging import os #from os.path import getsize, exists import re +import shutil #import time import uvicorn @@ -16,10 +18,75 @@ def main(): return http_instance.app if __name__ == 'jabbercard.__main__': + + directory = os.path.dirname(__file__) + + # Copy data files + 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): os.mkdir(directory_cache) + if not os.path.exists(directory_cache): + print(f'Creating a cache directory at {directory_cache}.') + os.mkdir(directory_cache) for subdirectory in ('details', 'photo', 'qr', 'xep_0060'): subdirectory_cache = os.path.join(directory_cache, subdirectory) - if not os.path.exists(subdirectory_cache): os.mkdir(subdirectory_cache) + 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') + data_settings = Toml.open_file_toml(file_settings) + + # Configure account + data_settings_account = data_settings['account'] + + settings_account = { + 'alias': 'Set an Alias', + '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 brand + data_settings_brand = data_settings['brand'] + + settings_brand_default = { + 'name': 'XMPP', + 'chat': 'Dino', + 'news': 'Reeder', + 'site': 'https://xmpp.org' + } + + for key in settings_brand_default: + data_settings_brand_value = data_settings_brand[key] + if not data_settings_brand_value: + settings_brand_default_value = settings_brand_default[key] + data_settings_brand_value = input(f'Set brand {key} (default: "{settings_brand_default_value}"): ') + if not data_settings_brand_value: data_settings_brand_value = settings_brand_default_value + data_settings_brand[key] = data_settings_brand_value + + Toml.save_to_toml(file_settings, data_settings) + + # Start JabberCard app = main() uvicorn.run(app, host='127.0.0.1', port=8000, reload=False) diff --git a/jabbercard/assets/template/conference.xhtml b/jabbercard/assets/template/conference.xhtml index 662c1f3..0178354 100644 --- a/jabbercard/assets/template/conference.xhtml +++ b/jabbercard/assets/template/conference.xhtml @@ -6,7 +6,7 @@ - {{brand_name}}: {{action}} {% if alias %}{{alias}}{% else %}{{title}}{% endif %} + {{action}} {% if alias %}{{alias}}{% else %}{{title}}{% endif %} ({{jid_bare}}) | {{brand_name}} diff --git a/jabbercard/assets/template/disco.xhtml b/jabbercard/assets/template/disco.xhtml index 36779a6..8331d56 100644 --- a/jabbercard/assets/template/disco.xhtml +++ b/jabbercard/assets/template/disco.xhtml @@ -6,7 +6,7 @@ - {{brand_name}}: {{action}} {{title}} + {{action}} {{title}} ({{jid_bare}}) | {{brand_name}} diff --git a/jabbercard/assets/template/download.xhtml b/jabbercard/assets/template/download.xhtml index a14c723..4a77d1b 100644 --- a/jabbercard/assets/template/download.xhtml +++ b/jabbercard/assets/template/download.xhtml @@ -6,7 +6,7 @@ - {{brand_name}}: Download + Download Clients | {{brand_name}} diff --git a/jabbercard/assets/template/jid.xhtml b/jabbercard/assets/template/jid.xhtml index 76f79ad..b23d883 100644 --- a/jabbercard/assets/template/jid.xhtml +++ b/jabbercard/assets/template/jid.xhtml @@ -6,7 +6,7 @@ - {{brand_name}}: {{action}} {% if alias %}{{alias}}{% else %}{{title}}{% endif %} + {{action}} {% if alias %}{{alias}}{% else %}{{title}}{% endif %} ({{jid_bare}}) | {{brand_name}} diff --git a/jabbercard/assets/template/main.xhtml b/jabbercard/assets/template/main.xhtml index 0368aed..b353b82 100644 --- a/jabbercard/assets/template/main.xhtml +++ b/jabbercard/assets/template/main.xhtml @@ -6,7 +6,7 @@ - {{brand_name}} : Welcome + Welcome | {{brand_name}} diff --git a/jabbercard/assets/template/node.xhtml b/jabbercard/assets/template/node.xhtml index 2859691..a319f1b 100644 --- a/jabbercard/assets/template/node.xhtml +++ b/jabbercard/assets/template/node.xhtml @@ -6,7 +6,7 @@ - {{brand_name}}: {{action}} {% if alias %}{{alias}}{% else %}{{title}}{% endif %} + Articles {% if alias %}{{alias}}{% else %}{{title}}{% endif %} ({{jid_bare}}) | {{brand_name}} diff --git a/jabbercard/assets/template/result.xhtml b/jabbercard/assets/template/result.xhtml index 185b09f..adbdcce 100644 --- a/jabbercard/assets/template/result.xhtml +++ b/jabbercard/assets/template/result.xhtml @@ -6,7 +6,7 @@ - {{brand_name}}: {{action}} {{title}} + {{action}} {{title}} | {{brand_name}} diff --git a/jabbercard/assets/template/software.xhtml b/jabbercard/assets/template/software.xhtml index 0a45fbe..743c47d 100644 --- a/jabbercard/assets/template/software.xhtml +++ b/jabbercard/assets/template/software.xhtml @@ -6,7 +6,7 @@ - {{brand_name}}: System + Operating Systems | {{brand_name}} diff --git a/jabbercard/assets/template/vcard.xhtml b/jabbercard/assets/template/vcard.xhtml index e67ce93..18996e8 100644 --- a/jabbercard/assets/template/vcard.xhtml +++ b/jabbercard/assets/template/vcard.xhtml @@ -6,7 +6,7 @@ - {{brand_name}}: {{action}} {% if alias %}{{alias}}{% else %}{{title}}{% endif %} + {{action}} {% if alias %}{{alias}}{% else %}{{title}}{% endif %} ({{jid_bare}}) | {{brand_name}} diff --git a/settings.toml b/jabbercard/configs/settings.toml similarity index 100% rename from settings.toml rename to jabbercard/configs/settings.toml diff --git a/pyproject.toml b/pyproject.toml index e69ec4b..1a8ce0f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -73,4 +73,4 @@ jabbercard = "jabbercard.__main__:main" platforms = ["any"] [tool.setuptools.package-data] -"*" = ["*.toml"] +"*" = ["*.css", "*.svg", "*.toml", "*.xhtml"]