imip-agent

imip_manager.py

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