# $Revision: 1.14 $
#################################################################
# Make sure the following variables are correct for your system.
# If you're on Windows, be sure to always use the forward slash (/)
# instead of the backslash (\).
# Otherwise maki's path matching won't work properly.
#################################################################
# directory where maki will store its files
#MAKI_DIR="c:/maki"
MAKI_DIR="/usr/local/maki"
# directory where examples and manual will be placed
# should be somewhere in your webserver's document root
DOC_DIR="/usr/local/apache/htdocs/maki"
#DOC_DIR="c:/maki/docs"
#DOC_DIR="/var/www/html/maki"
# the user id that your webserver/appserver runs as
# not relevent on Windows
WEB_USER="nobody"
#WEB_USER="apache"
# where to install maki and related modules
# if None, this script will try to figure out a reasonable
# location. It is safe to leave this set to None unless you
# really want the modules installed in a specific place, or if
# this script can't figure out a location for you.
MODULE_DIR=None
#################################################################
# Do not change anything beyond this point!
#################################################################
import site
import sys
import compileall
import string
import os
import shutil
isUnix = 1
try: import pwd
except: isUnix = 0
#############################################
def writeFile(fn, data):
f = open(fn, "w")
f.write(data)
f.close()
def getFile(fn):
f = open(fn)
data = f.read()
f.close()
return data
def makeDir(path):
if(not os.path.isdir(path)): os.makedirs(path)
def copyDirContents(src, dest):
for f in os.listdir(src):
#shutil.copyfile(src+"/"+f, dest+"/"+f)
if(os.path.isdir(src+"/"+f)):
makeDir(dest+"/"+f)
copyDirContents(src+"/"+f, dest+"/"+f)
else:
shutil.copyfile(src+"/"+f, dest+"/"+f)
def removeDirContents(path):
for f in os.listdir(path):
if(os.path.isdir(path+"/"+f)):
removeDirContents(path+"/"+f)
os.rmdir(path+"/"+f)
else:
os.remove(path+"/"+f)
def ensureFileExists(fn):
if(not os.path.isfile(fn)):
writeFile(fn, "")
def changeOwner(path, username):
if(isUnix):
entry = pwd.getpwnam(username)
uid = entry[2]
gid = entry[3]
os.chown(path, uid, gid)
#############################################
VERSION=getFile("VERSION").strip()
if(not MODULE_DIR):
try:
for dir in site.sitedirs:
if(dir):
MODULE_DIR = dir
break
except:
pass
if(not MODULE_DIR):
try:
for dir in sys.path:
if(dir):
MODULE_DIR = dir
break
except:
pass
if(MODULE_DIR):
print "MODULE_DIR = "+MODULE_DIR
else:
raise RuntimeError, "Couldn't figure out where to install modules.\nPlease edit this script and\nexplicitly set MODULE_DIR."
INSTALL_DIR = MODULE_DIR + "/spb"
TRANSFORMER = None
# try to find the "best" xslt transformer
sys.stdout.write("Checking for 4xslt... ")
try:
import Ft.Xml.Xslt.Processor
print "found"
TRANSFORMER = '4xslt'
except:
print "not found"
sys.stdout.write("Checking for Pyana... ")
try:
import Pyana
print "found"
TRANSFORMER = 'Pyana'
except:
print "not found"
sys.stdout.write("Checking for Sablot... ")
try:
import Sablot
print "found"
TRANSFORMER = 'Sablot'
except:
print "not found"
sys.stdout.write("Checking for libxsltmod... ")
try:
import libxsltmod
print "found"
TRANSFORMER = 'libxsltmod'
except:
print "not found"
sys.stdout.write("Checking for libxslt... ")
try:
import libxml2, libxslt
print "found"
TRANSFORMER = 'libxslt'
except:
print "not found"
if(not TRANSFORMER): raise RuntimeError, "You don't seem to have any of the supported Python xslt modules.\nPlease install at least one, then try again."
makiVars = {}
makiVars["MAKI_DIR"] = MAKI_DIR
makiVars["VERSION"] = VERSION
makiVars["DOC_DIR"] = DOC_DIR
makiVars["TRANSFORMER"] = TRANSFORMER
print "- modules..."
makeDir(INSTALL_DIR)
copyDirContents("spb", INSTALL_DIR)
makiVarsTemplate = """MAKI_DIR = "%(MAKI_DIR)s"
VERSION = "%(VERSION)s"
"""
writeFile(INSTALL_DIR+"/makiVars.py", makiVarsTemplate % makiVars)
compileall.compile_dir(INSTALL_DIR)
# create the session directory
import spb.sessionVars
makeDir(spb.sessionVars.SESSION_DIRECTORY)
changeOwner(spb.sessionVars.SESSION_DIRECTORY, WEB_USER)
os.chmod(spb.sessionVars.SESSION_DIRECTORY, 0700)
print "- maki files..."
makeDir(MAKI_DIR)
makeDir(MAKI_DIR+"/logicsheets")
copyDirContents("logicsheets", MAKI_DIR+"/logicsheets")
if(os.path.isdir(MAKI_DIR+"/cache")):
# clear out old cache
removeDirContents(MAKI_DIR+"/cache")
makeDir(MAKI_DIR+"/cache")
changeOwner(MAKI_DIR+"/cache", WEB_USER)
os.chmod(MAKI_DIR+"/cache", 0700)
ensureFileExists(MAKI_DIR+"/maki.log")
changeOwner(MAKI_DIR+"/maki.log", WEB_USER)
os.chmod(MAKI_DIR+"/maki.log", 0744)
clobberConfigfile="y"
if(os.path.isfile(MAKI_DIR+"/maki-conf.xml")):
clobberConfigfile=raw_input("""You already have a maki config file.
If you've installed maki previously and customized the config file,
you probably want to keep that file.
Should I overwrite your existing config file with the simple default
config file? [no] """)
if(clobberConfigfile.startswith("y")): clobberConfigfile="y"
else: clobberConfigfile="n"
if(clobberConfigfile == "y"):
print "- creating config file..."
confTemplate = getFile("maki-conf.xml.dist")
writeFile(MAKI_DIR+"/maki-conf.xml", confTemplate % makiVars)
shutil.copyfile("examples-conf.xml.dist", MAKI_DIR+"/examples-conf.xml")
print "- scripts..."
makeDir(MAKI_DIR+"/scripts")
copyDirContents("scripts", MAKI_DIR+"/scripts")
print "- examples files..."
makeDir(DOC_DIR+"/examples")
copyDirContents("examples", DOC_DIR+"/examples")
print "- manual files..."
makeDir(DOC_DIR+"/manual")
copyDirContents("manual", DOC_DIR+"/manual")
shutil.copyfile("index.xml", DOC_DIR+"/index.xml")
shutil.copyfile("index.xsl", DOC_DIR+"/index.xsl")
shutil.copyfile("maki_header.gif", DOC_DIR+"/maki_header.gif")
print "Done."
|