| 47 | |
| 48 | |
| 49 | class DataModel: |
| 50 | def __init__(self, profile): |
| 51 | self.profile = profile |
| 52 | |
| 53 | self.yaml = YAML() |
| 54 | self.config = None |
| 55 | self.modules: Dict[str, Module] = {} |
| 56 | |
| 57 | @staticmethod |
| 58 | def default_config(): |
| 59 | # TRANSLATORS: This part of text must be formatted in a monospaced font, and all lines must not exceed the width of a 70-cell-wide terminal. |
| 60 | config = _( |
| 61 | "# ===================================\n" |
| 62 | "# EH Forwarder Bot Configuration File\n" |
| 63 | "# ===================================\n" |
| 64 | "# \n" |
| 65 | "# This file determines what modules, including master channel, slave channels,\n" |
| 66 | "# and middlewares, are enabled in this profile.\n" |
| 67 | "# \n" |
| 68 | "# \n" |
| 69 | "# Master Channel\n" |
| 70 | "# --------------\n" |
| 71 | "# Exactly one instance of a master channel is required for a profile.\n" |
| 72 | "# Fill in the module ID and instance ID (if needed) below.\n" |
| 73 | ) |
| 74 | config += "\nmaster_channel:\n\n" |
| 75 | # TRANSLATORS: This part of text must be formatted in a monospaced font, and all lines must not exceed the width of a 70-cell-wide terminal. |
| 76 | config += _( |
| 77 | "# Slave Channels\n" |
| 78 | "# --------------\n" |
| 79 | "# \n" |
| 80 | "# At least one slave channel is required for a profile.\n" |
| 81 | "# Fill in the module ID and instance ID (if needed) of each slave channel\n" |
| 82 | "# to be enabled below.\n" |
| 83 | ) |
| 84 | config += "\nslave_channels: []\n\n" |
| 85 | # TRANSLATORS: This part of text must be formatted in a monospaced font, and all lines must not exceed the width of a 70-cell-wide terminal. |
| 86 | config += _( |
| 87 | "# Middlewares\n" |
| 88 | "# -----------\n" |
| 89 | "# Middlewares are not required to run an EFB profile. If you are not\n" |
| 90 | "# going to use any middleware in this profile, you can safely remove\n" |
| 91 | "# this section. Otherwise, please list down the module ID and instance\n" |
| 92 | "# ID of each middleware to be enabled below.\n" |
| 93 | ) |
| 94 | config += "middlewares: []\n" |
| 95 | |
| 96 | str_io = StringIO(config) |
| 97 | str_io.seek(0) |
| 98 | return str_io |
| 99 | |
| 100 | def load_config(self): |
| 101 | coordinator.profile = self.profile |
| 102 | conf_path = utils.get_config_path() |
| 103 | if not os.path.exists(conf_path): |
| 104 | self.config = self.yaml.load(self.default_config()) |
| 105 | else: |
| 106 | with open(conf_path) as f: |