Пример #1
0
def main():
    # Generate command line parser
    parser = argparse.ArgumentParser(usage='%(prog)s [options]')
    parser.add_argument('-d', '--daemon', dest='daemon', action='store_true', default=False,
                        help='Run as daemon.')
    # smbaker: util/config.py parses sys.argv[] directly to get config file name; include the option here to avoid
    #   throwing unrecognized argument exceptions
    parser.add_argument('-C', '--config', dest='config_file', action='store', default=DEFAULT_CONFIG_FN,
                        help='Name of config file.')
    args = parser.parse_args()

    if args.daemon: daemon()

    if django_setup: # 1.7
        django_setup()

    models_active = False
    wait = False
    while not models_active:
        try:
            _ = Instance.objects.first()
            _ = NetworkTemplate.objects.first()
            models_active = True
        except Exception,e:
            logger.info(str(e))
            logger.info('Waiting for data model to come up before starting...')
            time.sleep(10)
            wait = True
Пример #2
0
def register_cli_commands(parser):
    """Register the CLI's meta-subcommands on `parser`."""
    for name, command in commands.items():
        help_title, help_body = parse_docstring(command)
        command_parser = parser.subparsers.add_parser(
            safe_name(name), help=help_title, description=help_title,
            epilog=help_body)
        command_parser.set_defaults(execute=command(command_parser))

    # Setup the snap commands into the maascli if in a snap and command exists.
    if 'SNAP' in os.environ:
        # Only import snappy if running under the snap.
        from maascli import snappy
        for name, command in [
                ('init', snappy.cmd_init),
                ('config', snappy.cmd_config),
                ('status', snappy.cmd_status),
                ('migrate', snappy.cmd_migrate)]:
            help_title, help_body = parse_docstring(command)
            command_parser = parser.subparsers.add_parser(
                safe_name(name), help=help_title, description=help_title,
                epilog=help_body)
            command_parser.set_defaults(execute=command(command_parser))

    # Setup and the allowed django commands into the maascli.
    management = get_django_management()
    if management is not None and is_maasserver_available():
        os.environ.setdefault(
            "DJANGO_SETTINGS_MODULE", "maasserver.djangosettings.settings")
        from django import setup as django_setup
        django_setup()
        load_regiond_commands(management, parser)
Пример #3
0
def main():
    # Generate command line parser
    parser = argparse.ArgumentParser(usage='%(prog)s [options]')
    parser.add_argument('-d',
                        '--daemon',
                        dest='daemon',
                        action='store_true',
                        default=False,
                        help='Run as daemon.')
    # smbaker: util/config.py parses sys.argv[] directly to get config file name; include the option here to avoid
    #   throwing unrecognized argument exceptions
    parser.add_argument('-C',
                        '--config',
                        dest='config_file',
                        action='store',
                        default=DEFAULT_CONFIG_FN,
                        help='Name of config file.')
    args = parser.parse_args()

    if args.daemon: daemon()

    if django_setup:  # 1.7
        django_setup()

    backend = Backend()
    backend.run()
Пример #4
0
def main():
    # Generate command line parser
    parser = argparse.ArgumentParser(usage='%(prog)s [options]')
    parser.add_argument('-d', '--daemon', dest='daemon', action='store_true', default=False,
                        help='Run as daemon.')
    # smbaker: util/config.py parses sys.argv[] directly to get config file name; include the option here to avoid
    #   throwing unrecognized argument exceptions
    parser.add_argument('-C', '--config', dest='config_file', action='store', default=DEFAULT_CONFIG_FN,
                        help='Name of config file.')
    args = parser.parse_args()

    if args.daemon: daemon()

    if django_setup: # 1.7
        django_setup()

    models_active = False
    wait = False
    while not models_active:
        try:
            _ = Instance.objects.first()
            _ = NetworkTemplate.objects.first()
            models_active = True
        except Exception,e:
            logger.info(str(e))
            logger.info('Waiting for data model to come up before starting...')
            time.sleep(10)
            wait = True
Пример #5
0
def configure_django(django_settings, **config):
    if django_settings:
        os.environ['DJANGO_SETTINGS_MODULE'] = django_settings
    else:
        from django.conf import settings  # noqa
        if not settings.configured:
            settings.configure(**config)
    try:
        from django import setup as django_setup
    except ImportError:
        pass
    else:
        django_setup()
Пример #6
0
def configure_django(django_settings, **config):
    if django_settings:
        os.environ['DJANGO_SETTINGS_MODULE'] = django_settings
    else:
        from django.conf import settings  # noqa
        if not settings.configured:
            settings.configure(**config)
    try:
        from django import setup as django_setup
    except ImportError:
        pass
    else:
        django_setup()
def runtests(*test_args, **kwargs):
    django_setup()
    if not test_args:
        test_args = ['tests']
    parent = dirname(abspath(__file__))
    sys.path.insert(0, parent)
    test_runner = DiscoverRunner(
        verbosity=kwargs.get('verbosity', 1),
        interactive=kwargs.get('interactive', False),
        failfast=kwargs.get('failfast')
    )
    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Пример #8
0
def main():
    logging.basicConfig(format='%(asctime)s - %(levelname)s - %(message)s',
                        level=logging.WARNING)

    environ.setdefault('DJANGO_SETTINGS_MODULE', 'website.settings')

    print('Setting up Django...')

    django_setup()

    token = getenv('BOT_TOKEN')

    if not token:
        raise Exception('Bot token not found')

    updater = Updater(token=token, use_context=True)

    print('Loading handlers...')

    from . import handlers, persistence

    for handler in handlers.get_handlers():
        updater.dispatcher.add_handler(handler)

    print('Loading persistent data...')
    persistence.load()

    print('Loading scheduled jobs...')
    load_jobs(updater.bot)

    print('Starting scheduler thread...')
    thread = SchedulerThread()
    thread.start()

    print('Starting polling...')
    updater.start_polling()

    BotCLI().cmdloop()

    print('Stopping scheduler thread...')
    thread.stopper.set()
    thread.join()

    print('Stopping polling...')
    updater.stop()

    print('Saving persistent data...')
    persistence.close()

    print('Bye!')
Пример #9
0
def register_cli_commands(parser):
    """Register the CLI's meta-subcommands on `parser`."""
    def add_command(name, command):
        help_title, help_body = parse_docstring(command)
        arg_name = safe_name(name)
        if command.hidden:
            command_parser = parser.subparsers.add_parser(arg_name)
        else:
            command_parser = parser.subparsers.add_parser(
                arg_name,
                help=help_title,
                description=help_title,
                epilog=help_body,
            )
        command_parser.set_defaults(execute=command(command_parser))

    for name, command in commands.items():
        add_command(name, command)

    # Setup the snap commands into the maascli if in a snap and command exists.
    if "SNAP" in os.environ:
        # Only import snappy if running under the snap.
        from maascli import snappy

        extra_commands = [
            ("init", snappy.cmd_init),
            ("config", snappy.cmd_config),
            ("status", snappy.cmd_status),
            ("migrate", snappy.cmd_migrate),
            ("reconfigure-supervisord", snappy.cmd_reconfigure_supervisord),
        ]
    elif is_maasserver_available():
        extra_commands = [("init", cmd_init)]
    else:
        extra_commands = []

    for name, command in extra_commands:
        add_command(name, command)

    # Setup and the allowed django commands into the maascli.
    management = get_django_management()
    if management is not None and is_maasserver_available():
        os.environ.setdefault("DJANGO_SETTINGS_MODULE",
                              "maasserver.djangosettings.settings")
        from django import setup as django_setup

        django_setup()
        load_regiond_commands(management, parser)
Пример #10
0
def main():
    if not "-C" in sys.argv:
        print >> sys.stderr, "You probably wanted to use -C " + XOS_DIR + "/hpc_observer/hpc_observer_config"

    # Generate command line parser
    parser = argparse.ArgumentParser(usage='%(prog)s [options]')
    # smbaker: util/config.py parses sys.argv[] directly to get config file name; include the option here to avoid
    #   throwing unrecognized argument exceptions
    parser.add_argument('-C', '--config', dest='config_file', action='store', default=DEFAULT_CONFIG_FN,
                        help='Name of config file.')
    args = parser.parse_args()

    if django_setup: # 1.7
        django_setup()

    cc = XOSConsistencyCheck()
    cc.run()
Пример #11
0
def main():
    # Generate command line parser
    parser = argparse.ArgumentParser(usage='%(prog)s [options]')
    parser.add_argument('-d', '--daemon', dest='daemon', action='store_true', default=False,
                        help='Run as daemon.')
    # smbaker: util/config.py parses sys.argv[] directly to get config file name; include the option here to avoid
    #   throwing unrecognized argument exceptions
    parser.add_argument('-C', '--config', dest='config_file', action='store', default=DEFAULT_CONFIG_FN,
                        help='Name of config file.')
    args = parser.parse_args()

    if args.daemon: daemon()

    if django_setup: # 1.7
        django_setup()

    backend = Backend()
    backend.run()    
Пример #12
0
Файл: fsck.py Проект: xuys50/xos
def main():
    if not "-C" in sys.argv:
        print >> sys.stderr, "You probably wanted to use -C " + XOS_DIR + "/hpc_observer/hpc_observer_config"

    # Generate command line parser
    parser = argparse.ArgumentParser(usage='%(prog)s [options]')
    # smbaker: util/config.py parses sys.argv[] directly to get config file name; include the option here to avoid
    #   throwing unrecognized argument exceptions
    parser.add_argument('-C',
                        '--config',
                        dest='config_file',
                        action='store',
                        default=DEFAULT_CONFIG_FN,
                        help='Name of config file.')
    args = parser.parse_args()

    if django_setup:  # 1.7
        django_setup()

    cc = XOSConsistencyCheck()
    cc.run()
Пример #13
0
    version_file = open(filename).read()
    version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]",
                              version_file, re.M)
    if version_match:
        return version_match.group(1)
    raise RuntimeError('Unable to find version string.')


REPO_ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(REPO_ROOT)

VERSION = get_version('../xss_utils', '__init__.py')

# Configure Django for autodoc usage
settings.configure()
django_setup()

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#
# needs_sphinx = '1.0'
Пример #14
0
def main():
    django_setup()
    test_runner = get_runner(settings)(interactive=False, verbosity=2)
    failures = test_runner.run_tests(['djembe.tests'])
    sys.exit(failures)
Пример #15
0
# documentation root, use os.path.abspath to make it absolute, like shown here.
sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(__file__)), '..', 'coffeestats'))

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'coffeestats.settings.local')
os.environ.setdefault('COFFEESTATS_SITE_ADMINMAIL', '*****@*****.**')
os.environ.setdefault('COFFEESTATS_PGSQL_DATABASE', 'coffeestats')
os.environ.setdefault('COFFEESTATS_PGSQL_HOSTNAME', 'db')
os.environ.setdefault('COFFEESTATS_PGSQL_USER', 'coffeestats')
os.environ.setdefault('COFFEESTATS_PGSQL_PASSWORD', 'coffeestats')
os.environ.setdefault('COFFEESTATS_PGSQL_PORT', 'coffeestats')
os.environ.setdefault('COFFEESTATS_DOMAIN_NAME', 'coffeestats.org')
os.environ.setdefault('COFFEESTATS_SITE_NAME', 'coffeestats.org')
os.environ.setdefault('COFFEESTATS_SITE_SECRET', 'secret')

from django import setup as django_setup
django_setup()

# -- General configuration -----------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be extensions
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.todo',
    'sphinxcontrib.httpdomain',
]

todo_include_todos = True
Пример #16
0
def setup():
    django_setup()
Пример #17
0
def pytest_configure():
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "_project_.settings")
    django_setup()
Пример #18
0
 def __init__(self):
     django_setup()
     super(DjangoModelAccessor, self).__init__()
Пример #19
0
 def __init__(self):
     django_setup()
     super(DjangoModelAccessor, self).__init__()
Пример #20
0
def main():
    django_setup()
    test_runner = get_runner(settings)(interactive=False, verbosity=2)
    failures = test_runner.run_tests(['djembe.tests'])
    sys.exit(failures)