1.1 --- a/imip_manager.py Wed Mar 25 16:41:43 2015 +0100
1.2 +++ b/imip_manager.py Wed Mar 25 17:57:42 2015 +0100
1.3 @@ -27,7 +27,7 @@
1.4 from datetime import date, datetime, timedelta
1.5 import babel.dates
1.6 import pytz
1.7 -import cgi, os, sys
1.8 +import sys
1.9
1.10 sys.path.append(LIBRARY_PATH)
1.11
1.12 @@ -47,71 +47,10 @@
1.13 partition_by_day, remove_period, remove_affected_period, \
1.14 update_freebusy
1.15 from imiptools.profile import Preferences
1.16 +from imipweb.env import CGIEnvironment
1.17 import imip_store
1.18 import markup
1.19
1.20 -getenv = os.environ.get
1.21 -setenv = os.environ.__setitem__
1.22 -
1.23 -class CGIEnvironment:
1.24 -
1.25 - "A CGI-compatible environment."
1.26 -
1.27 - def __init__(self, charset=None):
1.28 - self.charset = charset
1.29 - self.args = None
1.30 - self.method = None
1.31 - self.path = None
1.32 - self.path_info = None
1.33 - self.user = None
1.34 -
1.35 - def get_args(self):
1.36 - if self.args is None:
1.37 - if self.get_method() != "POST":
1.38 - setenv("QUERY_STRING", "")
1.39 - args = cgi.parse(keep_blank_values=True)
1.40 -
1.41 - if not self.charset:
1.42 - self.args = args
1.43 - else:
1.44 - self.args = {}
1.45 - for key, values in args.items():
1.46 - self.args[key] = [unicode(value, self.charset) for value in values]
1.47 -
1.48 - return self.args
1.49 -
1.50 - def get_method(self):
1.51 - if self.method is None:
1.52 - self.method = getenv("REQUEST_METHOD") or "GET"
1.53 - return self.method
1.54 -
1.55 - def get_path(self):
1.56 - if self.path is None:
1.57 - self.path = getenv("SCRIPT_NAME") or ""
1.58 - return self.path
1.59 -
1.60 - def get_path_info(self):
1.61 - if self.path_info is None:
1.62 - self.path_info = getenv("PATH_INFO") or ""
1.63 - return self.path_info
1.64 -
1.65 - def get_user(self):
1.66 - if self.user is None:
1.67 - self.user = getenv("REMOTE_USER") or ""
1.68 - return self.user
1.69 -
1.70 - def get_output(self):
1.71 - return sys.stdout
1.72 -
1.73 - def get_url(self):
1.74 - path = self.get_path()
1.75 - path_info = self.get_path_info()
1.76 - return "%s%s" % (path.rstrip("/"), path_info)
1.77 -
1.78 - def new_url(self, path_info):
1.79 - path = self.get_path()
1.80 - return "%s/%s" % (path.rstrip("/"), path_info.lstrip("/"))
1.81 -
1.82 class Common:
1.83
1.84 "Common handler and manager methods."
3.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
3.2 +++ b/imipweb/env.py Wed Mar 25 17:57:42 2015 +0100
3.3 @@ -0,0 +1,86 @@
3.4 +#!/usr/bin/env python
3.5 +
3.6 +"""
3.7 +Web interface utilities.
3.8 +
3.9 +Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk>
3.10 +
3.11 +This program is free software; you can redistribute it and/or modify it under
3.12 +the terms of the GNU General Public License as published by the Free Software
3.13 +Foundation; either version 3 of the License, or (at your option) any later
3.14 +version.
3.15 +
3.16 +This program is distributed in the hope that it will be useful, but WITHOUT
3.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
3.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
3.19 +details.
3.20 +
3.21 +You should have received a copy of the GNU General Public License along with
3.22 +this program. If not, see <http://www.gnu.org/licenses/>.
3.23 +"""
3.24 +
3.25 +import cgi, os, sys
3.26 +
3.27 +getenv = os.environ.get
3.28 +setenv = os.environ.__setitem__
3.29 +
3.30 +class CGIEnvironment:
3.31 +
3.32 + "A CGI-compatible environment."
3.33 +
3.34 + def __init__(self, charset=None):
3.35 + self.charset = charset
3.36 + self.args = None
3.37 + self.method = None
3.38 + self.path = None
3.39 + self.path_info = None
3.40 + self.user = None
3.41 +
3.42 + def get_args(self):
3.43 + if self.args is None:
3.44 + if self.get_method() != "POST":
3.45 + setenv("QUERY_STRING", "")
3.46 + args = cgi.parse(keep_blank_values=True)
3.47 +
3.48 + if not self.charset:
3.49 + self.args = args
3.50 + else:
3.51 + self.args = {}
3.52 + for key, values in args.items():
3.53 + self.args[key] = [unicode(value, self.charset) for value in values]
3.54 +
3.55 + return self.args
3.56 +
3.57 + def get_method(self):
3.58 + if self.method is None:
3.59 + self.method = getenv("REQUEST_METHOD") or "GET"
3.60 + return self.method
3.61 +
3.62 + def get_path(self):
3.63 + if self.path is None:
3.64 + self.path = getenv("SCRIPT_NAME") or ""
3.65 + return self.path
3.66 +
3.67 + def get_path_info(self):
3.68 + if self.path_info is None:
3.69 + self.path_info = getenv("PATH_INFO") or ""
3.70 + return self.path_info
3.71 +
3.72 + def get_user(self):
3.73 + if self.user is None:
3.74 + self.user = getenv("REMOTE_USER") or ""
3.75 + return self.user
3.76 +
3.77 + def get_output(self):
3.78 + return sys.stdout
3.79 +
3.80 + def get_url(self):
3.81 + path = self.get_path()
3.82 + path_info = self.get_path_info()
3.83 + return "%s%s" % (path.rstrip("/"), path_info)
3.84 +
3.85 + def new_url(self, path_info):
3.86 + path = self.get_path()
3.87 + return "%s/%s" % (path.rstrip("/"), path_info.lstrip("/"))
3.88 +
3.89 +# vim: tabstop=4 expandtab shiftwidth=4
4.1 --- a/tools/install.sh Wed Mar 25 16:41:43 2015 +0100
4.2 +++ b/tools/install.sh Wed Mar 25 17:57:42 2015 +0100
4.3 @@ -11,8 +11,14 @@
4.4
4.5 cp $AGENTS "$INSTALL_DIR"
4.6 cp $MODULES "$INSTALL_DIR"
4.7 -mkdir "$INSTALL_DIR"/imiptools
4.8 -mkdir "$INSTALL_DIR"/imiptools/handlers
4.9 +
4.10 +if [ ! -e "$INSTALL_DIR/imiptools" ]; then
4.11 + mkdir "$INSTALL_DIR"/imiptools
4.12 + if [ ! -e "$INSTALL_DIR/imiptools" ]; then
4.13 + mkdir "$INSTALL_DIR"/imiptools/handlers
4.14 + fi
4.15 +fi
4.16 +
4.17 cp imiptools/*.py "$INSTALL_DIR"/imiptools/
4.18 cp imiptools/handlers/*.py "$INSTALL_DIR"/imiptools/handlers/
4.19
4.20 @@ -22,3 +28,9 @@
4.21
4.22 cp imip_manager.py "$WEB_INSTALL_DIR"
4.23 cp htdocs/styles.css "$WEB_INSTALL_DIR"
4.24 +
4.25 +if [ ! -e "$WEB_INSTALL_DIR/imipweb" ]; then
4.26 + mkdir "$WEB_INSTALL_DIR"/imipweb
4.27 +fi
4.28 +
4.29 +cp imipweb/*.py "$WEB_INSTALL_DIR"/imipweb/