コード例 #1
0
ファイル: newsetup.py プロジェクト: genzgd/lampost_lib
def new_setup(args):
    json.select_json()

    db = resource.register('datastore', redisstore.RedisStore(args.db_host, args.db_port, args.db_num, args.db_pw))
    if args.flush:
        db_num = db.pool.connection_kwargs['db']
        if db_num == args.db_num:
            log.info("Flushing database {}", db_num)
            db.redis.flushdb()
        else:
            print("Error:  DB Numbers do not match")
            return

    db_config = db.load_object(args.config_id, 'config')
    if db_config:
        print("Error:  This instance is already set up")
        return

    # Load config yaml files and create the database configuration
    config_yaml = config.load_yaml(args.config_dir)
    db_config = dbconfig.create(args.config_id, config_yaml, True)
    config.activate(db_config.section_values)

    # Initialize core services needed by the reset of the setup process
    resource.register('dispatcher', PulseDispatcher())
    resource.register('perm', permissions)
    um = resource.register('user_manager', user_manager)
    resource.register('edit_update_service', SetupEditUpdate)
    app_setup = import_module('{}.newsetup'.format(args.app_id))

    first_player = app_setup.first_time_setup(args, db)
    user = um.create_user(args.imm_account, args.imm_password)
    player = um.attach_player(user, first_player)
    db.set_db_hash('immortals', player.dbo_id, player.imm_level)
コード例 #2
0
ファイル: json.py プロジェクト: mjgorman/lampost_lib
def select_json():
    try:
        ujson = importlib.import_module('ujson')
        register('json_decode', ujson.decode)
        register('json_encode', UJsonEncoder(ujson.encode).encode)
        log.info("Selected ujson JSON library")
    except ImportError:
        json = importlib.import_module('json')
        register('json_decode', json.JSONDecoder().decode)
        register('json_encode', json.JSONEncoder().encode)
        log.info("Defaulted to standard JSON library")
コード例 #3
0
ファイル: tools.py プロジェクト: mjgorman/lampost_lib
def reload_config(args):
    db = RedisStore(args.db_host, args.db_port, args.db_num, args.db_pw)
    resource.register('datastore', db)
    config_id = args.config_id
    existing = db.load_object(config_id, dbconfig.Config)
    if not existing:
        print("Existing configuration does not exist, try lampost_setup")
        return
    db.delete_object(existing)

    try:
        config_yaml = config.load_yaml(args.config_dir)
        if not config_yaml:
            print("No yaml found.  Confirm config/working directory?")
            return
        db_config = dbconfig.create(config_id, config_yaml, True)
    except Exception:
        log.exception("Failed to create configuration from yaml")
        db.save_object(existing)
        print("Exception creating configuration from yaml.")
        return
    config.activate(db_config.section_values)
    print('Config {} successfully reloaded from yaml files'.format(config_id))
コード例 #4
0
def new_setup(args):
    json.select_json()

    db = resource.register(
        'datastore',
        redisstore.RedisStore(args.db_host, args.db_port, args.db_num,
                              args.db_pw))
    if args.flush:
        db_num = db.pool.connection_kwargs['db']
        if db_num == args.db_num:
            log.info("Flushing database {}", db_num)
            db.redis.flushdb()
        else:
            print("Error:  DB Numbers do not match")
            return

    db_config = db.load_object(args.config_id, 'config')
    if db_config:
        print("Error:  This instance is already set up")
        return

    # Load config yaml files and create the database configuration
    config_yaml = config.load_yaml(args.config_dir)
    db_config = dbconfig.create(args.config_id, config_yaml, True)
    config.activate(db_config.section_values)

    # Initialize core services needed by the reset of the setup process
    resource.register('dispatcher', PulseDispatcher())
    perm = resource.register('perm', permissions)
    um = resource.register('user_manager', user_manager)
    resource.register('edit_update_service', SetupEditUpdate)
    app_setup = import_module('{}.newsetup'.format(args.app_id))
    app.exec_bootstraps()

    first_player = app_setup.first_time_setup(args, db)
    user = um.create_user(args.imm_account, args.imm_password)
    player = um.attach_player(user, first_player)
    perm.update_immortal_list(player)
コード例 #5
0
def start(args):
    json.select_json()

    datastore = resource.register('datastore', RedisStore(args.db_host, args.db_port, args.db_num, args.db_pw))
    db_config = datastore.load_object(args.config_id, dbconfig.Config)
    config_values = config.activate(db_config.section_values)

    resource.register('dispatcher', dispatcher)
    resource.register('perm', permissions)

    app_setup = import_module('{}.appstart'.format(args.app_id))
    app_setup.start_engine(args)

    resource.register('display', display)
    resource.register('user_manager', user)
    resource.register('session_manager', SessionManager())
    resource.register('instance_manager', instancemgr)
    resource.register('email_sender', email_sender)
    resource.register('channel_service', ChannelService())
    resource.register('friend_service', friend)
    resource.register('message_service', message)
    resource.register('player_list_service', PlayerListService())
    resource.register('login_notify_service', AnyLoginService())
    resource.register('edit_update_service', EditUpdateService())

    app.start_app()

    pages.add_page(pages.LspPage('config.js', "var lampost_config = {{title:'{0}', description:'{1}'}};"
                                 .format(config_values['lampost_title'], config_values['lampost_description'])))

    web.service_root = args.service_root
    if args.web_files:
        web.add_raw_route("/", RedirectHandler, url="/webclient/lampost.html")
        web.add_raw_route("/webclient/(.*)", StaticFileHandler, path=os.path.abspath(args.web_files))
    web.add_raw_route("/lsp/(.*)", pages.LspHandler)
    web.add_routes(main_router.routes)
    web.add_routes(edit_router.routes)
    web.add_routes(app_setup.app_routes())
    web.start_service(args.port, args.server_interface)

    IOLoop.instance().start()
コード例 #6
0
ファイル: tools.py プロジェクト: mjgorman/lampost_lib
import logging

from lampost.di import resource, config
from lampost.db.redisstore import RedisStore
from lampost.db import dbconfig
from lampost.util.logging import LogFactory
from lampost.util import json

resource.register('log', LogFactory())
json.select_json()
log = logging.getLogger(__name__)


def reload_config(args):
    db = RedisStore(args.db_host, args.db_port, args.db_num, args.db_pw)
    resource.register('datastore', db)
    config_id = args.config_id
    existing = db.load_object(config_id, dbconfig.Config)
    if not existing:
        print("Existing configuration does not exist, try lampost_setup")
        return
    db.delete_object(existing)

    try:
        config_yaml = config.load_yaml(args.config_dir)
        if not config_yaml:
            print("No yaml found.  Confirm config/working directory?")
            return
        db_config = dbconfig.create(config_id, config_yaml, True)
    except Exception:
        log.exception("Failed to create configuration from yaml")
コード例 #7
0
ファイル: appstart.py プロジェクト: carriercomm/Lampost-Mud
def start_engine(args):
    resource.register('mud_core', mudcore)
コード例 #8
0
ファイル: appstart.py プロジェクト: genzgd/Lampost-Mud
def start_engine(args):
    import_module('lampmud.editor.start')
    resource.register('action_system', system)
コード例 #9
0
from collections import defaultdict

from lampost.di.resource import Injected, module_inject, register
from lampost.gameops.action import make_action, ActionError, ActionCache

log = Injected('log')
module_inject(__name__)

_mud_actions = ActionCache()
register('mud_actions', _mud_actions)

imm_actions = set()


def mud_action(verbs, msg_class=None, **kwargs):
    def dec_wrapper(func):
        action = make_action(func, verbs, msg_class, **kwargs)
        _mud_actions.add_unique(action)
    return dec_wrapper


def imm_action(verbs, msg_class=None, imm_level='builder', **kwargs):
    def dec_wrapper(func):
        imm_actions.add(func)
        func.imm_level = imm_level
        return make_action(func, verbs, msg_class, **kwargs)
    return dec_wrapper


@mud_action('help', target_class='cmd_str_opt')
def help_action(source, target):
コード例 #10
0
ファイル: lampost_setup.py プロジェクト: genzgd/Lampost-Mud
import sys

from lampost.util import logging
from lampost.setup import startargs

if __name__ != "__main__":
    print("Invalid usage")
    sys.exit(2)


args = startargs.create_parser.parse_args()

# We set the logging configuration before importing other modules so that the root logger is properly configured
logging.init_config(args)
logging.root_logger.info("Started with args {}", args)

from lampost.di.resource import register
register('log', logging.LogFactory())

from lampost.setup import newsetup

if args.flush:
    response = input("Please confirm the database number you wish to clear: ")
    if response != str(args.db_num):
        print("Database numbers do not match")
        sys.exit(2)

newsetup.new_setup(args)
コード例 #11
0
def start_engine(args):
    resource.register('action_system', system)
    resource.register('mud_core', mudcore)
コード例 #12
0
ファイル: lampost_mud.py プロジェクト: genzgd/Lampost-Mud
import sys

from lampost.setup import startargs
from lampost.util import logging


if __name__ != "__main__":
    print("Invalid usage")
    sys.exit(2)

args = startargs.main_parser.parse_args()
logging.init_config(args)
logging.root_logger.info("Started with args {}", args)

from lampost.di import resource
resource.register('log', logging.LogFactory())

from lampmud.setup import engine
engine.start(args)