imip-agent

Annotated imip_manager.py

1149:008b80c604da
2016-04-22 Paul Boddie Added some documentation for the store-copying tool. freebusy-collections
paul@69 1
#!/usr/bin/env python
paul@69 2
paul@146 3
"""
paul@146 4
A Web interface to a user's calendar.
paul@146 5
paul@146 6
Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk>
paul@146 7
paul@146 8
This program is free software; you can redistribute it and/or modify it under
paul@146 9
the terms of the GNU General Public License as published by the Free Software
paul@146 10
Foundation; either version 3 of the License, or (at your option) any later
paul@146 11
version.
paul@146 12
paul@146 13
This program is distributed in the hope that it will be useful, but WITHOUT
paul@146 14
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
paul@146 15
FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
paul@146 16
details.
paul@146 17
paul@146 18
You should have received a copy of the GNU General Public License along with
paul@146 19
this program.  If not, see <http://www.gnu.org/licenses/>.
paul@146 20
"""
paul@146 21
paul@146 22
# Edit this path to refer to the location of the imiptools libraries, if
paul@146 23
# necessary.
paul@146 24
paul@146 25
LIBRARY_PATH = "/var/lib/imip-agent"
paul@146 26
paul@440 27
import sys
paul@146 28
sys.path.append(LIBRARY_PATH)
paul@69 29
paul@446 30
from imipweb.calendar import CalendarPage
paul@446 31
from imipweb.event import EventPage
paul@922 32
from imipweb.profile import ProfilePage
paul@756 33
from imipweb.resource import ResourceClient
paul@69 34
paul@756 35
class Manager(ResourceClient):
paul@69 36
paul@69 37
    "A simple manager application."
paul@69 38
paul@69 39
    def select_action(self):
paul@69 40
paul@69 41
        "Select the desired action and show the result."
paul@69 42
paul@121 43
        path_info = self.env.get_path_info().strip("/")
paul@121 44
paul@69 45
        if not path_info:
paul@446 46
            CalendarPage(self).show()
paul@922 47
        elif path_info == "profile":
paul@922 48
            ProfilePage(self).show()
paul@446 49
        elif EventPage(self).show(path_info):
paul@70 50
            pass
paul@70 51
        else:
paul@70 52
            self.no_page()
paul@69 53
paul@82 54
    def __call__(self):
paul@69 55
paul@69 56
        "Interpret a request and show an appropriate response."
paul@69 57
paul@69 58
        if not self.user:
paul@69 59
            self.no_user()
paul@69 60
        else:
paul@69 61
            self.select_action()
paul@69 62
paul@70 63
        # Write the headers and actual content.
paul@70 64
paul@69 65
        print >>self.out, "Content-Type: text/html; charset=%s" % self.encoding
paul@69 66
        print >>self.out
paul@69 67
        self.out.write(unicode(self.page).encode(self.encoding))
paul@69 68
paul@69 69
if __name__ == "__main__":
paul@128 70
    Manager()()
paul@69 71
paul@69 72
# vim: tabstop=4 expandtab shiftwidth=4