2024-11-17 16:30:38 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2024-11-20 14:08:30 +01:00
|
|
|
from jabbercard.utilities.toml import Toml
|
|
|
|
from jabbercard.config import Cache, Data, Settings
|
2024-11-17 16:30:38 +01:00
|
|
|
from jabbercard.http.instance import HttpInstance
|
|
|
|
#import logging
|
|
|
|
import os
|
|
|
|
#from os.path import getsize, exists
|
|
|
|
import re
|
2024-11-20 14:08:30 +01:00
|
|
|
import shutil
|
2024-11-17 16:30:38 +01:00
|
|
|
#import time
|
|
|
|
import uvicorn
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
|
|
|
http_instance = HttpInstance()
|
|
|
|
return http_instance.app
|
|
|
|
|
|
|
|
if __name__ == 'jabbercard.__main__':
|
2024-11-20 14:08:30 +01:00
|
|
|
|
|
|
|
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
|
2024-11-17 16:30:38 +01:00
|
|
|
directory_cache = Cache.get_directory()
|
2024-11-20 14:08:30 +01:00
|
|
|
if not os.path.exists(directory_cache):
|
|
|
|
print(f'Creating a cache directory at {directory_cache}.')
|
|
|
|
os.mkdir(directory_cache)
|
2024-11-17 16:30:38 +01:00
|
|
|
for subdirectory in ('details', 'photo', 'qr', 'xep_0060'):
|
|
|
|
subdirectory_cache = os.path.join(directory_cache, subdirectory)
|
2024-11-20 14:08:30 +01:00
|
|
|
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
|
2024-11-17 16:30:38 +01:00
|
|
|
app = main()
|
|
|
|
uvicorn.run(app, host='127.0.0.1', port=8000, reload=False)
|