#!/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)