Skip to content

Commit

Permalink
refactor(CONFIG): standardize, add fields
Browse files Browse the repository at this point in the history
  • Loading branch information
niall-byrne committed Dec 8, 2023
1 parent a2f26c5 commit f96f5e9
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion pi_portal/commands/tests/test_upload_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_invoke(self, m_module: mock.Mock) -> None:
m_move.assert_called_once_with(
self.mock_file,
os.path.join(
config.VIDEO_UPLOAD_QUEUE_PATH,
config.PATH_VIDEO_UPLOAD_QUEUE,
os.path.basename(self.mock_file),
)
)
2 changes: 1 addition & 1 deletion pi_portal/commands/upload_video.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ def invoke(self) -> None:
shutil.move(
self.file_name,
os.path.join(
config.VIDEO_UPLOAD_QUEUE_PATH, os.path.basename(self.file_name)
config.PATH_VIDEO_UPLOAD_QUEUE, os.path.basename(self.file_name)
)
)
30 changes: 22 additions & 8 deletions pi_portal/config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
"""Core configuration settings."""

DOOR_MONITOR_LOGFILE_PATH = "/var/log/pi_portal.door.log"
MOTION_FOLDER = "/var/lib/motion"
SLACK_BOT_LOGFILE_PATH = "/var/log/pi_portal.slack_bot.log"
SLACK_CLIENT_LOGFILE_PATH = "/var/log/pi_portal.slack_client.log"
SUPERVISOR_SOCKET_PATH = "/var/run/supervisor.sock"
TEMPERATURE_MONITOR_LOGFILE_PATH = "/var/log/pi_portal.temperature.log"
VIDEO_UPLOAD_QUEUE_PATH = "/opt/pi_portal/queue_videos"
VIDEO_UPLOAD_QUEUE_LOGFILE_PATH = "/var/log/pi_portal.video_queue.log"
FILE_BEAT_BINARY = "/usr/bin/filebeat"
FILE_BEAT_CONFIG = "/etc/filebeat/filebeat.yml"

LOG_FILE_DOOR_MONITOR = "/var/log/pi_portal.door.log"
LOG_FILE_MOTION = "/var/log/pi_portal.motion.log"
LOG_FILE_SLACK_BOT = "/var/log/pi_portal.slack_bot.log"
LOG_FILE_SLACK_CLIENT = "/var/log/pi_portal.slack_client.log"
LOG_FILE_TEMPERATURE_MONITOR = "/var/log/pi_portal.temperature.log"
LOG_FILE_VIDEO_UPLOAD_CRON = "/var/log/pi_portal.video_upload_cron.log"

LOG_PREFIX_SUPERVISOR = "/var/log/supervisor/supervisor"

PATH_MOTION_CONTENT = "/var/lib/motion"
PATH_SUPERVISOR_SOCKET = "/var/run/supervisor.sock"
PATH_VIDEO_UPLOAD_QUEUE = "/opt/pi_portal/queue_videos"
PATH_USER_CONFIG_INSTALL = "/opt/venvs/pi_portal/config.json"

PID_FILE_MOTION = '/var/run/motion/motion.pid'
PID_FILE_SUPERVISORD = '/var/run/supervisord.pid'

PI_PORTAL_SHIM = "/usr/bin/portal"
PI_PORTAL_USER = "pi-portal"
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class DoorMonitor(monitor.GPIOMonitorBase[contact_switch.ContactSwitch]):
gpio_poll_interval = 0.5
gpio_log_changes_only = True
logger_name = "pi_portal_door"
log_file_path = config.DOOR_MONITOR_LOGFILE_PATH
log_file_path = config.LOG_FILE_DOOR_MONITOR
open = DoorState["OPENED"].value

def hook_log_state(self, gpio_pin: contact_switch.ContactSwitch) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TemperatureSensorMonitor(
gpio_poll_interval = 60.0
gpio_log_changes_only = False
logger_name = "pi_portal_temperature"
log_file_path = config.TEMPERATURE_MONITOR_LOGFILE_PATH
log_file_path = config.LOG_FILE_TEMPERATURE_MONITOR

def __init__(
self, gpio_pins: Sequence[temperature_sensor.TemperatureSensor]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class TemperatureMonitorLogFileReader(read_log_file.LogFileReader):
"""Read access to the Temperature Monitor Log File."""

configured_sensor_count: int
log_file_path: str = config.TEMPERATURE_MONITOR_LOGFILE_PATH
log_file_path: str = config.LOG_FILE_TEMPERATURE_MONITOR
temperature_readings: Dict[str, TemperatureReadingType]

def __init__(self) -> None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def test_initialization__one_sensor(
one_sensor_temp_log_file_reader: TemperatureMonitorLogFileReader,
) -> None:
assert one_sensor_temp_log_file_reader.log_file_path == \
config.TEMPERATURE_MONITOR_LOGFILE_PATH
config.LOG_FILE_TEMPERATURE_MONITOR
assert one_sensor_temp_log_file_reader.state.user_config == \
mocked_state.user_config
assert one_sensor_temp_log_file_reader.configured_sensor_count == 1
Expand All @@ -80,7 +80,7 @@ def test_initialization__two_sensors(
two_sensor_temp_log_file_reader: TemperatureMonitorLogFileReader,
) -> None:
assert two_sensor_temp_log_file_reader.log_file_path == \
config.TEMPERATURE_MONITOR_LOGFILE_PATH
config.LOG_FILE_TEMPERATURE_MONITOR
assert two_sensor_temp_log_file_reader.state.user_config == \
mocked_state.user_config
assert two_sensor_temp_log_file_reader.configured_sensor_count == 2
Expand Down
4 changes: 2 additions & 2 deletions pi_portal/modules/integrations/motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Motion:
"""Integration with the Motion application."""

snapshot_url = 'http://localhost:8080/0/action/snapshot'
snapshot_fname = os.path.join(config.MOTION_FOLDER, 'lastsnap.jpg')
video_glob_pattern = os.path.join(config.MOTION_FOLDER, '/*.mp4')
snapshot_fname = os.path.join(config.PATH_MOTION_CONTENT, 'lastsnap.jpg')
video_glob_pattern = os.path.join(config.PATH_MOTION_CONTENT, '/*.mp4')
snapshot_retries = 10
s3_retries = 3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ def test__initialization__attrs(
self,
video_upload_queue_instance: video_upload_cron.VideoUploadCron,
) -> None:
assert video_upload_queue_instance.path == config.VIDEO_UPLOAD_QUEUE_PATH
assert video_upload_queue_instance.path == config.PATH_VIDEO_UPLOAD_QUEUE
assert video_upload_queue_instance.log_file_path == \
config.VIDEO_UPLOAD_QUEUE_LOGFILE_PATH
config.LOG_FILE_VIDEO_UPLOAD_CRON
assert video_upload_queue_instance.logger_name == "video_upload_cron"

def test__initialization__inheritance(
Expand Down
4 changes: 2 additions & 2 deletions pi_portal/modules/integrations/s3/video_upload_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ class VideoUploadCron(cron.S3UploadCronJobBase):
:param interval: The interval in seconds to check for new files.
"""

path = config.VIDEO_UPLOAD_QUEUE_PATH
log_file_path = config.VIDEO_UPLOAD_QUEUE_LOGFILE_PATH
path = config.PATH_VIDEO_UPLOAD_QUEUE
log_file_path = config.LOG_FILE_VIDEO_UPLOAD_CRON
logger_name = "video_upload_cron"
2 changes: 1 addition & 1 deletion pi_portal/modules/integrations/slack/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SlackBot(write_log_file.LogFileWriter):
"""Slack bot."""

logger_name = "bot"
log_file_path = config.SLACK_BOT_LOGFILE_PATH
log_file_path = config.LOG_FILE_SLACK_BOT
web_socket: SocketModeHandler

def __init__(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pi_portal/modules/integrations/slack/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class SlackClient(write_log_file.LogFileWriter):
"""Slack messaging client."""

logger_name = "client"
log_file_path = config.SLACK_CLIENT_LOGFILE_PATH
log_file_path = config.LOG_FILE_SLACK_CLIENT
retries = 5

def __init__(self) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pi_portal/modules/integrations/tests/test_motion.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_initialization(self) -> None:
self.assertEqual(motion_client.s3_retries, 3)
self.assertEqual(
motion_client.video_glob_pattern,
os.path.join(config.MOTION_FOLDER, '/*.mp4')
os.path.join(config.PATH_MOTION_CONTENT, '/*.mp4')
)
self.assertIsInstance(motion_client.s3_client, client.S3BucketClient)

Expand Down
2 changes: 1 addition & 1 deletion pi_portal/modules/system/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def installer(user_config_file: str) -> None:
os.system( # nosec
"sudo bash install.sh "
f"'{configuration.user_config['LOGZ_IO_CODE']}' "
f"'{config.SUPERVISOR_SOCKET_PATH}' "
f"'{config.PATH_SUPERVISOR_SOCKET}' "
f"'{absolute_path}'"
)
2 changes: 1 addition & 1 deletion pi_portal/modules/system/supervisor.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class SupervisorClient:
def __init__(self, host: str = 'localhost', port: int = 9001):
self.server = xmlrpc.client.Server(
f"http://{host}:{port}",
transport=UnixStreamTransport(config.SUPERVISOR_SOCKET_PATH)
transport=UnixStreamTransport(config.PATH_SUPERVISOR_SOCKET)
)

def start(self, process: ProcessList) -> None:
Expand Down
2 changes: 1 addition & 1 deletion pi_portal/modules/system/tests/test_installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ def test_installer(
m_system.assert_called_once_with(
"sudo bash install.sh "
f"'{self.mock_config_file_content['LOGZ_IO_CODE']}' "
f"'{config.SUPERVISOR_SOCKET_PATH}' "
f"'{config.PATH_SUPERVISOR_SOCKET}' "
f"'{os.path.abspath(mock_config_filename)}'"
)

0 comments on commit f96f5e9

Please sign in to comment.