source: trunk/web/templates/webcommon.py @ 209

Last change on this file since 209 was 209, checked in by ecprice, 17 years ago

Split main.py in four.

File size: 1.3 KB
Line 
1"""Exceptions for the web interface."""
2
3from sipb_xen_database import Machine
4
5class MyException(Exception):
6    """Base class for my exceptions"""
7    pass
8
9class InvalidInput(MyException):
10    """Exception for user-provided input is invalid but maybe in good faith.
11
12    This would include setting memory to negative (which might be a
13    typo) but not setting an invalid boot CD (which requires bypassing
14    the select box).
15    """
16    def __init__(self, err_field, err_value, expl=None):
17        MyException.__init__(self, expl)
18        self.err_field = err_field
19        self.err_value = err_value
20
21class CodeError(MyException):
22    """Exception for internal errors or bad faith input."""
23    pass
24
25import controls
26
27class Global(object):
28    """Global state of the system, to avoid duplicate remctls to get state"""
29    def __init__(self, user):
30        self.user = user
31
32    def __get_uptimes(self):
33        if not hasattr(self, '_uptimes'):
34            self._uptimes = controls.getUptimes(Machine.select())
35        return self._uptimes
36    uptimes = property(__get_uptimes)
37
38    def clear(self):
39        """Clear the state so future accesses reload it."""
40        for attr in ('_uptimes', ):
41            if hasattr(self, attr):
42                delattr(self, attr)
43
44g = Global(None)
Note: See TracBrowser for help on using the repository browser.