#!/usr/bin/env python # -*- coding: utf-8 -*- # WWW-sovellukset TJTA270 Vt4 Taso 5 # http://appro.mit.jyu.fi/sovellukset/vt/vt4/ # (C) Esa-Matti Suuronen """ Simppeli mod_python-ohjelma joka konfiguroi CherryPyn ajettavaksi mod_pythonin yli users.jyu.fissa """ import os import os.path from mod_python import apache RUN_DIR = "run" RW_FILES_FOR_APACHE = [ 'error.log', 'users.txt', '__init__.py', '.htaccess', 'kuvat.txt' ] RW_DIRS_FOR_APACHE = [ 'kuvat', 'sessions', ] def handler(req): req.content_type = 'text/html' req.send_http_header() if os.path.basename(req.filename) != "install.py": req.write("
Please open install.py
") return apache.OK this_dir = os.path.abspath(os.path.dirname(__file__)) for can_rw_this in RW_FILES_FOR_APACHE: filepath = os.path.join(this_dir, RUN_DIR, can_rw_this) open(filepath, "w").close() open(filepath, "r").close() os.chmod(filepath, 0666) for can_rw_this in RW_DIRS_FOR_APACHE: filepath = os.path.join(this_dir, RUN_DIR, can_rw_this) if not os.path.exists(filepath): os.mkdir(filepath) os.chmod(filepath, 0777) htaccess_content = """ SetHandler python-program PythonHandler cherrypy._cpmodpy::handler PythonOption cherrypy.setup c2mp::setup_server PythonDebug On PythonPath "['%s'] + sys.path" """ % this_dir htaccess_file = open(os.path.join(this_dir, RUN_DIR, ".htaccess"), "w") htaccess_file.write(htaccess_content) htaccess_file.close() config_content = """ MOUNT_POINT = '%s' ERROR_LOG = '%s' PIC_DIR = '%s' PIC_DB = '%s' USER_DB = '%s' SESSIONS_DIR = '%s' """ % (os.path.join( os.path.dirname(req.uri), RUN_DIR), os.path.join(this_dir, RUN_DIR, "error.log"), os.path.join(this_dir, RUN_DIR, "kuvat"), os.path.join(this_dir, RUN_DIR, "kuvat.txt"), os.path.join(this_dir, RUN_DIR, "users.txt"), os.path.join(this_dir, RUN_DIR, "sessions"), ) config_file = open(os.path.join(this_dir, RUN_DIR, "__init__.py"), "w") config_file.write(config_content) config_file.close() req.write( "%s" "
%s" "
%s
" "" % ( htaccess_file.name, htaccess_content, config_file.name, config_content, str(RW_FILES_FOR_APACHE) + str(RW_DIRS_FOR_APACHE), RUN_DIR )) return apache.OK