@@ -267,51 +267,17 @@ def chainResult(_ignored):
267267 t .addCallbacks (chainResult , chainError )
268268 return d
269269
270- def _commitWithThread (self , transaction : CommitTransaction ):
271- if not self .running :
272- host = transaction .source_address .host
273- port = transaction .source_address .port
274- raise defer .CancelledError (f"CF Processor is not running (transaction: { host } :{ port } )" )
275-
276- _log .info ("CF_COMMIT: {transaction}" .format (transaction = transaction ))
277- _log .debug ("CF_COMMIT: transaction: {s}" .format (s = repr (transaction )))
278- """
279- a dictionary with a list of records with their associated property info
280- pvInfo
281- {record_id: { "pvName":"recordName",
282- "infoProperties":{propName:value, ...}}}
283- """
284- ioc_info = IocInfo (
285- hostname = transaction .client_infos .get ("HOSTNAME" ) or transaction .source_address .host ,
286- iocname = transaction .client_infos .get ("IOCNAME" ) or str (transaction .source_address .port ),
287- iocIP = transaction .source_address .host ,
288- owner = (
289- transaction .client_infos .get ("ENGINEER" )
290- or transaction .client_infos .get ("CF_USERNAME" )
291- or self .cf_config .username
292- ),
293- time = self .currentTime (timezone = self .cf_config .timezone ),
294- port = transaction .source_address .port ,
295- channelcount = 0 ,
296- )
297-
298- """The unique identifier for a particular IOC"""
299- iocid = ioc_info .ioc_id
300- _log .debug ("transaction: {s}" .format (s = repr (transaction )))
301-
270+ def transaction_to_recordInfo (self , ioc_info : IocInfo , transaction : CommitTransaction ) -> Dict [str , RecordInfo ]:
302271 recordInfo : Dict [str , RecordInfo ] = {}
303272 for record_id , (record_name , record_type ) in transaction .records_to_add .items ():
304273 recordInfo [record_id ] = RecordInfo (pvName = record_name , recordType = None , infoProperties = [], aliases = [])
305274 if self .cf_config .record_type_enabled :
306275 recordInfo [record_id ].recordType = record_type
276+
307277 for record_id , (record_infos_to_add ) in transaction .record_infos_to_add .items ():
308278 # find intersection of these sets
309279 if record_id not in recordInfo :
310- _log .warning (
311- "IOC: {iocid}: PV not found for recinfo with RID: {record_id}" .format (
312- iocid = iocid , record_id = record_id
313- )
314- )
280+ _log .warning ("IOC: %s: PV not found for recinfo with RID: {record_id}" , ioc_info , record_id )
315281 continue
316282 recinfo_wl = [p for p in self .record_property_names_list if p in record_infos_to_add .keys ()]
317283 if recinfo_wl :
@@ -320,15 +286,11 @@ def _commitWithThread(self, transaction: CommitTransaction):
320286 create_property (ioc_info .owner , infotag , record_infos_to_add [infotag ])
321287 )
322288
323- for record_id , alias in transaction .aliases .items ():
289+ for record_id , record_aliases in transaction .aliases .items ():
324290 if record_id not in recordInfo :
325- _log .warning (
326- "IOC: {iocid}: PV not found for alias with RID: {record_id}" .format (
327- iocid = iocid , record_id = record_id
328- )
329- )
291+ _log .warning ("IOC: %s: PV not found for alias with RID: %s" , ioc_info , record_id )
330292 continue
331- recordInfo [record_id ].aliases = alias
293+ recordInfo [record_id ].aliases = record_aliases
332294
333295 for record_id in recordInfo :
334296 for epics_env_var_name , cf_prop_name in self .env_vars .items ():
@@ -340,21 +302,27 @@ def _commitWithThread(self, transaction: CommitTransaction):
340302 _log .debug (
341303 "EPICS environment var %s listed in environment_vars setting list not found in this IOC: %s" ,
342304 epics_env_var_name ,
343- ioc_info . iocname ,
305+ ioc_info ,
344306 )
307+ return recordInfo
345308
346- records_to_delete = list (transaction .records_to_delete )
347- _log .debug ("Delete records: {s}" .format (s = records_to_delete ))
348-
309+ def record_info_by_name (self , recordInfo , ioc_info ) -> Dict [str , RecordInfo ]:
349310 recordInfoByName = {}
350311 for record_id , (info ) in recordInfo .items ():
351312 if info .pvName in recordInfoByName :
352- _log .warning (
353- "Commit contains multiple records with PV name: {pv} ({iocid})" .format (pv = info .pvName , iocid = iocid )
354- )
313+ _log .warning ("Commit contains multiple records with PV name: %s (%s)" , info .pvName , ioc_info )
355314 continue
356315 recordInfoByName [info .pvName ] = info
357-
316+ return recordInfoByName
317+
318+ def update_ioc_infos (
319+ self ,
320+ transaction : CommitTransaction ,
321+ ioc_info : IocInfo ,
322+ records_to_delete : List [str ],
323+ recordInfoByName : Dict [str , RecordInfo ],
324+ ):
325+ iocid = ioc_info .ioc_id
358326 if transaction .initial :
359327 """Add IOC to source list """
360328 self .iocs [iocid ] = ioc_info
@@ -366,27 +334,58 @@ def _commitWithThread(self, transaction: CommitTransaction):
366334 """In case, alias exists"""
367335 if self .cf_config .alias_enabled :
368336 if record_name in recordInfoByName :
369- for alias in recordInfoByName [record_name ].aliases :
370- self .channel_ioc_ids [alias ].append (iocid ) # add iocname to pvName in dict
337+ for record_aliases in recordInfoByName [record_name ].aliases :
338+ self .channel_ioc_ids [record_aliases ].append (iocid ) # add iocname to pvName in dict
371339 self .iocs [iocid ].channelcount += 1
372340 for record_name in records_to_delete :
373341 if iocid in self .channel_ioc_ids [record_name ]:
374342 self .remove_channel (record_name , iocid )
375343 """In case, alias exists"""
376344 if self .cf_config .alias_enabled :
377345 if record_name in recordInfoByName :
378- for alias in recordInfoByName [record_name ].aliases :
379- self .remove_channel (alias , iocid )
346+ for record_aliases in recordInfoByName [record_name ].aliases :
347+ self .remove_channel (record_aliases , iocid )
348+
349+ def _commitWithThread (self , transaction : CommitTransaction ):
350+ if not self .running :
351+ host = transaction .source_address .host
352+ port = transaction .source_address .port
353+ raise defer .CancelledError (f"CF Processor is not running (transaction: { host } :{ port } )" )
354+
355+ _log .info ("CF_COMMIT: %s" , transaction )
356+ _log .debug ("CF_COMMIT: transaction: %s" , repr (transaction ))
357+
358+ ioc_info = IocInfo (
359+ hostname = transaction .client_infos .get ("HOSTNAME" ) or transaction .source_address .host ,
360+ iocname = transaction .client_infos .get ("IOCNAME" ) or str (transaction .source_address .port ),
361+ iocIP = transaction .source_address .host ,
362+ owner = (
363+ transaction .client_infos .get ("ENGINEER" )
364+ or transaction .client_infos .get ("CF_USERNAME" )
365+ or self .cf_config .username
366+ ),
367+ time = self .currentTime (timezone = self .cf_config .timezone ),
368+ port = transaction .source_address .port ,
369+ channelcount = 0 ,
370+ )
371+
372+ recordInfo = self .transaction_to_recordInfo (ioc_info , transaction )
373+
374+ records_to_delete = list (transaction .records_to_delete )
375+ _log .debug ("Delete records: {s}" .format (s = records_to_delete ))
376+
377+ recordInfoByName = self .record_info_by_name (recordInfo , ioc_info )
378+ self .update_ioc_infos (transaction , ioc_info , records_to_delete , recordInfoByName )
380379 poll (__updateCF__ , self , recordInfoByName , records_to_delete , ioc_info )
381380
382- def remove_channel (self , recordName , iocid ):
381+ def remove_channel (self , recordName : str , iocid : str ):
383382 self .channel_ioc_ids [recordName ].remove (iocid )
384383 if iocid in self .iocs :
385384 self .iocs [iocid ].channelcount -= 1
386385 if self .iocs [iocid ].channelcount == 0 :
387386 self .iocs .pop (iocid , None )
388387 elif self .iocs [iocid ].channelcount < 0 :
389- _log .error ("Channel count negative: {s} " , s = iocid )
388+ _log .error ("Channel count negative: %s " , iocid )
390389 if len (self .channel_ioc_ids [recordName ]) <= 0 : # case: channel has no more iocs
391390 del self .channel_ioc_ids [recordName ]
392391
0 commit comments