Hide keyboard shortcuts

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 

18 

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 

24 

25 

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): 

30 

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) 

37 

38 

39class Event(BaseEvent): 

40 

41 labels_class = EventLabels 

42 logs_class = EventLogs 

43 voevent_class = EventVOEvents 

44 

45 

46SIGNOFF_INSTRUMENTS = ['H1', 'L1', 'V1'] 

47 

48 

49class Superevent(BaseEvent): 

50 

51 labels_class = SupereventLabels 

52 logs_class = SupereventLogs 

53 voevent_class = SupereventVOEvents 

54 

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 += '/' 

61 

62 def add(self, event_id): 

63 self._events.create(data={'event': event_id}) 

64 

65 def remove(self, event_id): 

66 self._events.delete(event_id) 

67 

68 def _modify_permissions(self, action): 

69 url = join(self.url, 'permissions/modify/') 

70 self.session.post(url, data={'action': action}) 

71 

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 

80 

81 def expose(self): 

82 self._modify_permissions('expose') 

83 

84 def unexpose(self): 

85 self._modify_permissions('hide') 

86 

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) 

97 

98 

99class SupereventEventList(Deletable, Mutable, Resource): 

100 

101 path = 'events/'