Here is the script. It's not a great example, but it works. It is
actually an apache handler....etc... Gotta go sleep. The formatting will
get mangled...so here goes.
from __future__ import with_statement
options = {"content_type": "text/plain"}
import os
from mod_python import apache
import shutil
try:
from mod_python.util import parse_qsl
except ImportError:
from cgi import parse_qsl
from trac.config import *
from trac.perm import PermissionSystem
from trac.env import open_environment
from acct_mgr.api import AccountManager
def handler(req):
# try:
req.content_type = 'text/plain'
query = get_env(req)
contractName = query['contractName']
contractNumber = query['contractNumber']
contractId = query['contractId']
officePhone = query['officePhone']
contractTeamTable = query['contractTeamTable']
contractTable = query['contractTable']
projectPath = 'C:/trac/%s-%s' % (contractName, contractNumber)
if os.path.exists(projectPath):
req.write("Project site already exists!")
return apache.OK
# copy project Template
shutil.copytree('C:/TracDev/backups/projectTemplate', projectPath)
# undo copy if necessary
try:
# edit trac.ini
config = Configuration(os.path.join(projectPath, 'conf',
'trac.ini'))
config.set('project', 'name', contractName)
config.set('project', 'contractId', contractId)
config.set('project', 'contractNumber', contractNumber)
config.set('project', 'officePhone', officePhone)
config.set('project', 'contractTeamTable', contractTeamTable)
config.set('project', 'contractTable', contractTable)
config.save()
# Save user
env = open_environment(projectPath, use_cache=False)
try:
mgr = AccountManager(env)
user = password = '%s-%s' % (contractName.lower(),
contractNumber)
mgr.set_password(user , password)
perm = PermissionSystem(env)
perm.grant_permission(user, 'client')
finally:
env.shutdown()
except Exception, e:
shutil.rmtree(projectPath)
raise e
else:
# respond
return apache.OK
# except :
# return apache.INTERNAL_SERVER_ERROR
def get_env(req):
# grab GET variables
req.add_common_vars()
req.content_type = options['content_type']
query = req.subprocess_env['QUERY_STRING']
# grab POST variables
if req.subprocess_env['REQUEST_METHOD'] == 'POST':
query += '&' + req.read()
# break down the urlencoded query string
query = parse_qsl(query)
http_var = dict(query)
return http_var
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac
Users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/trac-users?hl=en
-~----------~----~----~----~------~----~------~--~---