This repository has been archived on 2024-11-20. You can view files and clone it, but cannot push or open issues or pull requests.
old-scribeengine/scribeengine/websetup.py
2010-04-14 08:47:53 +02:00

90 lines
3.8 KiB
Python

# -*- 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 os
import hashlib
import hmac
import logging
from datetime import datetime
from paste.deploy.converters import asbool
from scribeengine.config.environment import load_environment
log = logging.getLogger(__name__)
def setup_app(command, conf, vars):
"""Place any commands to setup scribeengine here"""
conf.local_conf['setup-app'] = True
load_environment(conf.global_conf, conf.local_conf)
from scribeengine.model.meta import metadata, Session, engine
from scribeengine.model import Category, Permission, Post, Variable, \
User, Role
if os.name == u'posix':
import readline
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:'
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')
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])
user = User(email=email, password=password, nick=nick)
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.commit()