<commit_before>import argparse
import os
import string


def generate_rpm_spec(template, patch_file):
    spec_template = string.Template(template)

    base_name, _ = os.path.splitext(patch_file)

    values = {
        'name': 'kpatch-module-{}'.format(base_name),
        'patch_file': patch_file,
        'kmod_filename': 'kpatch-{}.ko'.format(base_name),
        'description': 'Package generated from {} by '
                       'kpatch-package-builder'.format(patch_file),
        'target_kernel': '3.10.0-229.el7',
        'target_arch': 'x86_64',
    }

    return spec_template.substitute(values)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Generate RPM spec file to '
                                                 'build a kpatch package')
    parser.add_argument('patch', metavar='PATCH',
                        help='patch file from which to build the livepatch '
                             'module')
    parser.add_argument('-o', '--output', metavar='FILE', default=None,
                        help='name of output spec file')

    args = parser.parse_args()

    with open('kpatch-patch.spec') as f:
        template = f.read()

    spec_content = generate_rpm_spec(template, args.patch)

    with open(args.output, 'w') as f:
        f.write(spec_content)<commit_msg>Split arg parsing into function<commit_after>import argparse
import os
import string


def generate_rpm_spec(template, patch_file):
    spec_template = string.Template(template)

    base_name, _ = os.path.splitext(patch_file)

    values = {
        'name': 'kpatch-module-{}'.format(base_name),
        'patch_file': patch_file,
        'kmod_filename': 'kpatch-{}.ko'.format(base_name),
        'description': 'Package generated from {} by '
                       'kpatch-package-builder'.format(patch_file),
        'target_kernel': '3.10.0-229.el7',
        'target_arch': 'x86_64',
    }

    return spec_template.substitute(values)


def get_args():
    parser = argparse.ArgumentParser(description='Generate RPM spec file to '
                                                 'build a kpatch package')
    parser.add_argument('patch', metavar='PATCH',
                        help='patch file from which to build the livepatch '
                             'module')
    parser.add_argument('-o', '--output', metavar='FILE', default=None,
                        help='name of output spec file')

    return parser.parse_args()

if __name__ == '__main__':
    args = get_args()

    with open('kpatch-patch.spec') as f:
        template = f.read()

    spec_content = generate_rpm_spec(template, args.patch)

    with open(args.output, 'w') as f:
        f.write(spec_content)
{'fraction_non_alphanumeric': 0.12269712601326456, 'fraction_numerical': 0.008843036109064112, 'mean_word_length': 2.3559950556242275, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1802199', 'n_tokens_mistral': 825, 'n_tokens_neox': 785, 'n_words': 171}