2024-02-08 21:39:18 +02:00
|
|
|
import configparser
|
2024-02-09 09:14:24 +02:00
|
|
|
import argparse
|
2024-02-08 21:39:18 +02:00
|
|
|
import os
|
2024-02-09 09:14:24 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
def base_path():
|
|
|
|
my_name = sys.argv[0]
|
|
|
|
my_name_pyless, _ = os.path.splitext(my_name)
|
|
|
|
return f'/tmp/{my_name_pyless}'
|
|
|
|
|
|
|
|
def cli_args():
|
|
|
|
parser = argparse.ArgumentParser(description="Usage: python3.11 ircthing.py /myconfig.ini")
|
|
|
|
parser.add_argument('config', help="Path to the configuration file.")
|
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
if args.config:
|
|
|
|
return args.config
|
|
|
|
return None
|
2024-02-08 21:39:18 +02:00
|
|
|
|
|
|
|
def read_config(config_path):
|
|
|
|
config = configparser.ConfigParser()
|
|
|
|
config.read(config_path)
|
|
|
|
|
|
|
|
network_configs = []
|
|
|
|
|
|
|
|
try:
|
|
|
|
# Collect information from each topic / network
|
|
|
|
for topic in config.sections():
|
|
|
|
network = config[topic]
|
|
|
|
server = network.get("server")
|
|
|
|
port = network.getint("port")
|
|
|
|
channels = network.get("channels", fallback=None)
|
|
|
|
nickname = network.get("nickname")
|
|
|
|
password = network.get("password", fallback=None)
|
|
|
|
|
|
|
|
network_config = {
|
|
|
|
"net_name": network.name,
|
|
|
|
"server": server,
|
|
|
|
"port": port,
|
|
|
|
"channels": channels,
|
|
|
|
"nickname": nickname,
|
|
|
|
"password": password,
|
|
|
|
}
|
|
|
|
network_configs.append(network_config)
|
|
|
|
return network_configs
|
|
|
|
except Exception as e:
|
|
|
|
print(f"Failure while reading configuration file. {e}")
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
def make_files(path, net_name):
|
|
|
|
|
|
|
|
os.makedirs(path, exist_ok=True)
|
|
|
|
server_dir = os.path.join(path, net_name)
|
|
|
|
os.makedirs(server_dir, exist_ok=True)
|
|
|
|
try:
|
|
|
|
os.mkfifo(f"{server_dir}/in")
|
|
|
|
except FileExistsError:
|
|
|
|
pass
|
|
|
|
try:
|
|
|
|
os.mkfifo(f"{server_dir}/out")
|
|
|
|
except FileExistsError:
|
|
|
|
pass
|
|
|
|
fifo_files = []
|
|
|
|
fifo_files.append(f"{server_dir}/in")
|
|
|
|
fifo_files.append(f"{server_dir}/out")
|
2024-02-09 09:14:24 +02:00
|
|
|
return fifo_files, server_dir
|
2024-02-08 21:39:18 +02:00
|
|
|
|