From 451ee498abbf5a4b7986954a561e4bda94955e72 Mon Sep 17 00:00:00 2001 From: Ben Brown Date: Tue, 21 Jan 2014 11:38:48 +0000 Subject: Initial commit for trove-overseer project --- overseerlib/app.py | 83 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 overseerlib/app.py (limited to 'overseerlib/app.py') diff --git a/overseerlib/app.py b/overseerlib/app.py new file mode 100644 index 0000000..13fb461 --- /dev/null +++ b/overseerlib/app.py @@ -0,0 +1,83 @@ +#!/usr/bin/python +# +# Copyright (C) 2014 Codethink Limited +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; version 2 of the License. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + + +import os +import smtplib +import getpass + +import cliapp + +import overseerlib + + +class TroveOverseer(cliapp.Application): + + def add_settings(self): + self.settings.string(['config-path'], 'path to configuration file', + metavar='FILE', default='/etc/monitoring.conf') + + def process_args(self, args): +# self.rungit(['remote', 'update', 'origin']) +# self.rungit(['reset', '--hard', 'origin/master']) +# self.rungit(['clean', '-fdx']) + cliapp.Application.process_args(self, args) + + def human_to_bytes(self, threshold): + symbols = ('B', 'K', 'M', 'G', 'T') + s = threshold + letter = s[-1:].strip().upper() + num = s[:-1] + if letter not in symbols: + raise cliapp.AppException('Valid symbols: B, K, M, G, T') + num = float(num) + prefix = {symbols[0]:1} + for i, s in enumerate(symbols[1:]): + prefix[s] = 1 << (i+1)*10 + return int(num * prefix[letter]) + + def rungit(self, args): + self.runcmd(['git']+args, cwd='/src/morph') + + def write_to_html(self, html_file): + if html_file: + try: + with open(self.html_file + '.new', 'w') as ofh: + ofh.write('\n') + ofh.write(self.gen_html()) + ofh.write('\n') + target = self.filename + os.rename(self.filename + '.new', target) + except: + os.unlink(self.filename + '.new') + raise + + def gen_footer(self): + curtime = format_time(time.time()) + return self.tag('div', Class='footer', content= + 'Generated by Trove Monitoring at ' + curtime) + + + def tag(self, tagname, content=None, gap=False, **kwargs): + tagval = ' '.join([tagname] + + ['%s=%r' % (k.lower(), v) + for k, v in kwargs.iteritems()]) + gap = '\n' if gap else '' + if content is None: + return '<%s />' % tagval + else: + return '<%s>%s%s%s' % (tagval, gap, content, gap, tagname) -- cgit v1.2.1