From 74c5ff45a23e42604ba75a0ceb593ec51469fc56 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 18 Nov 2012 09:22:25 +0100 Subject: rss publising MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- sysrss.py | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/sysrss.py b/sysrss.py index f764682..fb886a7 100755 --- a/sysrss.py +++ b/sysrss.py @@ -67,6 +67,8 @@ def flush(): ''' Mane class + +@dependency util-linux::uuidgen ''' class SysRSS: ''' @@ -77,6 +79,7 @@ class SysRSS: self.sysinit() + ''' Initialise the system ''' @@ -110,6 +113,78 @@ class SysRSS: file.flush() printf('Created rss file %s, your should set you news feed aggregator to syndicate this file.\n', self.root + 'maintenance.rss') flush() + self.pubdate = date + self.publish('Welcome to SysRSS', 'This is going to be so awesome! 😄 \n\nEx animo\nSysRSS\n\n') + else: + data = None + with open(self.root + 'maintenance.rss', 'rb') as file: + data = file.read() + data = data.decode('utf8', 'replace') + data = data[data.find('') + len(''):] + data = data[:data.find('\n'.encode('utf-8')) + file.write('\n'.encode('utf-8')) + file.write(' \n'.encode('utf-8')) + file.write(' SysRSS\n'.encode('utf-8')) + file.write(' System maintenance notification RSS\n'.encode('utf-8')) + file.write(' http://localhost/\n'.encode('utf-8')) + file.write((' %s\n' % date).encode('utf-8')) + file.write((' %s\n' % self.pubdate).encode('utf-8')) + with open(self.root + 'log', 'rb') as logfile: + file.write(logfile.read()) + file.write(' \n'.encode('utf-8')) + file.write('\n'.encode('utf-8')) + file.write('\n'.encode('utf-8')) + file.flush() + Popen(['mv', self.root + 'tmp', self.root + 'maintenance.rss']).wait() + printf('The feed as been updated with %s.\n', system) + + + ''' + Generate RSS item + + @param system:str The subsystem that generated the message + @param message:str Message to display + @return :str RSS item + ''' + def makeNews(self, system, message): + def makeUglyButReadable(data): + data = data.replace(']]>', ']]>]]') + data = data.replace('\n', '
') # [sic!] + return '' + return('\n %s\n %s\n %s\n %s\n\n\n' % + (makeUglyButReadable(system), self.generateUUID(), self.getTime(), makeUglyButReadable(message))) + + + ''' + Generate an UUID + + @return An UUID + ''' + def generateUUID(self): + uuid = Popen(['uuidgen'], stdout=PIPE).communicate()[0].decode('utf-8', 'replace') + if uuid[-1] == '\n': + uuid = uuid[:-1] + return uuid ''' -- cgit v1.2.3-70-g09d2