@@ -29,22 +29,22 @@ def heroic_site_id(site: Site):
2929 ''' Extract a HEROIC id for the site.
3030 This concatenates the observatory.site for human readability
3131 '''
32- return settings .HEROIC_OBSERVATORY + '.' + site .code
32+ return f" { settings .HEROIC_OBSERVATORY } . { site .code } "
3333
3434
3535def heroic_telescope_id (telescope : Telescope ):
3636 ''' Extract a HEROIC id for the telescope
3737 This concatenates the observatory.site.telescope for human readability
3838 '''
39- return heroic_site_id (telescope .enclosure .site ) + '.' + telescope .enclosure .code + '-' + telescope .code
39+ return f" { heroic_site_id (telescope .enclosure .site )} . { telescope .enclosure .code } - { telescope .code } "
4040
4141
4242def heroic_instrument_id (instrument : Instrument ):
4343 ''' Extract a HEROIC id for the instrument
4444 This concatenates the observatory.site.telescope.instrument
4545 for human-readability.
4646 '''
47- return heroic_telescope_id (instrument .telescope ) + '.' + instrument .code
47+ return f" { heroic_telescope_id (instrument .telescope )} . { instrument .code } "
4848
4949
5050def heroic_optical_element_groups (instrument : Instrument ):
@@ -128,23 +128,24 @@ def send_to_heroic(api_endpoint: str, payload: dict, update: bool = False):
128128def create_heroic_instrument (instrument : Instrument ):
129129 ''' Create a new instrument payload and send it to HEROIC
130130 '''
131- instrument_payload = {
132- 'id' : heroic_instrument_id (instrument ),
133- 'name' : f"{ instrument .instrument_type .name } - { instrument .code } " ,
134- 'telescope' : heroic_telescope_id (instrument .telescope ),
135- 'available' : True
136- }
137- try :
138- send_to_heroic ('instruments/' , instrument_payload )
139- except Exception as e :
140- logger .error (f'Failed to create heroic instrument { str (instrument )} : { repr (e )} ' )
131+ if (instrument .telescope .enclosure .site .code not in settings .HEROIC_EXCLUDE_SITES ):
132+ instrument_payload = {
133+ 'id' : heroic_instrument_id (instrument ),
134+ 'name' : f"{ instrument .instrument_type .name } - { instrument .code } " ,
135+ 'telescope' : heroic_telescope_id (instrument .telescope ),
136+ 'available' : True
137+ }
138+ try :
139+ send_to_heroic ('instruments/' , instrument_payload )
140+ except Exception as e :
141+ logger .error (f'Failed to create heroic instrument { str (instrument )} : { repr (e )} ' )
141142
142143
143144def update_heroic_instrument_capabilities (instrument : Instrument ):
144145 ''' Send the current instrument capabilities of an instrument to HEROIC
145146 if it is not DISABLED and heroic is set up in settings.py
146147 '''
147- if can_submit_to_heroic () and instrument .state != 'DISABLED' :
148+ if can_submit_to_heroic () and instrument .state != 'DISABLED' and instrument . telescope . enclosure . site . code not in settings . HEROIC_EXCLUDE_SITES :
148149 capabilities = instrument_to_heroic_instrument_capabilities (instrument )
149150 try :
150151 send_to_heroic ('instrument-capabilities/' , capabilities )
@@ -155,25 +156,27 @@ def update_heroic_instrument_capabilities(instrument: Instrument):
155156def create_heroic_telescope (telescope : Telescope ):
156157 ''' Create a new telescope payload and send it to HEROIC
157158 '''
158- telescope_payload = telescope_to_heroic_telescope_properties (telescope )
159- telescope_payload ['id' ] = heroic_telescope_id (telescope )
160- telescope_payload ['status' ] = telescope_status_conversion (telescope )
161- if telescope_payload ['status' ] != 'SCHEDULABLE' :
162- telescope_payload ['reason' ] = 'Telescope is currently marked as inactive to prevent usage'
163- try :
164- send_to_heroic ('telescopes/' , telescope_payload )
165- except Exception as e :
166- logger .error (f'Failed to create heroic telescope { str (telescope )} : { repr (e )} ' )
159+ if telescope .enclosure .site .code not in settings .HEROIC_EXCLUDE_SITES :
160+ telescope_payload = telescope_to_heroic_telescope_properties (telescope )
161+ telescope_payload ['id' ] = heroic_telescope_id (telescope )
162+ telescope_payload ['status' ] = telescope_status_conversion (telescope )
163+ if telescope_payload ['status' ] != 'SCHEDULABLE' :
164+ telescope_payload ['reason' ] = 'Telescope is currently marked as inactive to prevent usage'
165+ try :
166+ send_to_heroic ('telescopes/' , telescope_payload )
167+ except Exception as e :
168+ logger .error (f'Failed to create heroic telescope { str (telescope )} : { repr (e )} ' )
167169
168170
169171def update_heroic_telescope_properties (telescope : Telescope ):
170172 ''' Send updated telescope properties to HEROIC when they change
171173 '''
172- telescope_update_payload = telescope_to_heroic_telescope_properties (telescope )
173- try :
174- send_to_heroic (f'telescopes/{ heroic_telescope_id (telescope )} /' , telescope_update_payload , update = True )
175- except Exception as e :
176- logger .error (f'Failed to update heroic telescope { str (telescope )} : { repr (e )} ' )
174+ if telescope .enclosure .site .code not in settings .HEROIC_EXCLUDE_SITES :
175+ telescope_update_payload = telescope_to_heroic_telescope_properties (telescope )
176+ try :
177+ send_to_heroic (f'telescopes/{ heroic_telescope_id (telescope )} /' , telescope_update_payload , update = True )
178+ except Exception as e :
179+ logger .error (f'Failed to update heroic telescope { str (telescope )} : { repr (e )} ' )
177180
178181
179182def site_to_heroic_site_properties (site : Site ):
@@ -191,19 +194,21 @@ def site_to_heroic_site_properties(site: Site):
191194def create_heroic_site (site : Site ):
192195 ''' Create a new site payload and send it to HEROIC
193196 '''
194- site_payload = site_to_heroic_site_properties (site )
195- site_payload ['id' ] = heroic_site_id (site )
196- try :
197- send_to_heroic ('sites/' , site_payload )
198- except Exception as e :
199- logger .error (f'Failed to create heroic site { str (site )} : { repr (e )} ' )
197+ if site .code not in settings .HEROIC_EXCLUDE_SITES :
198+ site_payload = site_to_heroic_site_properties (site )
199+ site_payload ['id' ] = heroic_site_id (site )
200+ try :
201+ send_to_heroic ('sites/' , site_payload )
202+ except Exception as e :
203+ logger .error (f'Failed to create heroic site { str (site )} : { repr (e )} ' )
200204
201205
202206def update_heroic_site (site : Site ):
203207 ''' Send updated site properties to HEROIC when they change
204208 '''
205- site_payload = site_to_heroic_site_properties (site )
206- try :
207- send_to_heroic (f'sites/{ heroic_site_id (site )} /' , site_payload , update = True )
208- except Exception as e :
209- logger .error (f'Failed to update heroic site { str (site )} : { repr (e )} ' )
209+ if site .code not in settings .HEROIC_EXCLUDE_SITES :
210+ site_payload = site_to_heroic_site_properties (site )
211+ try :
212+ send_to_heroic (f'sites/{ heroic_site_id (site )} /' , site_payload , update = True )
213+ except Exception as e :
214+ logger .error (f'Failed to update heroic site { str (site )} : { repr (e )} ' )
0 commit comments