<commit_before>#!/usr/bin/env python
# coding: utf-8
from twiml_generator import TwimlCodeGenerator, load_language_spec
from pathlib import Path
from lxml.etree import XMLSyntaxError

import argparse

LANGUAGES_VERSIONS = {
    'python': '6.x',
    'java': '7.x',
    'csharp': '5.x',
    'node': '3.x',
    'php': '5.x'
}


def generate_code_sample_filepath(twiml_filepath, language):
    if language not in LANGUAGES_VERSIONS:
        raise Exception('Unkown language to generate : {}'.format(language))

    language_spec = load_language_spec(language)
    version = LANGUAGES_VERSIONS[language]
    return twiml_filepath.parent.parent / (twiml_filepath.name[:-3] + version + language_spec['extension'])


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("root_twiml_filepath", help="Path to a directory containing TwiML file")
    parser.add_argument("-l", "--languages", help="Languages for the code to generate (default: all)",
                        choices=['csharp', 'java', 'node', 'php', 'python'],
                        action="append")
    args = parser.parse_args()

    if not args.languages:
        languages = LANGUAGES_VERSIONS.keys()
    else:
        languages = args.languages

    filepaths = Path(args.root_twiml_filepath).glob('**/*.xml')
    for twiml_filepath in filepaths:
        try:
            for language in languages:
                code_filepath = generate_code_sample_filepath(twiml_filepath, language)
                print("{} -> {}".format(twiml_filepath, code_filepath))
                code_generator = TwimlCodeGenerator(twiml_filepath, language=language)
                if language in ['java', 'csharp', 'php']:
                    code_generator.overwrite_language_spec('formatter', 'node ../code-sample-formatter/app.js -f {filepath}')
                code_generator.write_code()
        except XMLSyntaxError as e:
            print('Error parsing : {}'.format(twiml_filepath))
<commit_msg>Add specific code_filepath whene generating a snippet<commit_after>#!/usr/bin/env python
# coding: utf-8
from twiml_generator import TwimlCodeGenerator, load_language_spec
from pathlib import Path
from lxml.etree import XMLSyntaxError

import argparse

LANGUAGES_VERSIONS = {
    'python': '6.x',
    'java': '7.x',
    'csharp': '5.x',
    'node': '3.x',
    'php': '5.x'
}


def generate_code_sample_filepath(twiml_filepath, language):
    if language not in LANGUAGES_VERSIONS:
        raise Exception('Unkown language to generate : {}'.format(language))

    language_spec = load_language_spec(language)
    version = LANGUAGES_VERSIONS[language]
    return twiml_filepath.parent.parent / (twiml_filepath.name[:-3] + version + language_spec['extension'])


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("root_twiml_filepath", help="Path to a directory containing TwiML file")
    parser.add_argument("-l", "--languages", help="Languages for the code to generate (default: all)",
                        choices=['csharp', 'java', 'node', 'php', 'python'],
                        action="append")
    args = parser.parse_args()

    if not args.languages:
        languages = LANGUAGES_VERSIONS.keys()
    else:
        languages = args.languages

    filepaths = Path(args.root_twiml_filepath).glob('**/*.xml')
    for twiml_filepath in filepaths:
        try:
            for language in languages:
                code_filepath = generate_code_sample_filepath(twiml_filepath, language)
                print("{} -> {}".format(twiml_filepath, code_filepath))
                code_generator = TwimlCodeGenerator(twiml_filepath, code_filepath=code_filepath, language=language)
                if language in ['java', 'csharp', 'php']:
                    code_generator.overwrite_language_spec('formatter', 'node ../code-sample-formatter/app.js -f {filepath}')
                code_generator.write_code()
        except XMLSyntaxError as e:
            print('Error parsing : {}'.format(twiml_filepath))

{'fraction_non_alphanumeric': 0.11995043370508054, 'fraction_numerical': 0.003469640644361834, 'mean_word_length': 3.1437371663244353, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '244724', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1230, 'n_words': 269}