def _generate_sample(app, config_file, base_name): def info(msg): LOG.info('[%s] %s' % (__name__, msg)) # If we are given a file that isn't an absolute path, look for it # in the source directory if it doesn't exist. candidates = [ config_file, os.path.join( app.srcdir, config_file, ), ] for c in candidates: if os.path.isfile(c): info('reading config generator instructions from %s' % c) config_path = c break else: raise ValueError("Could not find config_generator_config_file %r" % app.config.config_generator_config_file) if base_name: out_file = os.path.join(app.srcdir, base_name) + '.conf.sample' if not os.path.isdir(os.path.dirname(os.path.abspath(out_file))): os.mkdir(os.path.dirname(os.path.abspath(out_file))) else: file_name = 'sample.config' out_file = os.path.join(app.srcdir, file_name) info('writing sample configuration to %s' % out_file) generator.main( args=['--config-file', config_path, '--output-file', out_file])
def prehook(cmd): try: from oslo_config import generator generator.main( ['--config-file', 'etc/gnocchi/gnocchi-config-generator.conf']) except Exception as e: print("Unable to build sample configuration file: %s" % e)
def _generate_sample(app, config_file, base_name): def info(msg): LOG.info('[%s] %s' % (__name__, msg)) # If we are given a file that isn't an absolute path, look for it # in the source directory if it doesn't exist. candidates = [ config_file, os.path.join(app.srcdir, config_file,), ] for c in candidates: if os.path.isfile(c): info('reading config generator instructions from %s' % c) config_path = c break else: raise ValueError( "Could not find config_generator_config_file %r" % app.config.config_generator_config_file) if base_name: out_file = os.path.join(app.srcdir, base_name) + '.conf.sample' if not os.path.isdir(os.path.dirname(os.path.abspath(out_file))): os.mkdir(os.path.dirname(os.path.abspath(out_file))) else: file_name = 'sample.config' out_file = os.path.join(app.srcdir, file_name) info('writing sample configuration to %s' % out_file) generator.main(args=['--config-file', config_path, '--output-file', out_file])
def prehook(cmd): try: from oslo_config import generator generator.main(['--config-file', 'gnocchi-config-generator.conf']) except Exception as e: print("Unable to build sample configuration file: %s" % e)
def config_generator(): args = ['--output-file', 'etc/aodh/aodh.conf'] try: from oslo_config import generator generator.main([ '--config-file', '%s/aodh-config-generator.conf' % os.path.dirname(__file__) ] + args) except Exception as e: print("Unable to build sample configuration file: %s" % e)
def config_files(self): config_files = super(ConfigTestCase, self).config_files() sample_file = 'keystone.conf.sample' args = ['--namespace', 'keystone', '--output-file', unit.dirs.etc(sample_file)] generator.main(args=args) config_files.insert(0, unit.dirs.etc(sample_file)) self.addCleanup(os.remove, unit.dirs.etc(sample_file)) return config_files
def generate_sample_config(self, local_dir): conf_generator = os.path.join(os.path.dirname(__file__), 'config-generator.tempest.conf') output_file = os.path.join(local_dir, 'etc/tempest.conf.sample') if os.path.isfile(conf_generator): generator.main(['--config-file', conf_generator, '--output-file', output_file]) else: LOG.warning("Skipping sample config generation because global " "config file %s can't be found" % conf_generator)
def config_generator(): try: from oslo_config import generator generator.main([ '--config-file', '%s/aodh-config-generator.conf' % os.path.dirname(__file__) ] + sys.argv[1:]) except Exception as e: print("Unable to build sample configuration file: %s" % e) return 1
def prehook(cmd, args=None): if args is None: args = ['--output-file', 'etc/gnocchi/gnocchi.conf'] try: from oslo_config import generator generator.main([ '--config-file', '%s/gnocchi-config-generator.conf' % os.path.dirname(__file__) ] + args) except Exception as e: print("Unable to build sample configuration file: %s" % e)
def config_files(self): config_files = super(ConfigTestCase, self).config_files() # NOTE(lbragstad): This needs some investigation, but CONF.find_file() # apparently needs the sample configuration file in order to find the # paste file. This should really be replaced by just setting the # default configuration directory on the config object instead. sample_file = 'keystone.conf.sample' args = ['--namespace', 'keystone', '--output-file', unit.dirs.etc(sample_file)] generator.main(args=args) config_files.insert(0, unit.dirs.etc(sample_file)) self.addCleanup(os.remove, unit.dirs.etc(sample_file)) return config_files
def config_generator(): args = sys.argv[1:] if args is None: args = ['--output-file', 'etc/gnocchi/gnocchi.conf'] return generator.main([ '--config-file', '%s/../gnocchi-config-generator.conf' % os.path.dirname(__file__) ] + args)
def config_generator(): args = sys.argv[1:] if args is None: args = ['--output-file', 'etc/gnocchi/gnocchi.conf'] return generator.main(['--config-file', '%s/../gnocchi-config-generator.conf' % os.path.dirname(__file__)] + args)
def setup(app): global _RUN if _RUN: return # NOTE(sileht): On gnocchi.xyz, we build a multiversion of the docs # all versions are built with the master gnocchi.gendoc sphinx extension. # So the hack here run an other python script to generate the rest.rst # file of old version of the module. # It also drop the database before each run. if sys.argv[0].endswith("sphinx-versioning"): subprocess.check_call(["dropdb", os.environ['PGDATABASE']]) subprocess.check_call(["createdb", os.environ['PGDATABASE']]) from sphinxcontrib.versioning import sphinx_ version = sphinx_.EventHandlers.CURRENT_VERSION with tempfile.NamedTemporaryFile() as f: f.write(multiversion_hack % app.confdir) f.flush() subprocess.check_call(['python', f.name, version]) _RUN = True return # TODO(jd) Do not hardcode doc/source with open("doc/source/rest.yaml") as f: scenarios = ScenarioList(yaml.load(f)) test = test_rest.RestTest() test.auth_mode = "basic" test.setUpClass() test.setUp() webapp = test.app try: for entry in scenarios: if 'filter' in entry: entry['filter'] = jinja2.Template(entry['filter']).render( scenarios=scenarios) template = jinja2.Template(entry['request']) fake_file = six.moves.cStringIO() content = template.render(scenarios=scenarios) if six.PY2: content = content.encode('utf-8') fake_file.write(content) fake_file.seek(0) request = webapp.RequestClass.from_file(fake_file) # TODO(jd) Fix this lame bug in webob < 1.7 if (hasattr(webob.request, "http_method_probably_has_body") and request.method == "DELETE"): # Webob has a bug it does not read the body for DELETE, l4m3r clen = request.content_length if clen is None: request.body = fake_file.read() else: request.body = fake_file.read(clen) app.info("Doing request %s: %s" % (entry['name'], six.text_type(request))) with webapp.use_admin_user(): response = webapp.request(request) entry['response'] = response entry['doc'] = _format_request_reply(request, response) finally: test.tearDown() test.tearDownClass() with open("doc/source/rest.j2", "r") as f: content = f.read() if six.PY2: content = content.decode("utf-8") template = jinja2.Template(content) with open("doc/source/rest.rst", "w") as f: content = template.render(scenarios=scenarios) if six.PY2: content = content.encode("utf-8") f.write(content) config_output_file = 'doc/source/gnocchi.conf.sample' app.info("Generating %s" % config_output_file) generator.main([ '--config-file', '%s/gnocchi-config-generator.conf' % os.path.dirname(__file__), '--output-file', config_output_file, ]) _RUN = True
opt_group = cfg.OptGroup(name="simple", title="A simple example") simple_opts = [ cfg.BoolOpt("enable", default=False, help=('True enables, False disables')) ] cli_opts = [ cfg.StrOpt("file", default="gen.conf", help="the config file to save as.") ] CONF = cfg.CONF # CONF: ConfigOpts CONF.register_group(opt_group) CONF.register_opts(simple_opts, opt_group) CONF.register_cli_opts(cli_opts) if __name__ == "__main__": ''' run it: python app.py --config-file app.conf --file gen.conf ''' CONF(default_config_files=['app.conf']) CONF(sys.argv[1:]) print(CONF.simple.enable) print(CONF.file) # only registered namespaces can work.. # oslo-config-generator --namespace oslo.messaging generator.main( args=['--namespace', 'oslo.messaging', '--output-file', CONF.file])
def sdist_prehook(sdist): generator.main(["--config-file", "gnocchi-config-generator.conf"])
def setup(app): global _RUN if _RUN: return # NOTE(sileht): On gnocchi.osci.io, we build a multiversion of the docs # all versions are built with the master gnocchi.gendoc sphinx extension. # So the hack here run an other python script to generate the rest.rst # file of old version of the module. # It also drop the database before each run. if sys.argv[0].endswith("sphinx-versioning"): subprocess.check_call(["dropdb", os.environ['PGDATABASE']]) subprocess.check_call(["createdb", os.environ['PGDATABASE']]) from sphinxcontrib.versioning import sphinx_ version = sphinx_.EventHandlers.CURRENT_VERSION with tempfile.NamedTemporaryFile() as f: f.write(multiversion_hack % app.confdir) f.flush() subprocess.check_call(['python', f.name, version]) _RUN = True return # TODO(jd) Do not hardcode doc/source with open("doc/source/rest.yaml") as f: scenarios = ScenarioList(yaml.load(f, Loader=yaml.FullLoader)) test = test_rest.RestTest() test.auth_mode = "basic" test.setUpClass() test.setUp() webapp = test.app try: for entry in scenarios: if 'filter' in entry: entry['filter'] = jinja2.Template( entry['filter']).render(scenarios=scenarios) template = jinja2.Template(entry['request']) fake_file = six.moves.cStringIO() content = template.render(scenarios=scenarios) if six.PY2: content = content.encode('utf-8') fake_file.write(content) fake_file.seek(0) request = webapp.RequestClass.from_file(fake_file) # TODO(jd) Fix this lame bug in webob < 1.7 if (hasattr(webob.request, "http_method_probably_has_body") and request.method == "DELETE"): # Webob has a bug it does not read the body for DELETE, l4m3r clen = request.content_length if clen is None: request.body = fake_file.read() else: request.body = fake_file.read(clen) LOG.info("Doing request %s: %s", entry['name'], six.text_type(request)) with webapp.use_admin_user(): response = webapp.request(request) entry['response'] = response entry['doc'] = _format_request_reply(request, response) finally: test.tearDown() test.tearDownClass() with open("doc/source/rest.j2", "r") as f: content = f.read() if six.PY2: content = content.decode("utf-8") template = jinja2.Template(content) with open("doc/source/rest.rst", "w") as f: content = template.render(scenarios=scenarios) if six.PY2: content = content.encode("utf-8") f.write(content) config_output_file = 'doc/source/gnocchi.conf.sample' LOG.info("Generating %s", config_output_file) generator.main([ '--config-file', '%s/gnocchi-config-generator.conf' % os.path.dirname(__file__), '--output-file', config_output_file, ]) _RUN = True