|
a/Allura/allura/lib/plugin.py |
|
b/Allura/allura/lib/plugin.py |
|
... |
|
... |
4 |
import re
|
4 |
import re
|
5 |
import os
|
5 |
import os
|
6 |
import logging
|
6 |
import logging
|
7 |
import subprocess
|
7 |
import subprocess
|
8 |
|
8 |
|
|
|
9 |
from urllib2 import urlopen
|
|
|
10 |
from cStringIO import StringIO
|
9 |
from random import randint
|
11 |
from random import randint
|
10 |
from hashlib import sha256
|
12 |
from hashlib import sha256
|
11 |
from base64 import b64encode
|
13 |
from base64 import b64encode
|
12 |
from datetime import datetime
|
14 |
from datetime import datetime
|
13 |
|
15 |
|
|
... |
|
... |
338 |
raise ValueError('Invalid project shortname: %s' % shortname)
|
340 |
raise ValueError('Invalid project shortname: %s' % shortname)
|
339 |
try:
|
341 |
try:
|
340 |
p = M.Project.query.get(shortname=shortname, neighborhood_id=neighborhood._id)
|
342 |
p = M.Project.query.get(shortname=shortname, neighborhood_id=neighborhood._id)
|
341 |
if p:
|
343 |
if p:
|
342 |
raise forge_exc.ProjectConflict()
|
344 |
raise forge_exc.ProjectConflict()
|
|
|
345 |
project_template = neighborhood.get_project_template()
|
343 |
p = M.Project(neighborhood_id=neighborhood._id,
|
346 |
p = M.Project(neighborhood_id=neighborhood._id,
|
344 |
shortname=shortname,
|
347 |
shortname=shortname,
|
345 |
name=project_name,
|
348 |
name=project_name,
|
346 |
short_description='',
|
349 |
short_description='',
|
347 |
description=('You can edit this description in the admin page'),
|
350 |
description=('You can edit this description in the admin page'),
|
|
... |
|
... |
350 |
last_updated = datetime.utcnow(),
|
353 |
last_updated = datetime.utcnow(),
|
351 |
is_root=True)
|
354 |
is_root=True)
|
352 |
p.configure_project(
|
355 |
p.configure_project(
|
353 |
users=[user],
|
356 |
users=[user],
|
354 |
is_user_project=user_project,
|
357 |
is_user_project=user_project,
|
355 |
is_private_project=private_project,
|
358 |
is_private_project=private_project or project_template.get('private', False),
|
356 |
apps=apps)
|
359 |
apps=apps or [] if 'tools' in project_template else None)
|
|
|
360 |
|
|
|
361 |
# Setup defaults from neighborhood project template if applicable
|
|
|
362 |
offset = p.next_mount_point(include_search=True)
|
|
|
363 |
if 'tools' in project_template:
|
|
|
364 |
for i, tool in enumerate(project_template['tools'].keys()):
|
|
|
365 |
tool_config = project_template['tools'][tool]
|
|
|
366 |
app = p.install_app(tool,
|
|
|
367 |
mount_label=tool_config['label'],
|
|
|
368 |
mount_point=tool_config['mount_point'],
|
|
|
369 |
ordinal=i+offset)
|
|
|
370 |
if 'options' in tool_config:
|
|
|
371 |
for option in tool_config['options']:
|
|
|
372 |
app.config.options[option] = tool_config['options'][option]
|
|
|
373 |
if 'tool_order' in project_template:
|
|
|
374 |
for i, tool in enumerate(project_template['tool_order']):
|
|
|
375 |
p.app_config(tool).options.ordinal = i
|
|
|
376 |
if 'labels' in project_template:
|
|
|
377 |
p.labels = project_template['labels']
|
|
|
378 |
if 'trove_cats' in project_template:
|
|
|
379 |
for trove_type in project_template['trove_cats'].keys():
|
|
|
380 |
troves = getattr(p, 'trove_%s' % trove_type)
|
|
|
381 |
for trove_id in project_template['trove_cats'][trove_type]:
|
|
|
382 |
troves.append(M.TroveCategory.query.get(trove_cat_id=trove_id)._id)
|
|
|
383 |
if 'home_options' in project_template and p.app_config('home'):
|
|
|
384 |
options = p.app_config('home').options
|
|
|
385 |
for option in project_template['home_options'].keys():
|
|
|
386 |
options[option] = project_template['home_options'][option]
|
|
|
387 |
if 'icon' in project_template:
|
|
|
388 |
icon_file = StringIO(urlopen(project_template['icon']['url']).read())
|
|
|
389 |
M.ProjectFile.save_image(
|
|
|
390 |
project_template['icon']['filename'], icon_file,
|
|
|
391 |
square=True, thumbnail_size=(48, 48),
|
|
|
392 |
thumbnail_meta=dict(project_id=p._id, category='icon'))
|
|
|
393 |
home_app = p.app_instance('home')
|
|
|
394 |
if home_app:
|
|
|
395 |
from forgewiki import model as WM
|
|
|
396 |
text = project_template.get('home_text',
|
|
|
397 |
'[[project_admins]]\n[[download_button]]')
|
|
|
398 |
WM.Page.query.get(app_config_id=home_app.config._id).text = text
|
357 |
except forge_exc.ProjectConflict:
|
399 |
except forge_exc.ProjectConflict:
|
358 |
raise
|
400 |
raise
|
359 |
except:
|
401 |
except:
|
360 |
ThreadLocalORMSession.close_all()
|
402 |
ThreadLocalORMSession.close_all()
|
361 |
log.exception('Error registering project %s' % p)
|
403 |
log.exception('Error registering project %s' % p)
|