2010-01-15 20:55:30 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# ScribeEngine - Open Source Blog Software #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# Copyright (c) 2010 Raoul Snyman #
|
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# This program is free software; you can redistribute it and/or modify it #
|
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
|
|
|
# Software Foundation; version 2 of the License. #
|
|
|
|
# #
|
|
|
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
|
|
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
|
|
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
|
|
|
###############################################################################
|
|
|
|
|
|
|
|
"""
|
|
|
|
Setup the ScribeEngine application
|
|
|
|
"""
|
|
|
|
import logging
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from scribeengine.config.environment import load_environment
|
|
|
|
|
|
|
|
log = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
def setup_app(command, conf, vars):
|
|
|
|
"""Place any commands to setup scribeengine here"""
|
2010-01-18 20:04:49 +00:00
|
|
|
conf.local_conf['setup-app'] = True
|
2010-01-15 20:55:30 +00:00
|
|
|
load_environment(conf.global_conf, conf.local_conf)
|
|
|
|
|
2010-01-19 09:08:44 +00:00
|
|
|
import os
|
2010-01-15 20:55:30 +00:00
|
|
|
import hashlib
|
|
|
|
import hmac
|
|
|
|
from scribeengine.model.meta import metadata, Session, engine
|
|
|
|
from scribeengine.model import Category, Permission, Post, Variable, \
|
|
|
|
User, Role
|
|
|
|
|
2010-01-19 09:08:44 +00:00
|
|
|
if os.name == 'posix':
|
|
|
|
import readline
|
|
|
|
|
|
|
|
# Let's prompt the user for an e-mail address, password and nick for the first user in the system.
|
|
|
|
print 'First User:'
|
|
|
|
email = raw_input('E-mail address [admin@scribeengine.org]: ')
|
|
|
|
password = raw_input('Password [P@ssw0rd]: ')
|
|
|
|
nick = raw_input('Nick [Admin]: ')
|
|
|
|
|
|
|
|
if not email:
|
|
|
|
email = u'admin@scribeengine.org'
|
|
|
|
else:
|
|
|
|
email = unicode(email)
|
|
|
|
if not password:
|
|
|
|
password = u'P@ssw0rd'
|
|
|
|
else:
|
|
|
|
password = unicode(password)
|
|
|
|
if not nick:
|
|
|
|
nick = u'Admin'
|
|
|
|
else:
|
|
|
|
nick = unicode(nick)
|
|
|
|
password = unicode(hmac.new(conf[u'security.salt'], password,
|
|
|
|
hashlib.sha256).hexdigest(), u'utf-8')
|
|
|
|
|
2010-01-15 20:55:30 +00:00
|
|
|
# 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_editmyposts = Permission(name=u'Edit My Posts')
|
|
|
|
perm_delmyposts = Permission(name=u'Delete My Posts')
|
|
|
|
|
|
|
|
role_admin = Role(name=u'Administrator')
|
|
|
|
role_admin.permissions.extend([perm_addposts, perm_editmyposts, perm_delmyposts])
|
|
|
|
|
2010-01-19 09:08:44 +00:00
|
|
|
user = User(email=email, password=password, nick=nick)
|
2010-01-15 20:55:30 +00:00
|
|
|
user.roles.append(role_admin)
|
|
|
|
|
|
|
|
Session.add_all([blog_title, blog_slogan, user])
|
|
|
|
Session.commit()
|