def delete_channel_or_recorder_by_name(self, channel_name, infocfg=None): """deletes all channels or recorders by given channel name. ignores when there's no id for a matched channel name, or when there are no channels in the returned json. """ if infocfg is None: # query device for configured channels try: infocfg = self.get_infocfg() except Exception as e: msg = 'failed to delete channel/recorder(%s); ' % channel_name msg += 'GET infocfg for device(%s) - %s' % ( self.url, e.message) logging.getLogger(__name__).error(msg) raise e if 'channels' in infocfg: for c in infocfg['channels']: if c['name'].strip() == channel_name: try: WebUiChannel.delete_channel( client=self, channel_id=c['id']) except Exception as e: msg = 'failed to delete channel(%s)(%s)' \ % (c['id'], c['name']) msg += ' from device(%s)' % self.url msg += ' - %s' % e.message logging.getLogger(__name__).error(msg) raise e if 'recorders' in infocfg: for r in infocfg['recorders']: if r['name'].strip() == channel_name: try: WebUiChannel.delete_recorder( client=self, recorder_id=r['id']) except Exception as e: msg = 'failed to delete recorder(%s)(%s)' \ % (r['id'], r['name']) msg += ' from device(%s)' % self.url msg += ' - %s' % e.message logging.getLogger(__name__).error(msg) raise e return True
def delete_recorder(self, recorder_id): """deletes given recorder_id.""" return WebUiChannel.delete_recorder( client=self, recorder_id=recorder_id)