From e3f8bfcfd01042d609c191f71fc785db047a4d3e Mon Sep 17 00:00:00 2001 From: Oskar Hahn Date: Sat, 4 Aug 2012 20:59:27 +0200 Subject: [PATCH] update setup.py to make an openslides module --- .gitignore | 2 + MANIFEST.in | 23 ++++- openslides/__init__.py | 2 +- openslides/default.settings.py | 29 ------ openslides/main.py | 148 +++++++++++++++++------------- openslides/openslides_settings.py | 12 --- setup.py | 11 ++- 7 files changed, 118 insertions(+), 109 deletions(-) delete mode 100644 openslides/default.settings.py diff --git a/.gitignore b/.gitignore index 1cafbf7b3..c17fd65ee 100644 --- a/.gitignore +++ b/.gitignore @@ -9,3 +9,5 @@ extras/website/* extras/website-old/* docs/_build/* *.egg-info +build/* +dist/* diff --git a/MANIFEST.in b/MANIFEST.in index 6bf92a5f7..d028d548b 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -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 diff --git a/openslides/__init__.py b/openslides/__init__.py index 6e440cbbb..77f92322b 100644 --- a/openslides/__init__.py +++ b/openslides/__init__.py @@ -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.""" diff --git a/openslides/default.settings.py b/openslides/default.settings.py deleted file mode 100644 index 39599f79e..000000000 --- a/openslides/default.settings.py +++ /dev/null @@ -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 diff --git a/openslides/main.py b/openslides/main.py index 91f4156d3..2c62b851f 100644 --- a/openslides/main.py +++ b/openslides/main.py @@ -19,6 +19,7 @@ import optparse import socket import time import threading +import base64 import webbrowser from contextlib import nested @@ -28,50 +29,95 @@ from django.utils.crypto import get_random_string import openslides +CONFIG_TEMPLATE = """ +from openslides.openslides_settings import * -def main(argv = None): +# 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.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", - help = "Do not use threading") - parser.add_option("--syncdb", action = "store_true", - help = "Update/create database before starting the server") - parser.add_option("--reset-admin", action = "store_true", - help = "Make sure the user 'admin' exists and uses 'admin' as password") + 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", + help="Do not use threading") + parser.add_option("--syncdb", action="store_true", + help="Update/create database before starting the server") + parser.add_option("--reset-admin", action="store_true", + 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) - # NOTE: --insecure is needed so static files will be served if - # DEBUG is set to False - argv = ["", "runserver", "--noreload", "--insecure"] - if opts.nothread: - argv.append("--nothread") + 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"] + if opts.nothread: + argv.append("--nothread") - argv.append("%s:%d" % (addr, port)) + argv.append("%s:%d" % (addr, port)) - start_browser(url) - execute_from_command_line(argv) + start_browser(url) + 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): @@ -106,51 +152,33 @@ 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) - set_system_url(url) + if url is not None: + set_system_url(url) def check_database(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() diff --git a/openslides/openslides_settings.py b/openslides/openslides_settings.py index 6486831dd..8de303633 100755 --- a/openslides/openslides_settings.py +++ b/openslides/openslides_settings.py @@ -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 diff --git a/setup.py b/setup.py index 07c67a521..6b2911a46 100644 --- a/setup.py +++ b/setup.py @@ -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', + ], + }, )