4be8dad823
Automate installation process; Minor changes to HTML templates; Thank you to LeXofLeviafan.
92 lines
3.3 KiB
Python
92 lines
3.3 KiB
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
|
|
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
|
|
|
|
def main():
|
|
|
|
http_instance = HttpInstance()
|
|
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):
|
|
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):
|
|
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)
|