# HG changeset patch # User Paul Boddie # Date 1427302662 -3600 # Node ID ab91c238fbb6f13e675c0c7dee76b65c1fa23acd # Parent d6fb308c1023c83b767de18afc48bc575fb1d8af Created an imipweb package, moving the CGIEnvironment class into the env module. diff -r d6fb308c1023 -r ab91c238fbb6 imip_manager.py --- a/imip_manager.py Wed Mar 25 16:41:43 2015 +0100 +++ b/imip_manager.py Wed Mar 25 17:57:42 2015 +0100 @@ -27,7 +27,7 @@ from datetime import date, datetime, timedelta import babel.dates import pytz -import cgi, os, sys +import sys sys.path.append(LIBRARY_PATH) @@ -47,71 +47,10 @@ partition_by_day, remove_period, remove_affected_period, \ update_freebusy from imiptools.profile import Preferences +from imipweb.env import CGIEnvironment import imip_store import markup -getenv = os.environ.get -setenv = os.environ.__setitem__ - -class CGIEnvironment: - - "A CGI-compatible environment." - - def __init__(self, charset=None): - self.charset = charset - self.args = None - self.method = None - self.path = None - self.path_info = None - self.user = None - - def get_args(self): - if self.args is None: - if self.get_method() != "POST": - setenv("QUERY_STRING", "") - args = cgi.parse(keep_blank_values=True) - - if not self.charset: - self.args = args - else: - self.args = {} - for key, values in args.items(): - self.args[key] = [unicode(value, self.charset) for value in values] - - return self.args - - def get_method(self): - if self.method is None: - self.method = getenv("REQUEST_METHOD") or "GET" - return self.method - - def get_path(self): - if self.path is None: - self.path = getenv("SCRIPT_NAME") or "" - return self.path - - def get_path_info(self): - if self.path_info is None: - self.path_info = getenv("PATH_INFO") or "" - return self.path_info - - def get_user(self): - if self.user is None: - self.user = getenv("REMOTE_USER") or "" - return self.user - - def get_output(self): - return sys.stdout - - def get_url(self): - path = self.get_path() - path_info = self.get_path_info() - return "%s%s" % (path.rstrip("/"), path_info) - - def new_url(self, path_info): - path = self.get_path() - return "%s/%s" % (path.rstrip("/"), path_info.lstrip("/")) - class Common: "Common handler and manager methods." diff -r d6fb308c1023 -r ab91c238fbb6 imipweb/__init__.py diff -r d6fb308c1023 -r ab91c238fbb6 imipweb/env.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/imipweb/env.py Wed Mar 25 17:57:42 2015 +0100 @@ -0,0 +1,86 @@ +#!/usr/bin/env python + +""" +Web interface utilities. + +Copyright (C) 2014, 2015 Paul Boddie + +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; either version 3 of the License, or (at your option) any later +version. + +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, see . +""" + +import cgi, os, sys + +getenv = os.environ.get +setenv = os.environ.__setitem__ + +class CGIEnvironment: + + "A CGI-compatible environment." + + def __init__(self, charset=None): + self.charset = charset + self.args = None + self.method = None + self.path = None + self.path_info = None + self.user = None + + def get_args(self): + if self.args is None: + if self.get_method() != "POST": + setenv("QUERY_STRING", "") + args = cgi.parse(keep_blank_values=True) + + if not self.charset: + self.args = args + else: + self.args = {} + for key, values in args.items(): + self.args[key] = [unicode(value, self.charset) for value in values] + + return self.args + + def get_method(self): + if self.method is None: + self.method = getenv("REQUEST_METHOD") or "GET" + return self.method + + def get_path(self): + if self.path is None: + self.path = getenv("SCRIPT_NAME") or "" + return self.path + + def get_path_info(self): + if self.path_info is None: + self.path_info = getenv("PATH_INFO") or "" + return self.path_info + + def get_user(self): + if self.user is None: + self.user = getenv("REMOTE_USER") or "" + return self.user + + def get_output(self): + return sys.stdout + + def get_url(self): + path = self.get_path() + path_info = self.get_path_info() + return "%s%s" % (path.rstrip("/"), path_info) + + def new_url(self, path_info): + path = self.get_path() + return "%s/%s" % (path.rstrip("/"), path_info.lstrip("/")) + +# vim: tabstop=4 expandtab shiftwidth=4 diff -r d6fb308c1023 -r ab91c238fbb6 tools/install.sh --- a/tools/install.sh Wed Mar 25 16:41:43 2015 +0100 +++ b/tools/install.sh Wed Mar 25 17:57:42 2015 +0100 @@ -11,8 +11,14 @@ cp $AGENTS "$INSTALL_DIR" cp $MODULES "$INSTALL_DIR" -mkdir "$INSTALL_DIR"/imiptools -mkdir "$INSTALL_DIR"/imiptools/handlers + +if [ ! -e "$INSTALL_DIR/imiptools" ]; then + mkdir "$INSTALL_DIR"/imiptools + if [ ! -e "$INSTALL_DIR/imiptools" ]; then + mkdir "$INSTALL_DIR"/imiptools/handlers + fi +fi + cp imiptools/*.py "$INSTALL_DIR"/imiptools/ cp imiptools/handlers/*.py "$INSTALL_DIR"/imiptools/handlers/ @@ -22,3 +28,9 @@ cp imip_manager.py "$WEB_INSTALL_DIR" cp htdocs/styles.css "$WEB_INSTALL_DIR" + +if [ ! -e "$WEB_INSTALL_DIR/imipweb" ]; then + mkdir "$WEB_INSTALL_DIR"/imipweb +fi + +cp imipweb/*.py "$WEB_INSTALL_DIR"/imipweb/