Initialize the variables.
(self)
| 1121 | else: |
| 1122 | logger.warning("Could not add local MAC to blacklist: MAC address not found") |
| 1123 | |
| 1124 | |
| 1125 | |
| 1126 | def get_raspberry_mac(self): |
| 1127 | """Get the MAC address of the primary network interface (usually wlan0 or eth0).""" |
| 1128 | try: |
| 1129 | # First try wlan0 (wireless interface) |
| 1130 | result = subprocess.run(['cat', '/sys/class/net/wlan0/address'], |
| 1131 | capture_output=True, text=True) |
| 1132 | if result.returncode == 0 and result.stdout.strip(): |
| 1133 | return result.stdout.strip().lower() |
| 1134 | |
| 1135 | # If wlan0 fails, try eth0 (ethernet interface) |
| 1136 | result = subprocess.run(['cat', '/sys/class/net/eth0/address'], |
| 1137 | capture_output=True, text=True) |
| 1138 | if result.returncode == 0 and result.stdout.strip(): |
| 1139 | return result.stdout.strip().lower() |
| 1140 | |
| 1141 | logger.warning("Could not find MAC address for wlan0 or eth0") |
| 1142 | return None |
| 1143 | |
| 1144 | except Exception as e: |
| 1145 | logger.error(f"Error getting Raspberry Pi MAC address: {e}") |
| 1146 | return None |
| 1147 | |
| 1148 | |
| 1149 | |
| 1150 | def setup_environment(self, clear_console=False): |
| 1151 | """Setup the environment with the necessary directories and files.""" |
| 1152 | if clear_console: |
| 1153 | os.system('cls' if os.name == 'nt' else 'clear') |
| 1154 | self.create_directories() # Create all necessary directories first |
| 1155 | self.save_config() |
| 1156 | if self._pager_mode: |
| 1157 | # On Pager: try to regenerate actions.json (works if deps are available), |
| 1158 | # fall back to loading existing file if generation fails. |
| 1159 | if not os.path.exists(self.actions_file): |
| 1160 | try: |
| 1161 | self.generate_actions_json() |
| 1162 | except Exception as e: |
| 1163 | logger.warning(f"Could not generate actions.json: {e}") |
| 1164 | self._load_status_list_from_actions_json() |
| 1165 | else: |
| 1166 | # Skip costly re-import of every action module if actions.json |
| 1167 | # is already up to date (same set of .py files in actions/). |
| 1168 | self._generate_actions_json_if_needed() |
| 1169 | self.delete_webconsolelog() |
| 1170 | self.initialize_csv() |
| 1171 | self.initialize_epd_display() |
| 1172 | |
| 1173 | def create_directories(self): |
| 1174 | """Create all necessary directories for the application.""" |
| 1175 | directories_to_create = [ |
| 1176 | self.configdir, |
| 1177 | self.datadir, |
| 1178 | self.actions_dir, |
| 1179 | self.webdir, |
| 1180 | self.resourcesdir, |
no test coverage detected