def module(ctx): """[GROUP] Module commands""" from isomer import database database.initialize(ctx.obj["dbhost"], ctx.obj["dbname"]) ctx.obj["db"] = database
def pytest_configure(config): """Setup the testing namespace""" dbname = config.getoption("--dbname", default=DEFAULT_DATABASE_NAME) dbhost = config.getoption("--dbhost", default=DEFAULT_DATABASE_HOST) dbport = config.getoption("--dbport", default=DEFAULT_DATABASE_PORT) instance_name = config.getoption("--instance", default=DEFAULT_INSTANCE_NAME) pytest.TestComponent = TestComponent pytest.clean_test_components = clean_test_components pytest.WaitEvent = WaitEvent pytest.wait_for = wait_for pytest.call_event = call_event pytest.PLATFORM = sys.platform pytest.PYVER = sys.version_info[:3] pytest.DBNAME = dbname pytest.DBHOST = dbhost pytest.DBPORT = dbport pytest.INSTANCENAME = instance_name pytest.call_event_from_name = call_event_from_name pytest.run_cli = run_cli pytest.reset_base = reset_base clean_test_database(config) initialize(address="%s:%i" % (dbhost, dbport), database_name=dbname, instance_name=instance_name)
def xmpp(ctx): """Hello world""" check_root() from isomer import database database.initialize(ctx.obj['dbhost'], ctx.obj['dbname']) from isomer.schemata.component import ComponentConfigSchemaTemplate factory = model_factory(ComponentConfigSchemaTemplate) bot_config = factory.find_one({'name': 'XMPPBOT'}) if bot_config is None: password = std_uuid() bot_config = factory({ 'nick': 'claptrap', 'name': 'XMPPBOT', 'componentclass': 'XMPPBot', 'jid': 'claptrap@localhost/node', 'password': password, 'uuid': std_uuid() }) bot_config.save() # log(bot_config.serializablefields(), pretty=True) ctx.obj['bot_config'] = bot_config
def _get_system_configuration(dbhost, dbname): from isomer import database database.initialize(dbhost, dbname) systemconfig = database.objectmodels["systemconfig"].find_one( {"active": True}) return systemconfig
def config(ctx): """[GROUP] Configuration management operations""" from isomer import database database.initialize(ctx.obj["dbhost"], ctx.obj["dbname"]) from isomer.schemata.component import ComponentConfigSchemaTemplate ctx.obj["col"] = model_factory(ComponentConfigSchemaTemplate)
def cli_reload(self, event): """Experimental call to reload the component tree""" self.log("Reloading all components.") self.update_components(forcereload=True) initialize() from isomer.debugger import cli_compgraph self.fireEvent(cli_compgraph())
def db(ctx): """[GROUP] Database management operations""" # log(ctx.obj, pretty=True) from isomer import database ignore_fail = ctx.invoked_subcommand in ("list-all", "rename", "delete") database.initialize(ctx.obj["dbhost"], ctx.obj["dbname"], ignore_fail=ignore_fail) ctx.obj["db"] = database
def install_provisions(ctx, package, clear_provisions=False, overwrite=False, list_provisions=False): """Install default provisioning data""" log("Installing Isomer default provisions") # from isomer.logger import verbosity, events # verbosity['console'] = verbosity['global'] = events from isomer import database log("Instance settings:", ctx.obj, pretty=True, lvl=debug) database.initialize(ctx.obj["dbhost"], ctx.obj["dbname"]) provision(list_provisions, overwrite, clear_provisions, package)
def launch(ctx, run=True, **args): """Assemble and run an Isomer instance""" instance_name = ctx.obj["instance"] instance = load_instance(instance_name) environment_name = ctx.obj["environment"] isolog("Launching instance %s - (%s)" % (instance_name, environment_name), emitter="CORE", lvl=debug) database_host = ctx.obj["dbhost"] database_name = ctx.obj["dbname"] if ctx.params["live_log"] is True: from isomer import logger logger.live = True if args["web_certificate"] is not None: isolog( "Warning! Using SSL on the backend is currently not recommended!", lvl=critical, emitter="CORE", ) isolog("Initializing database access", emitter="CORE", lvl=debug) initialize(database_host, database_name, instance_name) isolog("Setting instance paths", emitter="CORE", lvl=debug) set_instance(instance_name, environment_name) server = construct_graph(ctx, instance_name, instance, args) if run and not args["no_run"]: server.run() return server
def cli_reload_db(self, event): """Experimental call to reload the database""" self.log("This command is WiP.") initialize()
def export_schemata(ctx, output_path, output_format, no_entity_mode, include_meta, schemata): """Utility function for exporting known schemata to various formats Exporting to typescript requires the "json-schema-to-typescript" tool. You can install it via: npm -g install json-schema-to-typescript """ # TODO: This one is rather ugly to edit, should the need arise.. banner = ( "/* tslint:disable */\n/**\n* This file was automatically generated " "by Isomer's command line tool using:\n" " * 'iso dev export-schemata -f typescript' " "- using json-schema-to-typescript.\n" " * DO NOT MODIFY IT BY HAND. Instead, modify the source isomer object " "file,\n* and run the iso tool schemata exporter again, to regenerate this file.\n*/" ) # TODO: This should be employable to automatically generate # typescript definitions inside a modules frontend part as part # of the development cycle. from isomer import database, schemastore database.initialize(ctx.obj["dbhost"], ctx.obj["dbname"], ignore_fail=True) if len(schemata) == 0: schemata = database.objectmodels.keys() if output_path is not None: stdout = False if not os.path.exists(output_path): abort("Output Path doesn't exist.") else: stdout = True for item in schemata: if item not in schemastore.schemastore: log("Schema not registered:", item, lvl=warn) continue schema = schemastore.schemastore[item]["schema"] if not include_meta: if "perms" in schema["properties"]: del schema["properties"]["perms"] if "roles_create" in schema: del schema["roles_create"] if "required" in schema: del schema["required"] if output_format == "jsonschema": log("Generating json schema of", item) if stdout: print(json.dumps(schema, indent=4)) else: with open(os.path.join(output_path, item + ".json"), "w") as f: json.dump(schema, f, indent=4) elif output_format == "typescript": log("Generating typescript annotations of", item) # TODO: Fix typing issues here and esp. in run_process success, result = run_process( output_path, [ "json2ts", "--bannerComment", banner, ], stdin=json.dumps(schema).encode("utf-8"), ) typescript = result.output.decode("utf-8") if no_entity_mode is False: typescript = ( "import { Entity, Key } from '@briebug/ngrx-auto-entity';\n" + typescript) typescript = typescript.replace("uuid", "@Key uuid") typescript = typescript.replace( "export interface", "@Entity({modelName: '%s'})\n" "export class" % item, ) if stdout: print(typescript) else: with open(os.path.join(output_path, item + ".ts"), "w") as f: f.write(typescript) finish(ctx)