import configparser import argparse import os 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 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") return fifo_files, server_dir