Skip to content

Commit

Permalink
remove duplicate code for removing channel
Browse files Browse the repository at this point in the history
  • Loading branch information
jacomago committed Mar 21, 2024
1 parent 1c58a56 commit 3bc15cf
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions server/recceiver/cfstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,31 +246,26 @@ def _commitWithThread(self, TR):
self.iocs[iocid]["channelcount"] += 1
for pv in delrec:
if iocid in self.channel_dict[pv]:
self.channel_dict[pv].remove(iocid)
if iocid in self.iocs:
self.iocs[iocid]["channelcount"] -= 1
if self.iocs[iocid]['channelcount'] == 0:
self.iocs.pop(iocid, None)
elif self.iocs[iocid]['channelcount'] < 0:
_log.error("Channel count negative: %s", iocid)
if len(self.channel_dict[pv]) <= 0: # case: channel has no more iocs
del self.channel_dict[pv]
self.remove_channel(pv, iocid)
"""In case, alias exists"""
if (self.conf.get('alias', 'default' == 'on')):
if pv in pvInfoByName and "aliases" in pvInfoByName[pv]:
for a in pvInfoByName[pv]["aliases"]:
self.channel_dict[a].remove(iocid)
if iocid in self.iocs:
self.iocs[iocid]["channelcount"] -= 1
if self.iocs[iocid]['channelcount'] == 0:
self.iocs.pop(iocid, None)
elif self.iocs[iocid]['channelcount'] < 0:
_log.error("Channel count negative: %s", iocid)
if len(self.channel_dict[a]) <= 0: # case: channel has no more iocs
del self.channel_dict[a]
self.remove_channel(a, iocid)
poll(__updateCF__, self, pvInfoByName, delrec, hostName, iocName, iocid, owner, time)
dict_to_file(self.channel_dict, self.iocs, self.conf)

def remove_channel(self, a, iocid):
self.channel_dict[a].remove(iocid)
if iocid in self.iocs:
self.iocs[iocid]["channelcount"] -= 1
if self.iocs[iocid]['channelcount'] == 0:
self.iocs.pop(iocid, None)
elif self.iocs[iocid]['channelcount'] < 0:
_log.error("Channel count negative: %s", iocid)
if len(self.channel_dict[a]) <= 0: # case: channel has no more iocs
del self.channel_dict[a]

def clean_service(self):
"""
Marks all channels as "Inactive" until the recsync server is back up
Expand Down

0 comments on commit 3bc15cf

Please sign in to comment.