Ejemplo n.º 1
0
def makefile(control):
    '''write file valavm.makefile with these targets
    valavm-{feature_group}-{locality}-{system}
    all
    '''
    months = ('200512', '200601', '200602', '200603', '200604', '200605',
              '200606', '200607', '200608', '200609', '200610', '200611',
              '200612', '200701', '200702', '200703', '200704', '200705',
              '200706', '200707', '200708', '200709', '200710', '200711',
              '200712', '200801', '200802', '200803', '200804', '200805',
              '200806', '200807', '200808', '200809', '200810', '200811',
              '200812', '200901', '200902')

    def make_jobs(args):
        jobs = {}
        for index in range(0, len(args), 2):
            system_name = args[index]
            hardware_threads = args[index + 1]
            jobs[system_name] = int(hardware_threads)
        return jobs

    def make_system_generator(jobs):
        systems = jobs.keys()
        for system in itertools.cycle(systems):
            for index in xrange(jobs[system]):
                yield system

    def make_system_months(jobs, months):
        result = collections.defaultdict(list)
        system_generator = make_system_generator(jobs)
        for month in months:
            system = system_generator.next()
            result[system].append(month)
        return result

    def make_variable(feature_group, locality, system, month):
        lhs = 'valavm-%s-all-%s-%s' % (feature_group, locality, system)
        rhs = '../data/working/valavm/%s-all-%s/%s' % (feature_group, locality,
                                                       month)
        line = '%s += %s' % (lhs, rhs)
        return line

    def make_target(feature_group, locality, system):
        var = 'valavm-%s-all-%s-%s' % (feature_group, locality, system)
        line = '%s : $(%s)' % (var, var)
        return line

    def make_rule(feature_group, locality, month):
        target_lhs = '../data/working/valavm/%s-all-%s/%s' % (feature_group,
                                                              locality, month)
        target_rhs = 'valavm.py ' + control.path_in_samples
        target_line = '%s : %s' % (target_lhs, target_rhs)

        recipe_line = '\t~/anaconda2/bin/python valavm.py %s-all-%s-%s' % (
            feature_group, locality, month)

        return (target_line, recipe_line)

    args = control.arg.makefile.split(' ')
    jobs = make_jobs(args)
    system_months = make_system_months(jobs, months)

    report_variables = Report()
    report_variables.append('# valavm variables')
    report_targets = Report()
    report_targets.append('# valavm targets')
    report_rules = Report()
    report_rules.append('# valavm rules')
    # for now, only implement hps 'all'
    for feature_group in ('s', 'sw', 'swp', 'swpn'):
        for locality in ('city', 'global'):
            for system in jobs.keys():
                for month in system_months[system]:
                    report_variables.append(
                        make_variable(feature_group, locality, system, month))
                    report_rules.append_lines(
                        make_rule(feature_group, locality, month))
                report_targets.append(
                    make_target(feature_group, locality, system))
    report_variables.append_report(report_targets)
    report_variables.append_report(report_rules)
    report_variables.write(control.path_out_makefile)
    return