示例#1
0
 def write_new(config):
     conf_str = json.dumpsPretty(config.getData())
     filetool.save(configPath, conf_str)
     return
示例#2
0
def main():
    global options
    (options, args) = GeneratorArguments(option_class=ExtendAction).parse_args(sys.argv[1:])

    if args:
        options.jobs = args[0].split(',')
    else:
        options.jobs = []

    # Save cli options to Context
    gen_opts = [x for x in sys.argv[1:] if x not in args]  # cli options without jobs list
    Context.generator_opts = gen_opts  # as list

    # Initialize console
    if options.verbose:
        level = "debug"
    elif options.quiet:
        level = "warning"
    else:
        level = "info"

    console = Log(options.logfile, level)
    Context.console = console

    # Grunt compat: Print list of jobs as json
    if options.listjobs:
        config = initConfig(console, options, args)
        config.resolveIncludes()
        from misc import json
        print(json.dumpsPretty(getJobsDesc(config.getExportedJobsList(), config)))
        sys.exit(0)

    # Treat verbosity of pre-job processing
    if options.config_verbose:
        console.setLevel("debug")
        console.setFilter(["generator.config.*"])
    else:
        console.setLevel("info")

    # Show progress indicator?
    console.progress_indication = options.show_progress_indicator

    # Initial user feedback
    appname = ((os.path.dirname(os.path.abspath(options.config)).split(os.sep)))[-1]
    console.head(u"Initializing: %s" % appname.decode('utf-8'), True)
    console.info(u"Processing configuration")
    console.debug(u"    file: %s" % options.config)

    config = initConfig(console, options, args);

    # Early check for log filter -- doesn't work as there is no job selected yet
    #console.setFilter(config.get("log/filter/debug", []))

    # Resolve "include"-Keys
    console.debug("Resolving config includes...")
    console.indent()
    config.resolveIncludes()
    console.outdent()

    # Check jobs
    availableJobs = config.getExportedJobsList()
    if len(options.jobs) == 0:
        default_job = config.get("default-job", "")
        if default_job:
            options.jobs.append(default_job)
        else:
            listJobs(console, availableJobs, config)
            sys.exit(1)

    elif '_all_' in options.jobs:
        options.jobs = []
        for job in availableJobs:
            if job not in _ALL_SKIP_JOBS:
                options.jobs.append(job)
    else:
        for job in options.jobs:
            if job not in availableJobs:
                console.warn("No such job: %s" % job)
                listJobs(console, availableJobs, config)
                sys.exit(1)

    console.debug(u"Jobs: %s" % ", ".join(options.jobs))
    context = {'config': config, 'console':console, 'jobconf':None, 'interruptRegistry':interruptRegistry}
    Context.config = config # TODO: clean up overlap between context dict and Context module

    # Resolve "extend"- and "run"-Keys
    expandedjobs = config.resolveExtendsAndRuns(options.jobs[:])

    # Include system defaults
    config.includeSystemDefaults(expandedjobs)

    # Resolve "let"-Keys
    config.resolveMacros(expandedjobs)

    # Resolve libs/Manifests
    config.resolveLibs(expandedjobs)

    # To see fully expanded config:
    # console.info(pprint.pformat(config.get(".")))

    # Do some config schema checking
    config.checkSchema(expandedjobs, checkJobTypes=True)

    # Clean-up config
    config.cleanUpJobs(expandedjobs)

    # Reset console level
    console.setLevel(level)
    console.resetFilter()

    # Processing jobs...
    for job in expandedjobs:
        console.head("Executing: %s" % job.name, True)
        if options.config_verbose:
            console.setLevel("debug")
            console.debug("Expanded job config:")
            console.debug(pprint.pformat(config.getJob(job).getData()))
            console.setLevel(level)

        ctx = context.copy()
        ctx['jobconf'] = config.getJob(job)
        Context.jobconf = ctx['jobconf']

        generatorObj = Generator(ctx)
        generatorObj.run()

    return
示例#3
0
 def write_new(config):
     conf_str = json.dumpsPretty(config.getData())
     filetool.save(configPath, conf_str)
     return
示例#4
0
def main():
    global options
    (options, args) = GeneratorArguments(option_class=ExtendAction).parse_args(
        sys.argv[1:])

    if args:
        options.jobs = args[0].split(',')
    else:
        options.jobs = []

    # Save cli options to Context
    gen_opts = [x for x in sys.argv[1:]
                if x not in args]  # cli options without jobs list
    Context.generator_opts = gen_opts  # as list

    # Initialize console
    if options.verbose:
        level = "debug"
    elif options.quiet:
        level = "warning"
    else:
        level = "info"

    console = Log(options.logfile, level)
    Context.console = console

    # Grunt compat: Print list of jobs as json
    if options.listjobs:
        config = initConfig(console, options, args)
        config.resolveIncludes()
        from misc import json
        print(
            json.dumpsPretty(getJobsDesc(config.getExportedJobsList(),
                                         config)))
        sys.exit(0)

    # Treat verbosity of pre-job processing
    if options.config_verbose:
        console.setLevel("debug")
        console.setFilter(["generator.config.*"])
    else:
        console.setLevel("info")

    # Show progress indicator?
    console.progress_indication = options.show_progress_indicator

    # Initial user feedback
    appname = ((os.path.dirname(os.path.abspath(options.config)).split(
        os.sep)))[-1]
    console.head(u"Initializing: %s" % appname.decode('utf-8'), True)
    console.info(u"Processing configuration")
    console.debug(u"    file: %s" % options.config)

    config = initConfig(console, options, args)

    # Early check for log filter -- doesn't work as there is no job selected yet
    #console.setFilter(config.get("log/filter/debug", []))

    # Resolve "include"-Keys
    console.debug("Resolving config includes...")
    console.indent()
    config.resolveIncludes()
    console.outdent()

    # Check jobs
    availableJobs = config.getExportedJobsList()
    if len(options.jobs) == 0:
        default_job = config.get("default-job", "")
        if default_job:
            options.jobs.append(default_job)
        else:
            listJobs(console, availableJobs, config)
            sys.exit(1)

    elif '_all_' in options.jobs:
        options.jobs = []
        for job in availableJobs:
            if job not in _ALL_SKIP_JOBS:
                options.jobs.append(job)
    else:
        for job in options.jobs:
            if job not in availableJobs:
                console.warn("No such job: %s" % job)
                listJobs(console, availableJobs, config)
                sys.exit(1)

    console.debug(u"Jobs: %s" % ", ".join(options.jobs))
    context = {
        'config': config,
        'console': console,
        'jobconf': None,
        'interruptRegistry': interruptRegistry
    }
    Context.config = config  # TODO: clean up overlap between context dict and Context module

    # Resolve "extend"- and "run"-Keys
    expandedjobs = config.resolveExtendsAndRuns(options.jobs[:])

    # Include system defaults
    config.includeSystemDefaults(expandedjobs)

    # Resolve "let"-Keys
    config.resolveMacros(expandedjobs)

    # Resolve libs/Manifests
    config.resolveLibs(expandedjobs)

    # To see fully expanded config:
    # console.info(pprint.pformat(config.get(".")))

    # Do some config schema checking
    config.checkSchema(expandedjobs, checkJobTypes=True)

    # Clean-up config
    config.cleanUpJobs(expandedjobs)

    # Reset console level
    console.setLevel(level)
    console.resetFilter()

    # Processing jobs...
    for job in expandedjobs:
        console.head("Executing: %s" % job.name, True)
        if options.config_verbose:
            console.setLevel("debug")
            console.debug("Expanded job config:")
            console.debug(pprint.pformat(config.getJob(job).getData()))
            console.setLevel(level)

        ctx = context.copy()
        ctx['jobconf'] = config.getJob(job)
        Context.jobconf = ctx['jobconf']

        generatorObj = Generator(ctx)
        generatorObj.run()

    return