Ejemplo n.º 1
0
def option_parser():
    defaults = dict(site_template=G.M_SITE_DEFAULT, **O.M_DEFAULTS)

    p = O.option_parser(defaults, "%prog [OPTION ...]")
    p.add_option("-S", "--site-template",
                 help="Site template name, e.g. default, rhui. [%default]")
    return p
Ejemplo n.º 2
0
def build(argv):
    """
    Configure and build files.
    """
    defaults = dict(build=True, genconf=True, **MO.M_DEFAULTS)

    p = MO.option_parser(defaults)
    p.add_option("--no-build", action="store_false", dest="build",
                 help="Do not build, generate ks.cfg, vm build scripts, etc.")
    p.add_option("--no-genconf", action="store_false", dest="genconf",
                 help="Do not generate config from context files")
    (options, args) = p.parse_args(argv)

    miniascape.globals.set_loglevel(options.verbose)
    options = MO.tweak_options(options)

    # suppress logs from anyconfig unless the environment variable
    # 'ANYCONFIG_DEBUG' is set to 1.
    if os.environ.get("ANYCONFIG_DEBUG", None) != '1':
        anyconfig.set_loglevel(logging.WARN)

    # configure
    if options.genconf:
        confdir = miniascape.site.configure(options.ctxs, options.tmpldir,
                                            options.workdir, options.site)

    if not options.build:
        return

    # ... and build (generate all).
    cf = miniascape.config.ConfFiles(confdir)

    miniascape.host.gen_host_files(cf, options.tmpldir, options.workdir, True)
    miniascape.guest.gen_all(cf, options.tmpldir, options.workdir)
Ejemplo n.º 3
0
def option_parser():
    defaults = dict(site_template=G.M_SITE_DEFAULT, **O.M_DEFAULTS)

    p = O.option_parser(defaults, "%prog [OPTION ...]")
    p.add_option("-S",
                 "--site-template",
                 help="Site template name, e.g. default, rhui. [%default]")
    return p
Ejemplo n.º 4
0
    def test_14__tweak_options__ctx(self):
        p = TT.option_parser()
        (options, _) = p.parse_args(["--ctx", "/tmp/foo"])

        # defaults = TT.M_DEFAULTS_POST

        options = TT.tweak_options(options)
        self.assertEquals(options.site, None)
        self.assertEquals(options.ctxs, ["/tmp/foo"])
Ejemplo n.º 5
0
def option_parser():
    defaults = dict(force=False, yes=False, dryrun=False,
                    confdir=G.site_confdir(), **O.M_DEFAULTS)

    p = O.option_parser(defaults, "%prog [OPTION ...]")
    p.add_option("-f", "--force", action="store_true",
                 help="Force outputs even if these exist")
    p.add_option("", "--dryrun", action="store_true", help="Dry run mode")
    p.add_option("-c", "--confdir",
                 help="Top dir to hold site configuration files or "
                      "configuration file [%default]")
    return p
Ejemplo n.º 6
0
    def test_12__tweak_options__site(self):
        p = TT.option_parser()
        (options, _) = p.parse_args([])

        defaults = TT.M_DEFAULTS_POST

        self.assertEquals(options.site, None)
        options = TT.tweak_options(options)
        self.assertEquals(options.site, defaults["site"])

        (options, _) = p.parse_args(["--site", "foo"])
        options = TT.tweak_options(options)
        self.assertEquals(options.site, "foo")
Ejemplo n.º 7
0
def option_parser():
    defaults = dict(force=False,
                    yes=False,
                    dryrun=False,
                    confdir=G.site_confdir(),
                    **O.M_DEFAULTS)

    p = O.option_parser(defaults, "%prog [OPTION ...]")
    p.add_option("-f",
                 "--force",
                 action="store_true",
                 help="Force outputs even if these exist")
    p.add_option("", "--dryrun", action="store_true", help="Dry run mode")
    p.add_option("-c",
                 "--confdir",
                 help="Top dir to hold site configuration files or "
                 "configuration file [%default]")
    return p
Ejemplo n.º 8
0
    def test_10__tweak_options__tmpldir(self):
        p = TT.option_parser()
        (options, _) = p.parse_args([])

        self.assertEquals(options.tmpldir, [])

        # It seems that optparse holds option values permanently so value of
        # options.tmpldir will be same even if p and options (returned from
        # p.parse_args) are re-newed:
        # options = TT.tweak_options(options)
        # self.assertEquals(options.tmpldir, [G.M_TMPL_DIR])

        (options, _) = p.parse_args(["--tmpldir", "/tmp"])

        self.assertNotEquals(options.tmpldir, [])
        self.assertEquals(options.tmpldir, ["/tmp"])

        defaults = TT.M_DEFAULTS_POST
        options = TT.tweak_options(options)

        self.assertEquals(options.tmpldir, ["/tmp", defaults["tmpldir"]])
        self.assertEquals(options.ctxs, [G.site_src_ctx()])
Ejemplo n.º 9
0
 def test_00__option_parser__wo_args(self):
     p = TT.option_parser()
     self.assertTrue(isinstance(p, TT.optparse.OptionParser))
     self.assertEquals(p.defaults, TT.M_DEFAULTS)