Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1#
2# Copyright (C) 2019-2020 Leo P. Singer <leo.singer@ligo.org>
3#
4# This program is free software: you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation, either version 3 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program. If not, see <https://www.gnu.org/licenses/>.
16#
17from os.path import join
19from .base import Deletable, Mutable, Resource
20from .files import Files
21from .voevents import EventVOEvents, SupereventVOEvents
22from .logs import EventLogs, SupereventLogs
23from .labels import EventLabels, SupereventLabels
26# FIXME: events have a 'log/' resource whereas superevents have 'logs/'.
27# Combine BaseEvent, Event, and Superevent into a single Event class
28# once this inconsistency has been fixed.
29class BaseEvent(Resource):
31 def __init__(self, *args, **kwargs):
32 super().__init__(*args, **kwargs)
33 self.files = Files(self)
34 self.logs = self.logs_class(self)
35 self.labels = self.labels_class(self)
36 self.voevents = self.voevent_class(self)
39class Event(BaseEvent):
41 labels_class = EventLabels
42 logs_class = EventLogs
43 voevent_class = EventVOEvents
46SIGNOFF_INSTRUMENTS = ['H1', 'L1', 'V1']
49class Superevent(BaseEvent):
51 labels_class = SupereventLabels
52 logs_class = SupereventLogs
53 voevent_class = SupereventVOEvents
55 def __init__(self, *args, **kwargs):
56 super().__init__(*args, **kwargs)
57 self._events = SupereventEventList(self)
58 # FIXME: GraceDB requires a random / for these URLs!
59 # This is inconsistent between events and superevents.
60 self.url += '/'
62 def add(self, event_id):
63 self._events.create(data={'event': event_id})
65 def remove(self, event_id):
66 self._events.delete(event_id)
68 def _modify_permissions(self, action):
69 url = join(self.url, 'permissions/modify/')
70 self.session.post(url, data={'action': action})
72 def is_exposed(self):
73 url = join(self.url, 'permissions/')
74 result = self.session.get(url).json()
75 for row in result['permissions']:
76 if row['group'] == 'public_users' \
77 and row['permission'] == 'view_superevent':
78 return True
79 return False
81 def expose(self):
82 self._modify_permissions('expose')
84 def unexpose(self):
85 self._modify_permissions('hide')
87 def signoff(self, signoff_type, status, comment=''):
88 url = join(self.url, 'signoffs/')
89 data = {'status': status, 'comment': comment}
90 if signoff_type in SIGNOFF_INSTRUMENTS:
91 data['signoff_type'] = 'OP'
92 data['instrument'] = signoff_type
93 else:
94 data['signoff_type'] = signoff_type
95 data['instrument'] = ''
96 self.session.post(url, data=data)
99class SupereventEventList(Deletable, Mutable, Resource):
101 path = 'events/'