Added setup options.

This commit is contained in:
Raoul Snyman 2010-04-14 08:47:53 +02:00
parent ff0e6e0093
commit 74054e69a4
3 changed files with 52 additions and 42 deletions

View File

@ -53,6 +53,11 @@ mail.smtp.password = mymailpassword
# Server-related settings # Server-related settings
server.timezone = 'Africa/Johannesburg' server.timezone = 'Africa/Johannesburg'
# Setup options
setup.create_tables = true
setup.create_user = false
setup.blog_details = false
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* # WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
# Debug mode will enable the interactive debugging tool, allowing ANYONE to # Debug mode will enable the interactive debugging tool, allowing ANYONE to
# execute malicious code after an exception is raised. # execute malicious code after an exception is raised.

View File

@ -53,6 +53,11 @@ mail.smtp.password = mymailpassword
# Server-related settings # Server-related settings
server.timezone = 'Africa/Johannesburg' server.timezone = 'Africa/Johannesburg'
# Setup options (for when you run "paster setup-app config.ini")
setup.create_tables = true
setup.create_user = false
setup.blog_details = false
# WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT* # WARNING: *THE LINE BELOW MUST BE UNCOMMENTED ON A PRODUCTION ENVIRONMENT*
# Debug mode will enable the interactive debugging tool, allowing ANYONE to # Debug mode will enable the interactive debugging tool, allowing ANYONE to
# execute malicious code after an exception is raised. # execute malicious code after an exception is raised.

View File

@ -23,9 +23,14 @@
""" """
Setup the ScribeEngine application Setup the ScribeEngine application
""" """
import os
import hashlib
import hmac
import logging import logging
from datetime import datetime from datetime import datetime
from paste.deploy.converters import asbool
from scribeengine.config.environment import load_environment from scribeengine.config.environment import load_environment
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -35,22 +40,24 @@ def setup_app(command, conf, vars):
conf.local_conf['setup-app'] = True conf.local_conf['setup-app'] = True
load_environment(conf.global_conf, conf.local_conf) load_environment(conf.global_conf, conf.local_conf)
import os
import hashlib
import hmac
from scribeengine.model.meta import metadata, Session, engine from scribeengine.model.meta import metadata, Session, engine
from scribeengine.model import Category, Permission, Post, Variable, \ from scribeengine.model import Category, Permission, Post, Variable, \
User, Role User, Role
if os.name == 'posix': if os.name == u'posix':
import readline import readline
# Let's prompt the user for an e-mail address, password and nick for the first user in the system. if asbool(conf.local_conf[u'setup.create_tables']):
# Create the tables if they don't already exist
metadata.create_all(bind=engine, checkfirst=True)
if asbool(conf.local_conf[u'setup.create_user']):
# Let's prompt the user for an e-mail address, password and nick for the
# first user in the system.
print 'First User:' print 'First User:'
email = raw_input('E-mail address [admin@scribeengine.org]: ') email = raw_input('E-mail address [admin@scribeengine.org]: ')
password = raw_input('Password [P@ssw0rd]: ') password = raw_input('Password [P@ssw0rd]: ')
nick = raw_input('Nick [Admin]: ') nick = raw_input('Nick [Admin]: ')
if not email: if not email:
email = u'admin@scribeengine.org' email = u'admin@scribeengine.org'
else: else:
@ -65,25 +72,18 @@ def setup_app(command, conf, vars):
nick = unicode(nick) nick = unicode(nick)
password = unicode(hmac.new(conf[u'security.salt'], password, password = unicode(hmac.new(conf[u'security.salt'], password,
hashlib.sha256).hexdigest(), u'utf-8') hashlib.sha256).hexdigest(), u'utf-8')
# Create the tables if they don't already exist
metadata.create_all(bind=engine, checkfirst=True)
blog_title = Variable(key=u'blog title', value=u'ScribeEngine')
blog_slogan = Variable(key=u'blog slogan', value=u'open source blog software')
pylons_cat = Category(name=u'Pylons', url=u'pylons')
database_cat = Category(name=u'Database', url=u'database')
perm_addposts = Permission(name=u'Add Posts') perm_addposts = Permission(name=u'Add Posts')
perm_editmyposts = Permission(name=u'Edit My Posts') perm_editmyposts = Permission(name=u'Edit My Posts')
perm_delmyposts = Permission(name=u'Delete My Posts') perm_delmyposts = Permission(name=u'Delete My Posts')
role_admin = Role(name=u'Administrator') role_admin = Role(name=u'Administrator')
role_admin.permissions.extend([perm_addposts, perm_editmyposts, perm_delmyposts]) role_admin.permissions.extend([perm_addposts, perm_editmyposts, perm_delmyposts])
user = User(email=email, password=password, nick=nick) user = User(email=email, password=password, nick=nick)
user.roles.append(role_admin) user.roles.append(role_admin)
Session.add(user)
if asbool(conf.local_conf[u'setup.blog_details']):
blog_title = Variable(key=u'blog title', value=u'ScribeEngine')
blog_slogan = Variable(key=u'blog slogan', value=u'open source blog software')
Session.add_all([blog_title, blog_slogan])
Session.add_all([blog_title, blog_slogan, user])
Session.commit() Session.commit()