def serve_networks(): """Start the HIL networking server""" from hil import model, deferred from time import sleep config.setup() server.init() server.register_drivers() server.validate_state() model.init_db() migrations.check_db_schema() # Check if config contains usable sleep_time if (cfg.has_section('network-daemon') and cfg.has_option('network-daemon', 'sleep_time')): try: sleep_time = cfg.getfloat('network-daemon', 'sleep_time') except (ValueError): sys.exit("Error: sleep_time set to non-float value") if sleep_time <= 0 or sleep_time >= 3600: sys.exit("Error: sleep_time not within bounds " "0 < sleep_time < 3600") if sleep_time > 60: logger.warn('sleep_time greater than 1 minute.') else: sleep_time = 2 while True: # Empty the journal until it's empty; then delay so we don't tight # loop. while deferred.apply_networking(): pass sleep(sleep_time)
def configure(): """Configure HIL, and test which db we're using. Skips the test unless we're using postgres. """ config_testsuite() if not cfg.get('database', 'uri').startswith('postgresql:'): pytest.skip('Database migrations are only supported for postgresql.') init_db()
def init(): """Set up the api server's internal state. This is a convenience wrapper that calls the other setup routines in this module in the correct order, as well as ``model.init_db`` """ register_drivers() validate_state() model.init_db()
def create_admin_user(username, password): """Create an admin user. Only valid for the database auth backend. This must be run on the HIL API server, with access to hil.cfg and the database. It will create an user named <username> with password <password>, who will have administrator privileges. This command should only be used for bootstrapping the system; once you have an initial admin, you can (and should) create additional users via the API. """ if not config.cfg.has_option('extensions', 'hil.ext.auth.database'): sys.exit("'make_inital_admin' is only valid with the database auth" " backend.") from hil import model from hil.model import db from hil.ext.auth.database import User model.init_db() db.session.add(User(label=username, password=password, is_admin=True)) db.session.commit()
def main(): """Entrypoint for the hil-admin command.""" ensure_not_root() config.setup() model.init_db() manager.run()
def newDB(): """Configures and returns a connection to a freshly initialized DB.""" with app.app_context(): init_db() create_db()
def main(): """Entrypoint for the hil-admin command.""" ensure_not_root() config.setup() model.init_db() manager.run()
def configure(): config_testsuite() if not cfg.get('database', 'uri').startswith('postgresql:'): pytest.skip('Database migrations are only supported for postgresql.') init_db()
def newDB(): """Configures and returns a connection to a freshly initialized DB.""" with app.app_context(): init_db() create_db()
def configure(): config_testsuite() if not cfg.get('database', 'uri').startswith('postgresql:'): pytest.skip('Database migrations are only supported for postgresql.') init_db()