class OptionsConfig(Config): """Load options from a common config file """ def __init__(self, conf_file): """Update Flask default data from janitoo option file """ Config.__init__(self) if not os.path.isfile(conf_file): raise RuntimeError("Can't find %s" %conf_file ) self.CONF_FILE = conf_file self.options = JNTOptions({"conf_file":conf_file}) self.options.load() if 'hostname' not in self.options.data or self.options.data['hostname'] is None: self.options.data['hostname'] = socket.gethostname() system = self.options.data webapp = self.options.get_options('webapp') database = self.options.get_options('database') #~ try: #~ flask = self.options.get_options('flask') #~ except ConfigParser.NoSectionError: #~ flask = {} self.SQLALCHEMY_DATABASE_URI = database['sqlalchemy.url'] if 'host' in webapp and 'port' in webapp: self.SERVER_NAME = "%s:%s"%(webapp['host'], webapp['port']) if 'cache_dir' in system: self.CACHE_DIR = os.path.join(system['cache_dir'], 'flask_cache_store')
def __init__(self, url=u'sqlite:////tmp/janitoo_db.sqlite', pkg_name='janitoo_db', ep_name='janitoo', conf_file=None, **kwargs): """ """ self.pkg_name = pkg_name self.ep_name = ep_name if conf_file is None: src = os.path.join(pkg_resources.resource_filename(pkg_resources.Requirement.parse(self.pkg_name), 'config'), u'alembic_template.conf') else: src = conf_file options = JNTOptions({'conf_file':conf_file}) options.load() alembic = options.get_options('database') url = alembic['sqlalchemy.url'] file_ = os.path.join(tempfile.gettempdir(), u'jntal_%s.conf')%(''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(26))) shutil.copyfile(src, file_) alConfig.__init__(self, file_=file_, ini_section='database', **kwargs) config_path = pkg_resources.resource_filename(pkg_resources.Requirement.parse(self.pkg_name), 'config') self.set_main_option("script_location", os.path.join(config_path, 'alembic')) self.set_main_option("sqlalchemy.url", url) version_locations = u"%s/alembic/versions %s/models/%s"%(config_path, config_path, self.ep_name) for entrypoint in pkg_resources.iter_entry_points(group='janitoo.models'): pkg = entrypoint.module_name.split('.')[0] config_path = pkg_resources.resource_filename(pkg_resources.Requirement.parse(pkg), 'config') version_locations += u" %s/models/%s"%(config_path, entrypoint.name) self.set_main_option("version_locations", version_locations)