Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions dencam/recorder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import os
import getpass
import time
import subprocess
import sys
from abc import ABC, abstractmethod

import picamera
Expand Down Expand Up @@ -66,6 +68,7 @@ def __init__(self, configs):
self.VID_FILE_SIZE = self.FILE_SIZE * self.SAFETY_FACTOR
self.recording = False
self.last_known_video_path = None
self._clear_ghost_drives()
self.video_path = self._video_path_selector()

@abstractmethod
Expand Down Expand Up @@ -164,6 +167,36 @@ def _check_home_storage_capacity(self, media_path):

return media_path

def _clear_ghost_drives(self):
log.info('Clearing ghost drives, if any are present.')
user = getpass.getuser()
media_dir = os.path.join('/media', user)
usb_drive_list = os.listdir(media_dir)
if len(usb_drive_list) > 0:
for usb_drive in usb_drive_list:
usb_drive_dir = media_dir + '/' + usb_drive
try:
result = subprocess.Popen(
['sudo', 'rmdir', usb_drive_dir],
stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
output, error = result.communicate()
if output:
log.info('Ghost drive (subprocess - output): ' +
output.decode('ascii'))
if error:
log.info('Ghost drive (subprocess - error): ' +
error.decode('ascii').strip())
except OSError as os_error:
log.info('Ghost drive (OSError - code): ' +
os_error.errno)
log.info('Ghost drive (OSError - message): ' +
os_error.strerror)
log.info('Ghost drive (OSError - filename): ' +
os_error.filename)
except Exception:
log.info('Ghost drive (Error): ' + sys.exc_info())

def get_free_space(self, media_path=None):
"""Get the remaining space on SD card in gigabytes

Expand Down