now also updating the front page

master
Marek Isalski 7 years ago
parent 4fac492255
commit a1eb4645c4

@ -4,27 +4,18 @@ import os
import glob
import re
class Event( object ):
def __init__( self, path, glob ):
class Index( object ):
def __init__( self, path ):
self.path = path
self.glob = glob
self.fields = {}
self.doc = ""
def path_short( self ):
# XXX needs tidy
return "content/event/" + os.path.basename( self.path )
return "content/pages/index.md"
def open( self ):
if os.path.exists( self.path ):
self.read()
return False
for path in glob.glob( self.glob ):
if os.path.exists( path ):
self.path = path
self.read()
return False
return True
def write( self ):
outdata = ( '''\
@ -45,6 +36,54 @@ class Event( object ):
self.fields = yaml.load( yamldata )
self.doc = docdata.strip()
def _toggle( self, fieldname ):
if self.fields.get( fieldname ):
del self.fields[ fieldname ]
else:
self.fields[ fieldname ] = True
return " ".join( [ x for x in [ 'incident', 'degraded', 'maintenance', 'notice', 'ok' ] if self.fields.get( x ) ] )
def toggle_incident( self ):
return self._toggle( 'incident' )
def toggle_degraded( self ):
return self._toggle( 'degraded' )
def toggle_maintenance( self ):
return self._toggle( 'maintenance' )
def toggle_notice( self ):
return self._toggle( 'notice' )
def toggle_ok( self ):
return self._toggle( 'ok' )
def set_flags( self, flags ):
for fieldname in [ 'incident', 'degraded', 'maintenance', 'notice', 'ok' ]:
self.fields[ fieldname ] = fieldname in flags
class Event( Index ):
def __init__( self, path, glob ):
super().__init__( path )
self.glob = glob
def path_short( self ):
# XXX needs tidy
return "content/event/" + os.path.basename( self.path )
def open( self ):
if os.path.exists( self.path ):
self.read()
return False
for path in glob.glob( self.glob ):
if os.path.exists( path ):
self.path = path
self.read()
return False
return True
def set_title( self, title ):
self.fields[ '$title@' ] = title
@ -86,25 +125,3 @@ class Event( object ):
if not self.fields.get( 'timeline' ):
self.fields[ 'timeline' ] = []
self.fields[ 'timeline' ].append( { 'time': time, 'line': line } )
def _toggle( self, fieldname ):
if self.fields.get( fieldname ):
del self.fields[ fieldname ]
else:
self.fields[ fieldname ] = True
return " ".join( [ x for x in [ 'incident', 'degraded', 'maintenance', 'notice', 'ok' ] if self.fields.get( x ) ] )
def toggle_incident( self ):
return self._toggle( 'incident' )
def toggle_degraded( self ):
return self._toggle( 'degraded' )
def toggle_maintenance( self ):
return self._toggle( 'maintenance' )
def toggle_notice( self ):
return self._toggle( 'notice' )
def toggle_ok( self ):
return self._toggle( 'ok' )

@ -56,6 +56,7 @@ def channel_name_to_raw_incident_number( channel_name ):
def mattermost_incident_command( command, args, channel_id, raw_incident_number, user_name ):
channel = app.mm.channels.get_channel( channel_id )
slug = slugify.slugify( channel[ 'purpose' ] )
index = event.Index( path = app.config[ "STATUS_EVENT_INDEX" ] )
ev = event.Event( path = app.config[ "STATUS_EVENT_SCHEME" ] % { "incident_number": raw_incident_number,
"slug": slug,
},
@ -154,7 +155,7 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
} )
elif command == "START":
new = ev.open()
ev.open()
started = ev.set_started( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) )
ev.write()
@ -162,7 +163,7 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
'message': "Event start date set by %s to: `%s`" % ( user_name, started ),
} )
elif command == "ETR":
new = ev.open()
ev.open()
expected = ev.set_expected( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) )
ev.write()
@ -170,7 +171,7 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
'message': "Event estimated time of resolution set by %s to: `%s`" % ( user_name, expected ),
} )
elif command == "FINISHED":
new = ev.open()
ev.open()
finished = ev.set_finished( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) )
ev.write()
@ -178,7 +179,7 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
'message': "Event finished time set by %s to: `%s`" % ( user_name, finished ),
} )
elif command == "RESOLVED":
new = ev.open()
ev.open()
resolved = ev.set_resolved( args or datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ) )
ev.write()
@ -189,7 +190,7 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
if not args:
return "You need to specify some text to add to the timeline..."
new = ev.open()
ev.open()
ev.add_timeline( time = datetime.datetime.utcnow().strftime( "%Y-%m-%d %H:%M" ), line = args )
ev.write()
@ -198,41 +199,56 @@ def mattermost_incident_command( command, args, channel_id, raw_incident_number,
} )
elif command == "INCIDENT":
new = ev.open()
ev.open()
flags = ev.toggle_incident()
ev.write()
index.open()
index.set_flags( flags.split() )
index.write()
app.mm.posts.create_post( options = { 'channel_id': channel_id,
'message': "Flags set by @%s to: `%s`" % ( user_name, flags ),
} )
elif command == "DEGRADED":
new = ev.open()
ev.open()
flags = ev.toggle_degraded()
ev.write()
index.open()
index.set_flags( flags.split() )
index.write()
app.mm.posts.create_post( options = { 'channel_id': channel_id,
'message': "Flags set by @%s to: `%s`" % ( user_name, flags ),
} )
elif command == "MAINTENANCE":
new = ev.open()
ev.open()
flags = ev.toggle_maintenance()
ev.write()
index.open()
index.set_flags( flags.split() )
index.write()
app.mm.posts.create_post( options = { 'channel_id': channel_id,
'message': "Flags set by @%s to: `%s`" % ( user_name, flags ),
} )
elif command == "NOTICE":
new = ev.open()
ev.open()
flags = ev.toggle_notice()
ev.write()
index.open()
index.set_flags( flags.split() )
index.write()
app.mm.posts.create_post( options = { 'channel_id': channel_id,
'message': "Flags set by @%s to: `%s`" % ( user_name, flags ),
} )
elif command == "OK":
new = ev.open()
ev.open()
flags = ev.toggle_ok()
ev.write()
index.open()
index.set_flags( flags.split() )
index.write()
app.mm.posts.create_post( options = { 'channel_id': channel_id,
'message': "Flags set by @%s to: `%s`" % ( user_name, flags ),

Loading…
Cancel
Save