def make_dir(self): try: self.configLock.acquire() stdir = get_stream_dir() Path(stdir).mkdir(parents=True, exist_ok=True) finally: self.configLock.release() return stdir
def run_file_copy(self): to_copy = '' try: stream_dir = get_stream_dir() available_files = [] seg_lists = list(Path(stream_dir).glob('*_index.txt')) earliest_seg_ctime = None if seg_lists: earliest_seg_ctime = path.getctime( min(seg_lists, key=path.getctime)) for i in seg_lists: with open(i) as fp: available_files.extend([ Path(stream_dir, j) for j in fp.readlines() if j and Path(stream_dir, j).exists() ]) available_files.extend([ j for j in Path(stream_dir).glob('*.mp4') if (path.getctime(j) < earliest_seg_ctime if earliest_seg_ctime else True) ]) available_files.sort(key=path.getctime) if len(available_files) == 0: # self.logger.debug('Nothing to copy, quitting') return to_copy = available_files[0] candidate_drive = self.get_cadidate_drive(path.getsize(to_copy)) if candidate_drive: # Mark the drive in use drives = self.filecopy.drives drives[candidate_drive]['in_use'] = True self.filecopy.drives = drives try: self.logger.debug('Starting to copy {} to {}'.format( to_copy, candidate_drive)) # Actually copy it copy2(to_copy, str(Path(candidate_drive, 'iris'))) remove(to_copy) self.logger.debug('{} copied and deleted.'.format(to_copy)) finally: # Mark the drive idle drives = self.filecopy.drives drives[candidate_drive]['in_use'] = False self.filecopy.drives = drives else: self.logger.info('No candidate drives, not copying.') except Exception as e: self.logger.warning('Copy of {} failed due to error: {}'.format( to_copy, e.__repr__()))
def load_streams(self): # Fetch the stream list from settings streams = self.streams try: self.configLock.acquire() status = get_cameras() st_dir = get_stream_dir() for i in status: i['capture_cmd'] = get_capture_command(directory=st_dir, camera_id=i['id'], url=i['url']) i['status'] = 'pending' status = {i['id']: i for i in status} streams.status = status finally: self.configLock.release()