Beispiel #1
0
 def test_get_version(self):
     self.assertEqual(get_version((1, 3, 0, 'beta', 2)), '1.3-beta2')
     self.assertEqual(get_version((1, 0, 0, 'final', 0)), '1.0')
     self.assertEqual(get_version((2, 5, 3, 'alpha', 0)), '2.5.3-alpha0')
     git_version = get_version((2, 5, 0, 'dev', 0))
     if 'unknown' in git_version:
         self.assertEqual(len(git_version), 14)
     else:
         self.assertEqual(len(git_version), 47)
Beispiel #2
0
def process_options(argv=None, manage_runserver=False):
    if argv is None:
        argv = sys.argv[1:]

    parser = optparse.OptionParser(
        description="Run openslides using the tornado webserver")
    parser.add_option(
        "-a", "--address",
        help="IP Address to listen on. Default: 0.0.0.0")
    parser.add_option(
        "-p", "--port", type="int",
        help="Port to listen on. Default: 8000 (start as admin/root: 80)")
    parser.add_option(
        "--syncdb", action="store_true",
        help="Update/create database before starting the server.")
    parser.add_option(
        "--backupdb", action="store", metavar="BACKUP_PATH",
        help="Make a backup copy of the database to BACKUP_PATH.")
    parser.add_option(
        "--reset-admin", action="store_true",
        help="Make sure the user 'admin' exists and uses 'admin' as password.")
    parser.add_option(
        "-s", "--settings", help="Set the path to the settings file.")
    parser.add_option(
        "--no-browser",
        action="store_false", dest="start_browser", default=True,
        help="Do not automatically start the web browser.")
    parser.add_option(
        "--no-reload", action="store_true",
        help="Do not reload the web server.")
    parser.add_option(
        "--no-run", action="store_true",
        help="Do not start the web server.")
    parser.add_option(
        "--version", action="store_true",
        help="Show version and exit.")

    opts, args = parser.parse_args(argv)

    # Do not parse any argv if the script is started via manage.py runserver.
    # This simulates the django runserver command
    if manage_runserver:
        opts.start_browser = False
        opts.no_reload = False
        return opts

    if opts.version:
        print get_version()
        exit(0)

    if args:
        sys.stderr.write("This command does not take arguments!\n\n")
        parser.print_help()
        sys.exit(1)

    return opts
Beispiel #3
0
    def get_context_data(self, **kwargs):
        context = super(VersionConfig, self).get_context_data(**kwargs)
        context['versions'] = [('OpenSlides', get_version())]
        for plugin in settings.INSTALLED_PLUGINS:
            try:
                mod = import_module(plugin)
                plugin_version = get_version(mod.VERSION)
            except (ImportError, AttributeError, AssertionError):
                continue
            try:
                plugin_name = mod.NAME
            except AttributeError:
                plugin_name = mod.__name__.split('.')[0]

            context['versions'].append((plugin_name, plugin_version))
        return context
Beispiel #4
0
    def get_context_data(self, **kwargs):
        context = super(VersionConfig, self).get_context_data(**kwargs)
        context['versions'] = [('OpenSlides', get_version())]
        for plugin in settings.INSTALLED_PLUGINS:
            try:
                mod = import_module(plugin)
                plugin_version = get_version(mod.VERSION)
            except (ImportError, AttributeError, AssertionError):
                continue
            try:
                plugin_name = mod.NAME
            except AttributeError:
                plugin_name = mod.__name__.split('.')[0]

            context['versions'].append((plugin_name, plugin_version))
        return context
Beispiel #5
0
 def test_get_version(self):
     """
     Tests the method during development process and for releases.
     """
     self.assertEqual(get_version(version=(1, 3, 0, 'beta', 2), release=False), '1.3b2-dev')
     self.assertEqual(get_version(version=(1, 0, 0, 'final', 0), release=False), '1.0-dev')
     self.assertEqual(get_version(version=(2, 5, 3, 'alpha', 0), release=False), '2.5.3a0-dev')
     self.assertEqual(get_version(version=(1, 3, 0, 'beta', 2), release=True), '1.3b2')
     self.assertEqual(get_version(version=(1, 0, 0, 'final', 0), release=True), '1.0')
     self.assertEqual(get_version(version=(2, 5, 3, 'alpha', 0), release=True), '2.5.3a0')
     self.assertEqual(get_version(version=(2, 5, 3, 'final', 0), release=True), '2.5.3')
Beispiel #6
0
    def get_context_data(self, **kwargs):
        context = super(VersionConfig, self).get_context_data(**kwargs)

        # OpenSlides version. During development the git commit id is added.
        openslides_version_string = get_version()
        if not RELEASE:
            openslides_version_string += ' Commit: %s' % get_git_commit_id()
        context['versions'] = [('OpenSlides', openslides_version_string)]

        # Version of plugins.
        for plugin in settings.INSTALLED_PLUGINS:
            try:
                mod = import_module(plugin)
                plugin_version = get_version(mod.VERSION)
            except (ImportError, AttributeError, AssertionError):
                continue
            try:
                plugin_name = mod.NAME
            except AttributeError:
                plugin_name = mod.__name__.split('.')[0]
            context['versions'].append((plugin_name, plugin_version))
        return context
Beispiel #7
0
def process_options(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(
        "--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.add_option("-s",
                      "--settings",
                      help="Path to the openslides configuration.")
    parser.add_option("--no-reload",
                      action="store_true",
                      help="Do not reload the development server.")
    parser.add_option("--version",
                      action="store_true",
                      help="Show version and exit.")

    opts, args = parser.parse_args(argv)
    if opts.version:
        print get_version()
        exit(0)
    if args:
        sys.stderr.write("This command does not take arguments!\n\n")
        parser.print_help()
        sys.exit(1)

    return opts
Beispiel #8
0
    def get_context_data(self, **kwargs):
        """
        Adds version strings to the context.
        """
        context = super(VersionView, self).get_context_data(**kwargs)

        # OpenSlides version. During development the git commit id is added.
        openslides_version_string = get_version()
        if not RELEASE:
            openslides_version_string += ' – Commit %s' % get_git_commit_id()
        context['versions'] = [('OpenSlides', openslides_version_string)]

        # Versions of plugins.
        for plugin in settings.INSTALLED_PLUGINS:
            # Get plugin
            try:
                mod = import_module(plugin)
            except ImportError:
                continue

            # Get version.
            try:
                plugin_version = mod.get_version()
            except AttributeError:
                try:
                    plugin_version = mod.VERSION
                except AttributeError:
                    continue

            # Get name.
            try:
                plugin_name = mod.get_name()
            except AttributeError:
                try:
                    plugin_name = mod.NAME
                except AttributeError:
                    plugin_name = mod.__name__.split('.')[0]

            context['versions'].append((plugin_name, plugin_version))

        return context
Beispiel #9
0
    def get_context_data(self, **kwargs):
        """
        Adds version strings to the context.
        """
        context = super(VersionView, self).get_context_data(**kwargs)

        # OpenSlides version. During development the git commit id is added.
        openslides_version_string = get_version()
        if not RELEASE:
            openslides_version_string += ' – Commit %s' % get_git_commit_id()
        context['versions'] = [('OpenSlides', openslides_version_string)]

        # Versions of plugins.
        for plugin in settings.INSTALLED_PLUGINS:
            # Get plugin
            try:
                mod = import_module(plugin)
            except ImportError:
                continue

            # Get version.
            try:
                plugin_version = mod.get_version()
            except AttributeError:
                try:
                    plugin_version = mod.VERSION
                except AttributeError:
                    continue

            # Get name.
            try:
                plugin_name = mod.get_name()
            except AttributeError:
                try:
                    plugin_name = mod.NAME
                except AttributeError:
                    plugin_name = mod.__name__.split('.')[0]

            context['versions'].append((plugin_name, plugin_version))

        return context
def compile_openslides_launcher():
    try:
        cc = distutils.ccompiler.new_compiler()
        if not cc.initialized:
            cc.initialize()
    except distutils.errors.DistutilsError:
        return False

    cc.add_include_dir(distutils.sysconfig.get_python_inc())
    cc.define_macro("_CRT_SECURE_NO_WARNINGS")

    gui_data_dir = os.path.dirname(openslides_gui.__file__)
    gui_data_dir = os.path.join(gui_data_dir, "data")
    shutil.copyfile(
        os.path.join(gui_data_dir, "openslides.ico"),
        "extras/win32-portable/openslides.ico")
    rcfile = "extras/win32-portable/openslides.rc"
    with open(rcfile, "w") as f:
        if openslides.VERSION[3] == "final":
            file_flags = "0"
        else:
            file_flags = "VS_FF_PRERELEASE"

        f.write(OPENSLIDES_RC_TMPL.format(
            version=openslides.VERSION,
            version_str=openslides.get_version(),
            file_flags=file_flags))

    objs = cc.compile([
        "extras/win32-portable/openslides.c",
        rcfile,
    ])
    cc.link_executable(
        objs, "extras/win32-portable/openslides",
        extra_preargs=["/subsystem:windows", "/nodefaultlib:python27.lib"],
        libraries=["user32"]
    )
    return True
def openslides_launcher_update_version_resource():
    try:
        import win32api
        import win32verstamp
    except ImportError:
        sys.stderr.write(
            "Using precompiled executable and pywin32 is not available - "
            "version resource may be out of date!\n")
        return False
    import struct

    sys.stdout.write("Updating version resource")
    # code based on win32verstamp.stamp() with some minor differences in
    # version handling
    major, minor, sub = openslides.VERSION[:3]
    build = openslides.VERSION[4]
    pre_release = openslides.VERSION[3] != "final"
    version_str = openslides.get_version()

    sdata = {
        "CompanyName": "OpenSlides team",
        "FileDescription": "OpenSlides",
        "FileVersion": version_str,
        "InternalName": "OpenSlides",
        "LegalCopyright": u"Copyright \xa9 2011-2015",
        "OriginalFilename": "openslides.exe",
        "ProductName": "OpenSlides",
        "ProductVersion": version_str,
    }
    vdata = {
        "Translation": struct.pack("hh", 0x409, 0x4e4),
    }

    vs = win32verstamp.VS_VERSION_INFO(
        major, minor, sub, build, sdata, vdata, pre_release, False)
    h = win32api.BeginUpdateResource("extras/win32-portable/openslides.exe", 0)
    win32api.UpdateResource(h, 16, 1, vs)
    win32api.EndUpdateResource(h, 0)
Beispiel #12
0
def parse_args():
    """
    Parses all command line arguments. The subcommand 'django' links to
    Django's command-line utility.
    """
    if len(sys.argv) == 1:
        sys.argv.append("start")

    # Init parser
    description = "Start script for OpenSlides."
    if "manage.py" not in sys.argv[0]:
        description += (
            " If it is called without any argument, this will be "
            'treated as if it is called with the "start" subcommand. '
            "That means OpenSlides will setup default settings and "
            "database, start the tornado webserver, launch the "
            "default web browser and open the webinterface."
        )
    parser = argparse.ArgumentParser(description=description)

    # Add version argument
    parser.add_argument("--version", action="version", version=get_version(), help="Show version number and exit.")

    # Init subparsers
    subparsers = parser.add_subparsers(
        dest="subcommand",
        title="Available subcommands",
        description="Type '%s <subcommand> --help' for help on a " "specific subcommand." % parser.prog,
        help="You can choose only one subcommand at once.",
    )

    # Subcommand start
    subcommand_start = subparsers.add_parser(
        "start",
        help="Setup settings and database, start tornado webserver, launch the "
        "default web browser and open the webinterface.",
    )
    add_general_arguments(subcommand_start, ("settings", "user_data_path", "language", "address", "port"))
    subcommand_start.add_argument("--no-browser", action="store_true", help="Do not launch the default web browser.")
    subcommand_start.set_defaults(callback=start)

    # Subcommand runserver
    subcommand_runserver = subparsers.add_parser("runserver", help="Run OpenSlides using tornado webserver.")
    add_general_arguments(subcommand_runserver, ("settings", "user_data_path", "address", "port"))
    subcommand_runserver.add_argument(
        "--start-browser", action="store_true", help="Launch the default web browser and open the webinterface."
    )
    subcommand_runserver.add_argument(
        "--no-reload", action="store_true", help="Do not reload the webserver if source code changes."
    )
    subcommand_runserver.set_defaults(callback=runserver)

    # Subcommand syncdb
    subcommand_syncdb = subparsers.add_parser("syncdb", help="Create or update database tables.")
    add_general_arguments(subcommand_syncdb, ("settings", "user_data_path", "language"))
    subcommand_syncdb.set_defaults(callback=syncdb)

    # Subcommand createsuperuser
    subcommand_createsuperuser = subparsers.add_parser(
        "createsuperuser", help="Make sure the user 'admin' exists and uses 'admin' as password."
    )
    add_general_arguments(subcommand_createsuperuser, ("settings", "user_data_path"))
    subcommand_createsuperuser.set_defaults(callback=createsuperuser)

    # Subcommand backupdb
    subcommand_backupdb = subparsers.add_parser(
        "backupdb", help="Store a backup copy of the SQLite3 database at the given path."
    )
    add_general_arguments(subcommand_backupdb, ("settings", "user_data_path"))
    subcommand_backupdb.add_argument("path", help="Path to the backup file. An existing file will be overwritten.")
    subcommand_backupdb.set_defaults(callback=backupdb)

    # Subcommand deletedb
    subcommand_deletedb = subparsers.add_parser("deletedb", help="Delete the SQLite3 database.")
    add_general_arguments(subcommand_deletedb, ("settings", "user_data_path"))
    subcommand_deletedb.set_defaults(callback=deletedb)

    # Subcommand create-dev-settings
    subcommand_create_dev_settings = subparsers.add_parser(
        "create-dev-settings", help="Create a settings file at current working directory for development use."
    )
    subcommand_create_dev_settings.set_defaults(callback=create_dev_settings)

    # Subcommand django
    subcommand_django_command_line_utility = subparsers.add_parser(
        "django",
        description="Link to Django's command-line utility. Type "
        "'%s django help' for more help on this." % parser.prog,
        help="Call Django's command-line utility.",
    )
    subcommand_django_command_line_utility.set_defaults(
        callback=django_command_line_utility, django_args=["%s" % subcommand_django_command_line_utility.prog]
    )

    known_args, unknown_args = parser.parse_known_args()

    if known_args.subcommand == "django":
        if not unknown_args:
            unknown_args.append("help")
        known_args.django_args.extend(unknown_args)
    else:
        if unknown_args:
            parser.error("Unknown arguments %s found." % " ".join(unknown_args))

    return known_args
def main():
    prefix = os.path.dirname(sys.executable)
    libdir = os.path.join(prefix, "Lib")
    sitedir = os.path.join(libdir, "site-packages")
    odir = "dist/openslides-{0}-portable".format(openslides.get_version())

    try:
        shutil.rmtree(odir)
    except OSError as e:
        if e.errno != errno.ENOENT:
            raise

    os.makedirs(odir)
    out_site_packages = os.path.join(odir, "Lib", "site-packages")

    collect_lib(libdir, odir)
    collect_site_packages(sitedir, out_site_packages)

    exclude = get_pkg_exclude("openslides")
    copy_dir_exclude(exclude, ".", "openslides", out_site_packages)

    if not compile_openslides_launcher():
        sys.stdout.write("Using prebuild openslides.exe\n")
        openslides_launcher_update_version_resource()

    shutil.copyfile(
        "extras/win32-portable/openslides.exe",
        os.path.join(odir, "openslides.exe"))

    shutil.copytree(
        "extras/openslides_gui",
        os.path.join(out_site_packages, "openslides_gui"))

    copy_dlls(odir)
    copy_msvcr(odir)

    # Info on included packages
    shutil.copytree(
        "extras/win32-portable/licenses",
        os.path.join(odir, "packages-info"))
    write_package_info_content(os.path.join(odir, 'packages-info', 'PACKAGES.txt'))

    # Create plugins directory with README.txt
    plugindir = os.path.join(odir, "openslides", "plugins")
    os.makedirs(plugindir)
    readmetext = ["Please copy your plugin directory into this directory.\n", "\n",
        "For more information about OpenSlides plugins see:\n",
        "https://github.com/OpenSlides/OpenSlides/wiki/De%3APlugins\n"]
    with open(os.path.join(plugindir, 'README.txt'), "w") as readme:
        readme.writelines(readmetext)

    # AUTHORS, LICENSE, README
    write_metadatafile('AUTHORS', os.path.join(odir, 'AUTHORS.txt'))
    write_metadatafile('LICENSE', os.path.join(odir, 'LICENSE.txt'))
    write_metadatafile('README.rst', os.path.join(odir, 'README.txt'))

    zip_fp = os.path.join(
        "dist", "openslides-{0}-portable.zip".format(
        openslides.get_version()))


    with zipfile.ZipFile(zip_fp, "w", zipfile.ZIP_DEFLATED) as zf:
        for dp, dnames, fnames in os.walk(odir):
            for fn in fnames:
                fp = os.path.join(dp, fn)
                rp = relpath(odir, fp)
                zf.write(fp, rp)

    print("Successfully build {0}".format(zip_fp))
Beispiel #14
0
 def test_get(self):
     response = self.client.get('/version/')
     self.assertContains(response, get_version(), status_code=200)
Beispiel #15
0
def parse_args():
    """
    Parses all command line arguments. The subcommand 'django' links to
    Django's command-line utility.
    """
    if len(sys.argv) == 1:
        sys.argv.append('start')

    # Init parser
    description = 'Start script for OpenSlides.'
    if 'manage.py' not in sys.argv[0]:
        description += (
            ' If it is called without any argument, this will be '
            'treated as if it is called with the "start" subcommand. '
            'That means OpenSlides will setup default settings and '
            'database, start the tornado webserver, launch the '
            'default web browser and open the webinterface.')
    parser = argparse.ArgumentParser(description=description)

    # Add version argument
    parser.add_argument('--version',
                        action='version',
                        version=get_version(),
                        help='Show version number and exit.')

    # Init subparsers
    subparsers = parser.add_subparsers(
        dest='subcommand',
        title='Available subcommands',
        description="Type '%s <subcommand> --help' for help on a "
        "specific subcommand." % parser.prog,
        help='You can choose only one subcommand at once.')

    # Subcommand start
    subcommand_start = subparsers.add_parser(
        'start',
        help='Setup settings and database, start tornado webserver, launch the '
        'default web browser and open the webinterface.')
    add_general_arguments(
        subcommand_start,
        ('settings', 'user_data_path', 'language', 'address', 'port'))
    subcommand_start.add_argument(
        '--no-browser',
        action='store_true',
        help='Do not launch the default web browser.')
    subcommand_start.set_defaults(callback=start)

    # Subcommand runserver
    subcommand_runserver = subparsers.add_parser(
        'runserver',
        help='Run OpenSlides using tornado webserver. The database tables must '
        'be created before. Use syncdb subcommand for this.')
    add_general_arguments(subcommand_runserver,
                          ('settings', 'user_data_path', 'address', 'port'))
    subcommand_runserver.add_argument(
        '--start-browser',
        action='store_true',
        help='Launch the default web browser and open the webinterface.')
    subcommand_runserver.set_defaults(callback=runserver)

    # Subcommand syncdb
    subcommand_syncdb = subparsers.add_parser(
        'syncdb', help='Create or update database tables.')
    add_general_arguments(subcommand_syncdb,
                          ('settings', 'user_data_path', 'language'))
    subcommand_syncdb.set_defaults(callback=syncdb)

    # Subcommand createsuperuser
    subcommand_createsuperuser = subparsers.add_parser(
        'createsuperuser',
        help="Make sure the user 'admin' exists and uses 'admin' as password. "
        "The database tables must be created before. Use syncdb subcommand for this."
    )
    add_general_arguments(subcommand_createsuperuser,
                          ('settings', 'user_data_path'))
    subcommand_createsuperuser.set_defaults(callback=createsuperuser)

    # Subcommand backupdb
    subcommand_backupdb = subparsers.add_parser(
        'backupdb',
        help='Store a backup copy of the SQLite3 database at the given path.')
    add_general_arguments(subcommand_backupdb, ('settings', 'user_data_path'))
    subcommand_backupdb.add_argument(
        'path',
        help='Path to the backup file. An existing file will be overwritten.')
    subcommand_backupdb.set_defaults(callback=backupdb)

    # Subcommand deletedb
    subcommand_deletedb = subparsers.add_parser(
        'deletedb', help='Delete the SQLite3 database.')
    add_general_arguments(subcommand_deletedb, ('settings', 'user_data_path'))
    subcommand_deletedb.set_defaults(callback=deletedb)

    # Subcommand create-dev-settings
    subcommand_create_dev_settings = subparsers.add_parser(
        'create-dev-settings',
        help=
        'Create a settings file at current working directory for development use.'
    )
    subcommand_create_dev_settings.set_defaults(callback=create_dev_settings)

    # Subcommand django
    subcommand_django_command_line_utility = subparsers.add_parser(
        'django',
        description="Link to Django's command-line utility. Type "
        "'%s django help' for more help on this." % parser.prog,
        help="Call Django's command-line utility.")
    subcommand_django_command_line_utility.set_defaults(
        callback=django_command_line_utility,
        django_args=['%s' % subcommand_django_command_line_utility.prog])

    known_args, unknown_args = parser.parse_known_args()

    if known_args.subcommand == 'django':
        if not unknown_args:
            unknown_args.append('help')
        known_args.django_args.extend(unknown_args)
    else:
        if unknown_args:
            parser.error('Unknown arguments %s found.' %
                         ' '.join(unknown_args))

    return known_args
Beispiel #16
0
 def test_get(self):
     response = self.client.get('/version/')
     self.assertContains(response, get_version(), status_code=200)
Beispiel #17
0
def parse_args():
    """
    Parses all command line arguments. The subcommand 'django' links to
    Django's command-line utility.
    """
    if len(sys.argv) == 1:
        sys.argv.append('start')

    # Init parser
    description = 'Start script for OpenSlides.'
    if 'manage.py' not in sys.argv[0]:
        description += (' If it is called without any argument, this will be '
                        'treated as if it is called with the "start" subcommand. '
                        'That means OpenSlides will setup default settings and '
                        'database, start the tornado webserver, launch the '
                        'default web browser and open the webinterface.')
    parser = argparse.ArgumentParser(description=description)

    # Add version argument
    parser.add_argument(
        '--version',
        action='version',
        version=get_version(),
        help='Show version number and exit.')

    # Init subparsers
    subparsers = parser.add_subparsers(
        dest='subcommand',
        title='Available subcommands',
        description="Type 'python %s <subcommand> --help' for help on a "
                    "specific subcommand." % parser.prog,
        help='You can choose only one subcommand at once.')

    # Subcommand start
    subcommand_start = subparsers.add_parser(
        'start',
        help='Setup settings and database, start tornado webserver, launch the '
             'default web browser and open the webinterface.')
    add_general_arguments(subcommand_start, ('settings', 'user_data_path', 'address', 'port'))
    subcommand_start.add_argument(
        '--no-browser',
        action='store_true',
        help='Do not launch the default web browser.')
    subcommand_start.set_defaults(callback=start)

    # Subcommand runserver
    subcommand_runserver = subparsers.add_parser(
        'runserver',
        help='Run OpenSlides using tornado webserver.')
    add_general_arguments(subcommand_runserver, ('settings', 'user_data_path', 'address', 'port'))
    subcommand_runserver.add_argument(
        '--start-browser',
        action='store_true',
        help='Launch the default web browser and open the webinterface.')
    subcommand_runserver.add_argument(
        '--no-reload',
        action='store_true',
        help='Do not reload the webserver if source code changes.')
    subcommand_runserver.set_defaults(callback=runserver)

    # Subcommand syncdb
    subcommand_syncdb = subparsers.add_parser(
        'syncdb',
        help='Create or update database tables.')
    add_general_arguments(subcommand_syncdb, ('settings', 'user_data_path'))
    subcommand_syncdb.set_defaults(callback=syncdb)

    # Subcommand createsuperuser
    subcommand_createsuperuser = subparsers.add_parser(
        'createsuperuser',
        help="Make sure the user 'admin' exists and uses 'admin' as password.")
    add_general_arguments(subcommand_createsuperuser, ('settings', 'user_data_path'))
    subcommand_createsuperuser.set_defaults(callback=createsuperuser)

    # Subcommand backupdb
    subcommand_backupdb = subparsers.add_parser(
        'backupdb',
        help='Store a backup copy of the SQLite3 database at the given path.')
    add_general_arguments(subcommand_backupdb, ('settings', 'user_data_path'))
    subcommand_backupdb.add_argument(
        'path',
        help='Path to the backup file. An existing file will be overwritten.')
    subcommand_backupdb.set_defaults(callback=backupdb)

    # Subcommand deletedb
    subcommand_deletedb = subparsers.add_parser(
        'deletedb',
        help='Delete the SQLite3 database.')
    add_general_arguments(subcommand_deletedb, ('settings', 'user_data_path'))
    subcommand_deletedb.set_defaults(callback=deletedb)

    # Subcommand create-dev-settings
    subcommand_create_dev_settings = subparsers.add_parser(
        'create-dev-settings',
        help='Create a settings file at current working directory for development use.')
    subcommand_create_dev_settings.set_defaults(callback=create_dev_settings)

    # Subcommand django
    subcommand_django_command_line_utility = subparsers.add_parser(
        'django',
        description="Link to Django's command-line utility. Type "
                    "'python %s django help' for more help on this." % parser.prog,
        help="Call Django's command-line utility.")
    subcommand_django_command_line_utility.set_defaults(
        callback=django_command_line_utility,
        django_args=['%s' % subcommand_django_command_line_utility.prog])

    known_args, unknown_args = parser.parse_known_args()

    if known_args.subcommand == 'django':
        if not unknown_args:
            unknown_args.append('help')
        known_args.django_args.extend(unknown_args)
    else:
        if unknown_args:
            parser.error('Unknown arguments %s found.' % ' '.join(unknown_args))

    return known_args
Beispiel #18
0
def get_parser():
    """
    Parses all command line arguments.
    """
    if len(sys.argv) == 1 and not is_development():
        sys.argv.append('start')

    # Init parser
    description = 'Start script for OpenSlides.'
    if 'manage.py' not in sys.argv[0]:
        description += (
            ' If it is called without any argument, this will be '
            'treated as if it is called with the "start" subcommand. '
            'That means OpenSlides will setup default settings and '
            'database, start the tornado webserver, launch the '
            'default web browser and open the webinterface.')
    parser = ExceptionArgumentParser(description=description)

    # Add version argument
    parser.add_argument('--version',
                        action='version',
                        version=get_version(),
                        help='Show version number and exit.')

    # Init subparsers
    subparsers = parser.add_subparsers(
        dest='subcommand',
        title='Available subcommands',
        description="Type '%s <subcommand> --help' for help on a "
        "specific subcommand." % parser.prog,
        help='You can choose only one subcommand at once.')

    # Subcommand start
    subcommand_start = subparsers.add_parser(
        'start',
        help='Setup settings and database, start tornado webserver, launch the '
        'default web browser and open the webinterface. The environment '
        'variable DJANGO_SETTINGS_MODULE is ignored.')
    subcommand_start.add_argument(
        '--no-browser',
        action='store_true',
        help='Do not launch the default web browser.')
    subcommand_start.add_argument(
        '--settings_path',
        action='store',
        default=None,
        help=
        'The used settings file. The file is created, if it does not exist.')
    subcommand_start.set_defaults(callback=start)
    subcommand_start.add_argument('--development',
                                  action='store_true',
                                  help='Command for development purposes.')

    # Subcommand createsettings
    subcommand_createsettings = subparsers.add_parser(
        'createsettings', help='Create the settings file.')
    subcommand_createsettings.set_defaults(callback=createsettings)
    subcommand_createsettings.add_argument(
        '--settings_path',
        action='store',
        default=None,
        help='The used settings file. The file is created, even if it exists.')
    subcommand_createsettings.add_argument(
        '--development',
        action='store_true',
        help='Command for development purposes.')

    return parser
Beispiel #19
0
with open('README.rst') as readme:
    long_description = readme.read()


with open('requirements_production.txt') as requirements_production:
    install_requires = requirements_production.readlines()


# For Python 2.6 support
install_requires.append('argparse==1.2.1')


setup(
    name='openslides',
    version=get_version(),
    author='OpenSlides-Team',
    author_email='*****@*****.**',
    url='http://openslides.org',
    description='Presentation and assembly system',
    long_description=long_description,
    classifiers=[
        # http://pypi.python.org/pypi?%3Aaction=list_classifiers
        'Development Status :: 5 - Production/Stable',
        'Environment :: Web Environment',
        'Intended Audience :: Other Audience',
        'Framework :: Django',
        'License :: OSI Approved :: MIT License',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
    ],
Beispiel #20
0
def revision(request):
    return {'openslides_version': get_version()}
Beispiel #21
0
 def test_get(self):
     user = User.objects.create_user('CoreMaximilian', '*****@*****.**', 'default')
     client = Client()
     client.login(username='******', password='******')
     response = client.get('/version/')
     self.assertContains(response, get_version(), status_code=200)
Beispiel #22
0
# for python 2.5 support
from __future__ import with_statement

from setuptools import setup
from setuptools import find_packages
from openslides import get_version

with open('README.txt') as file:
    long_description = file.read()

setup(
    name='openslides',
    description='Presentation and assembly system',
    long_description=long_description,
    version=get_version(),
    url='http://openslides.org',
    author='OpenSlides-Team',
    author_email='*****@*****.**',
    license='GPL2+',
    packages=find_packages(exclude=['tests']),
    include_package_data=True,
    classifiers=[
        # http://pypi.python.org/pypi?%3Aaction=list_classifiers
        'Development Status :: 5 - Production/Stable',
        'Environment :: Web Environment',
        'Intended Audience :: Other Audience',
        'Framework :: Django',
        'License :: OSI Approved :: GNU General Public License (GPL)',
        'Operating System :: OS Independent',
        'Programming Language :: Python',
Beispiel #23
0
def revision(request):
    return {'openslides_version': get_version()}
Beispiel #24
0
def process_options(argv=None, manage_runserver=False):
    if argv is None:
        argv = sys.argv[1:]

    parser = optparse.OptionParser(
        description="Run openslides using the tornado webserver")
    parser.add_option("-a",
                      "--address",
                      help="IP Address to listen on. Default: 0.0.0.0")
    parser.add_option(
        "-p",
        "--port",
        type="int",
        help="Port to listen on. Default: 8000 (start as admin/root: 80)")
    parser.add_option(
        "--syncdb",
        action="store_true",
        help="Update/create database before starting the server.")
    parser.add_option(
        "--backupdb",
        action="store",
        metavar="BACKUP_PATH",
        help="Make a backup copy of the database to BACKUP_PATH.")
    parser.add_option(
        "--reset-admin",
        action="store_true",
        help="Make sure the user 'admin' exists and uses 'admin' as password.")
    parser.add_option("-s",
                      "--settings",
                      help="Set the path to the settings file.")
    parser.add_option("--no-browser",
                      action="store_false",
                      dest="start_browser",
                      default=True,
                      help="Do not automatically start the web browser.")
    parser.add_option("--no-reload",
                      action="store_true",
                      help="Do not reload the web server.")
    parser.add_option("--no-run",
                      action="store_true",
                      help="Do not start the web server.")
    parser.add_option("--version",
                      action="store_true",
                      help="Show version and exit.")

    opts, args = parser.parse_args(argv)

    # Do not parse any argv if the script is started via manage.py runserver.
    # This simulates the django runserver command
    if manage_runserver:
        opts.start_browser = False
        opts.no_reload = False
        return opts

    if opts.version:
        print get_version()
        exit(0)

    if args:
        sys.stderr.write("This command does not take arguments!\n\n")
        parser.print_help()
        sys.exit(1)

    return opts