update setup.py to make an openslides module

This commit is contained in:
Oskar Hahn 2012-08-04 20:59:27 +02:00
parent 146a121606
commit e3f8bfcfd0
7 changed files with 118 additions and 109 deletions

2
.gitignore vendored
View File

@ -9,3 +9,5 @@ extras/website/*
extras/website-old/* extras/website-old/*
docs/_build/* docs/_build/*
*.egg-info *.egg-info
build/*
dist/*

View File

@ -1,10 +1,29 @@
include AUTHORS include AUTHORS
include LICENSE
include INSTALL.txt
include CHANGELOG include CHANGELOG
include initial_data.json include initial_data.json
include INSTALL.txt
include LICENSE
include manage.py include manage.py
include README.txt
include THANKS include THANKS
recursive-include openslides/static * recursive-include openslides/static *
recursive-include openslides/templates *
recursive-include openslides/agenda/templates *
recursive-include openslides/agenda/static *
recursive-include openslides/application/templates *
recursive-include openslides/application/static *
recursive-include openslides/assignment/templates *
recursive-include openslides/assignment/static *
recursive-include openslides/config/templates *
recursive-include openslides/config/static *
recursive-include openslides/participant/templates *
recursive-include openslides/participant/static *
recursive-include openslides/poll/templates *
recursive-include openslides/poll/static *
recursive-include openslides/projector/templates *
recursive-include openslides/projector/static *
recursive-include openslides/locale *.mo *.po recursive-include openslides/locale *.mo *.po
recursive-include openslides *.html recursive-include openslides *.html

View File

@ -5,7 +5,7 @@
:license: GNU GPL, see LICENSE for more details. :license: GNU GPL, see LICENSE for more details.
""" """
VERSION = (1, 2, 0, 'final', 1) VERSION = (1, 3, 0, 'alpha', 0)
def get_version(version=None): def get_version(version=None):
"""Derives a PEP386-compliant version number from VERSION.""" """Derives a PEP386-compliant version number from VERSION."""

View File

@ -1,29 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
openslides.default.settings
~~~~~~~~~~~~~~~~~~~~~~~~~~~
Global Django settings file for OpenSlides.
:copyright: 2011, 2012 by OpenSlides team, see AUTHORS.
:license: GNU GPL, see LICENSE for more details.
"""
from openslides_settings import *
# Use 'DEBUG = True' to get more details for server errors (Default for relaeses: 'False')
DEBUG = False
TEMPLATE_DEBUG = DEBUG
# Set timezone
TIME_ZONE = 'Europe/Berlin'
# Make this unique, and don't share it with anybody.
SECRET_KEY = '=(v@$58k$fcl4y8t2#q15y-9p=^45y&!$!ap$7xo6ub$akg-!5'
# Add OpenSlides plugins to this list (see example entry in comment)
INSTALLED_PLUGINS = (
# 'pluginname',
)
INSTALLED_APPS += INSTALLED_PLUGINS

View File

@ -19,6 +19,7 @@ import optparse
import socket import socket
import time import time
import threading import threading
import base64
import webbrowser import webbrowser
from contextlib import nested from contextlib import nested
@ -28,13 +29,48 @@ from django.utils.crypto import get_random_string
import openslides import openslides
CONFIG_TEMPLATE = """
from openslides.openslides_settings import *
# Use 'DEBUG = True' to get more details for server errors (Default for relaeses: 'False')
DEBUG = False
TEMPLATE_DEBUG = DEBUG
DBPATH = %(dbpath)r
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': DBPATH,
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
# Set timezone
TIME_ZONE = 'Europe/Berlin'
# Make this unique, and don't share it with anybody.
SECRET_KEY = %(default_key)r
# Add OpenSlides plugins to this list (see example entry in comment)
INSTALLED_PLUGINS = (
# 'pluginname',
)
INSTALLED_APPS += INSTALLED_PLUGINS
"""
KEY_LENGTH = 30
def main(argv=None): def main(argv=None):
if argv is None: if argv is None:
argv = sys.argv[1:] argv = sys.argv[1:]
parser = optparse.OptionParser(description = "Run openslides using " parser = optparse.OptionParser(
"django's builtin webserver") description="Run openslides using django's builtin webserver")
parser.add_option("-a", "--address", help="IP Address to listen on") parser.add_option("-a", "--address", help="IP Address to listen on")
parser.add_option("-p", "--port", type="int", help="Port to listen on") parser.add_option("-p", "--port", type="int", help="Port to listen on")
parser.add_option("--nothread", action="store_true", parser.add_option("--nothread", action="store_true",
@ -45,23 +81,28 @@ def main(argv = None):
help="Make sure the user 'admin' exists and uses 'admin' as password") help="Make sure the user 'admin' exists and uses 'admin' as password")
opts, args = parser.parse_args(argv) opts, args = parser.parse_args(argv)
if args: if not args:
sys.stderr.write("This command does not take arguments!\n\n")
parser.print_help() parser.print_help()
sys.exit(1) sys.exit(1)
command = args[0]
addr, port = detect_listen_opts(opts.address, opts.port) addr, port = detect_listen_opts(opts.address, opts.port)
if port == 80: if port == 80:
url = "http://%s" % (addr, ) url = "http://%s" % (addr, )
else: else:
url = "http://%s:%d" % (addr, port) url = "http://%s:%d" % (addr, port)
if not prepare_openslides(url, opts.syncdb): try:
sys.exit(1) environment_name = args[1]
except IndexError:
environment_name = None
if opts.reset_admin: if command == 'init':
create_or_reset_admin_user() create_environment(environment_name or 'openslides', url)
elif command == 'start':
set_setting_environment(environment_name or os.getcwd())
# NOTE: --insecure is needed so static files will be served if # NOTE: --insecure is needed so static files will be served if
# DEBUG is set to False # DEBUG is set to False
argv = ["", "runserver", "--noreload", "--insecure"] argv = ["", "runserver", "--noreload", "--insecure"]
@ -74,6 +115,11 @@ def main(argv = None):
execute_from_command_line(argv) execute_from_command_line(argv)
def set_setting_environment(environment):
sys.path.append(environment)
os.environ[django.conf.ENVIRONMENT_VARIABLE] = 'settings'
def detect_listen_opts(address, port): def detect_listen_opts(address, port):
if address is None: if address is None:
try: try:
@ -106,50 +152,32 @@ def start_browser(url):
t.start() t.start()
def prepare_openslides(url, always_syncdb = False): def create_environment(environment, url=None):
settings_module = os.environ.get(django.conf.ENVIRONMENT_VARIABLE) output = CONFIG_TEMPLATE % dict(
if not settings_module: default_key=base64.b64encode(os.urandom(KEY_LENGTH)),
os.environ[django.conf.ENVIRONMENT_VARIABLE] = "openslides.settings" dbpath=os.path.join(os.path.abspath(environment), 'database.db'))
settings_module = "openslides.settings"
try: dirname = environment
# settings is a lazy object, force the settings module if dirname and not os.path.exists(dirname):
# to be imported os.makedirs(dirname)
getattr(django.conf.settings, "DATABASES", None)
except ImportError:
pass
else:
if not check_database(url) and always_syncdb:
run_syncdb(url)
return True # import worked, settings are already configured
setting = os.path.join(environment, 'settings.py')
if settings_module != "openslides.settings": with open(setting, 'w') as fp:
sys.stderr.write("Settings module '%s' cannot be imported.\n" fp.write(output)
% (django.conf.ENVIRONMENT_VARIABLE, ))
return False
openslides_dir = os.path.dirname(openslides.__file__)
src_fp = os.path.join(openslides_dir, "default.settings.py")
dest_fp = os.path.join(openslides_dir, "settings.py")
with nested(open(dest_fp, "w"), open(src_fp, "r")) as (dest, src):
for l in src:
if l.startswith("SECRET_KEY ="):
l = "SECRET_KEY = '%s'\n" % (generate_secret_key(), )
dest.write(l)
set_setting_environment(environment)
run_syncdb(url) run_syncdb(url)
create_or_reset_admin_user() create_or_reset_admin_user()
return True
def run_syncdb(url): def run_syncdb(url=None):
# now initialize the database # now initialize the database
argv = ["", "syncdb", "--noinput"] argv = ["", "syncdb", "--noinput"]
execute_from_command_line(argv) execute_from_command_line(argv)
if url is not None:
set_system_url(url) set_system_url(url)
@ -201,11 +229,5 @@ def set_system_url(url):
config[key] = url config[key] = url
def generate_secret_key():
# same chars/ length as used in djangos startproject command
chars = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
return get_random_string(50, chars)
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -30,18 +30,6 @@ LOGIN_REDIRECT_URL = '/'
SESSION_COOKIE_NAME = 'OpenSlidesSessionID' SESSION_COOKIE_NAME = 'OpenSlidesSessionID'
DBPATH = _fs2unicode(os.path.join(os.path.join(SITE_ROOT, '..'), 'database.db'))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': DBPATH,
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
}
}
ugettext = lambda s: s ugettext = lambda s: s

View File

@ -11,6 +11,7 @@ from setuptools import setup
from setuptools import find_packages from setuptools import find_packages
from openslides import get_version from openslides import get_version
setup( setup(
name='openslides', name='openslides',
description='Presentation-System', description='Presentation-System',
@ -35,8 +36,14 @@ setup(
'versiontools >= 1.6', 'versiontools >= 1.6',
], ],
install_requires=[ install_requires=[
'django >= 1.3', 'django >= 1.4',
'django-mptt',
'reportlab', 'reportlab',
'pil', 'pil',
] ],
entry_points={
'console_scripts': [
'openslides = openslides.main:main',
],
},
) )