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/*
docs/_build/*
*.egg-info
build/*
dist/*

View File

@ -1,10 +1,29 @@
include AUTHORS
include LICENSE
include INSTALL.txt
include CHANGELOG
include initial_data.json
include INSTALL.txt
include LICENSE
include manage.py
include README.txt
include THANKS
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 *.html

View File

@ -5,7 +5,7 @@
: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):
"""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 time
import threading
import base64
import webbrowser
from contextlib import nested
@ -28,13 +29,48 @@ from django.utils.crypto import get_random_string
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):
if argv is None:
argv = sys.argv[1:]
parser = optparse.OptionParser(description = "Run openslides using "
"django's builtin webserver")
parser = optparse.OptionParser(
description="Run openslides using django's builtin webserver")
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("--nothread", action="store_true",
@ -45,23 +81,28 @@ def main(argv = None):
help="Make sure the user 'admin' exists and uses 'admin' as password")
opts, args = parser.parse_args(argv)
if args:
sys.stderr.write("This command does not take arguments!\n\n")
if not args:
parser.print_help()
sys.exit(1)
command = args[0]
addr, port = detect_listen_opts(opts.address, opts.port)
if port == 80:
url = "http://%s" % (addr, )
else:
url = "http://%s:%d" % (addr, port)
if not prepare_openslides(url, opts.syncdb):
sys.exit(1)
try:
environment_name = args[1]
except IndexError:
environment_name = None
if opts.reset_admin:
create_or_reset_admin_user()
if command == 'init':
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
# DEBUG is set to False
argv = ["", "runserver", "--noreload", "--insecure"]
@ -74,6 +115,11 @@ def main(argv = None):
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):
if address is None:
try:
@ -106,50 +152,32 @@ def start_browser(url):
t.start()
def prepare_openslides(url, always_syncdb = False):
settings_module = os.environ.get(django.conf.ENVIRONMENT_VARIABLE)
if not settings_module:
os.environ[django.conf.ENVIRONMENT_VARIABLE] = "openslides.settings"
settings_module = "openslides.settings"
def create_environment(environment, url=None):
output = CONFIG_TEMPLATE % dict(
default_key=base64.b64encode(os.urandom(KEY_LENGTH)),
dbpath=os.path.join(os.path.abspath(environment), 'database.db'))
try:
# settings is a lazy object, force the settings module
# to be imported
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
dirname = environment
if dirname and not os.path.exists(dirname):
os.makedirs(dirname)
setting = os.path.join(environment, 'settings.py')
if settings_module != "openslides.settings":
sys.stderr.write("Settings module '%s' cannot be imported.\n"
% (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)
with open(setting, 'w') as fp:
fp.write(output)
set_setting_environment(environment)
run_syncdb(url)
create_or_reset_admin_user()
return True
def run_syncdb(url):
def run_syncdb(url=None):
# now initialize the database
argv = ["", "syncdb", "--noinput"]
execute_from_command_line(argv)
if url is not None:
set_system_url(url)
@ -201,11 +229,5 @@ def set_system_url(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__":
main()

View File

@ -30,18 +30,6 @@ LOGIN_REDIRECT_URL = '/'
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

View File

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