def init(dbs=[], services={}, templates=False): """Initialise Starts up most of the modules needed to support REST and Services Arguments: dbs (str[]): List of DBs to start up services (dict): Dictionary of service name to instance being managed by the caller Returns: REST.Config """ # Load the config Conf.load('config.json') sConfOverride = 'config.%s.json' % platform.node() if os.path.isfile(sConfOverride): Conf.load_merge(sConfOverride) # Add the global prepend Record_Base.dbPrepend(Conf.get(("mysql", "prepend"), '')) # Go through the list of DBs requested for s in dbs: Record_MySQL.addHost(s, Conf.get(("mysql", "hosts", s))) # Init the Sesh module Sesh.init(Conf.get(("redis", "primary"))) # Create the REST config instance oRestConf = REST.Config(Conf.get("rest")) # Set verbose mode if requested if 'VERBOSE' in os.environ and os.environ['VERBOSE'] == '1': Services.verbose() # Get all the services dServices = {k:None for k in Conf.get(('rest', 'services'))} # Overwrite those passed in for n,o in services.items(): dServices[n] = o # Register all services Services.register(dServices, oRestConf, Conf.get(('services', 'salt'))) # Init Templates if templates: Templates.init(templates) # Return the REST config return oRestConf
# Pip imports from RestOC import Conf, Record_Base, Record_ReDB, REST, Services # Upgrade imports from . import UpgradeLog, run # If the version argument is missing if len(sys.argv) < 2: print('Must specify the version to run:\n\tpython -m upgrades v1.0') sys.exit(1) # Store the version sVer = sys.argv[1].replace('.', '_') # Load the config Conf.load('../config.json') sConfOverride = '../config.%s.json' % platform.node() if os.path.isfile(sConfOverride): Conf.load_merge(sConfOverride) # Add the global prepend and primary host to rethinkdb Record_Base.dbPrepend(Conf.get(("rethinkdb", "prepend"), '')) Record_ReDB.addHost('primary', Conf.get(("rethinkdb", "hosts", "primary"))) # Register all services Services.register( {k:None for k in Conf.get(('rest', 'services'))}, REST.Config(Conf.get("rest")), Conf.get(('services', 'salt')) )
import os, platform, time # Framework imports from RestOC import Conf, Record_MySQL # Records from records import Company, User # Services from services.primary import Primary # Only run if called directly if __name__ == "__main__": # Load the config Conf.load('config.json') sConfOverride = 'config.%s.json' % platform.node() if os.path.isfile(sConfOverride): Conf.load_merge(sConfOverride) # Add hosts Record_MySQL.addHost('primary', Conf.get(("mysql", "hosts", "primary"))) # Add the DB Record_MySQL.dbCreate( Conf.get(("mysql", "primary", "db"), "tims-ouroboros"), 'primary') # Install Primary.install() # Install admin user