@@ -36,6 +36,7 @@ class SnapshotProcessor:
36
36
37
37
def __init__ (self , config : SwatchConfig ) -> None :
38
38
self .config = config
39
+ self .media_dir = os .environ .get ("MEDIA_DIR" , CONST_MEDIA_DIR )
39
40
40
41
def save_snapshot (
41
42
self ,
@@ -47,7 +48,7 @@ def save_snapshot(
47
48
"""Saves the file snapshot to the correct snapshot dir."""
48
49
time = datetime .datetime .now ()
49
50
50
- file_dir = f"{ CONST_MEDIA_DIR } /snapshots/{ time .strftime ('%m-%d' )} /{ camera_name } "
51
+ file_dir = f"{ self . media_dir } /snapshots/{ time .strftime ('%m-%d' )} /{ camera_name } "
51
52
52
53
if not os .path .exists (file_dir ):
53
54
print (f"{ file_dir } doesn't exist, creating..." )
@@ -87,10 +88,10 @@ def save_snapshot(
87
88
88
89
def get_detection_snapshot (self , detection : Detection ) -> Any :
89
90
"""Get file snapshot for a specific detection."""
90
- file_dir = f"{ CONST_MEDIA_DIR } /snapshots/{ datetime .datetime .fromtimestamp (detection .start_time ).strftime ('%m-%d' )} /{ detection .camera } "
91
+ file_dir = f"{ self . media_dir } /snapshots/{ datetime .datetime .fromtimestamp (detection .start_time ).strftime ('%m-%d' )} /{ detection .camera } "
91
92
92
93
if not os .path .exists (file_dir ):
93
- file_dir = f"{ CONST_MEDIA_DIR } /snapshots/{ datetime .datetime .fromtimestamp (detection .end_time ).strftime ('%m-%d' )} /{ detection .camera } "
94
+ file_dir = f"{ self . media_dir } /snapshots/{ datetime .datetime .fromtimestamp (detection .end_time ).strftime ('%m-%d' )} /{ detection .camera } "
94
95
95
96
if not os .path .exists (file_dir ):
96
97
return None
@@ -142,7 +143,7 @@ def get_latest_zone_snapshot(
142
143
143
144
def get_latest_detection_snapshot (self , camera_name : str ) -> Any :
144
145
"""Get the latest file snapshot for a <camera_name> detection."""
145
- snaps_dir = f"{ CONST_MEDIA_DIR } /snapshots"
146
+ snaps_dir = f"{ self . media_dir } /snapshots"
146
147
recent_folder = max (
147
148
[os .path .join (snaps_dir , basename ) for basename in os .listdir (snaps_dir )]
148
149
)
@@ -173,6 +174,7 @@ def __init__(
173
174
threading .Thread .__init__ (self )
174
175
self .name = "snapshot_cleanup"
175
176
self .config = config
177
+ self .media_dir = os .environ .get ("MEDIA_DIR" , CONST_MEDIA_DIR )
176
178
self .stop_event = stop_event
177
179
178
180
def cleanup_snapshots (self , camera_config : CameraConfig ):
@@ -182,9 +184,9 @@ def cleanup_snapshots(self, camera_config: CameraConfig):
182
184
)
183
185
valid_month , _ , valid_day = retain_days_ago .strftime ("%m-%d" ).partition ("-" )
184
186
185
- for snap_dir in os .listdir (f"{ CONST_MEDIA_DIR } /snapshots/" ):
187
+ for snap_dir in os .listdir (f"{ self . media_dir } /snapshots/" ):
186
188
if not os .path .isdir (
187
- os .path .join (f"{ CONST_MEDIA_DIR } /snapshots/" , snap_dir )
189
+ os .path .join (f"{ self . media_dir } /snapshots/" , snap_dir )
188
190
):
189
191
continue
190
192
@@ -193,11 +195,11 @@ def cleanup_snapshots(self, camera_config: CameraConfig):
193
195
194
196
if month == valid_month and valid_day >= day :
195
197
delete_dir (
196
- f"{ CONST_MEDIA_DIR } /snapshots/{ month } -{ day } " , camera_config .name
198
+ f"{ self . media_dir } /snapshots/{ month } -{ day } " , camera_config .name
197
199
)
198
200
elif valid_month > month and (int (day ) - int (valid_day )) <= 24 :
199
201
delete_dir (
200
- f"{ CONST_MEDIA_DIR } /snapshots/{ month } -{ day } " , camera_config .name
202
+ f"{ self . media_dir } /snapshots/{ month } -{ day } " , camera_config .name
201
203
)
202
204
203
205
def run (self ):
0 commit comments