diff options
Diffstat (limited to 'overseerlib/app.py')
-rw-r--r-- | overseerlib/app.py | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/overseerlib/app.py b/overseerlib/app.py deleted file mode 100644 index dc3e811..0000000 --- a/overseerlib/app.py +++ /dev/null @@ -1,99 +0,0 @@ -#!/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 - - -defaults = { - 'work-area': '/home/trove-overseer', - 'config-name': 'monitoring.conf', -} - - -class TroveOverseer(cliapp.Application): - - def add_settings(self): - self.settings.string(['work-area'], - 'path to the area for the controller to work in', - metavar='PATH', - default=defaults['work-area']) - self.settings.string(['config-name'], 'configuration file name. ' - 'Defaults to monitoring.conf', - metavar='FILENAME', - default=defaults['config-name']) - - def process_args(self, args): - self.rungit(['remote', 'update', 'origin']) - self.rungit(['reset', '--hard', 'origin/master']) - self.rungit(['clean', '-fdx']) - config = os.path.join(self.settings['work-area'], 'git', - self.settings['config-name'])) - overseerlib.parseyaml.ParseYAML.load_config(config) - - 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=os.path.join(self.settings['work-area'], - 'git')) - - def write_to_html(self, html_file): - if html_file: - try: - with open(html_file + '.new', 'w') as ofh: - ofh.write('<!DOCTYPE html>\n') - ofh.write(self.gen_html()) - ofh.write('\n') - target = filename - os.rename(filename + '.new', target) - except: - os.unlink(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</%s>' % (tagval, gap, content, gap, tagname) |