<commit_before>import gzip
import argparse
import sys
import urllib.request
import subprocess
import os

SCHEMA_LOCATION_ATTRIBUTE = 'SchemaLocation'


def launch():
    parser = ArgParser(sys.argv)

    # get clinvar schema xsd file
    schema_url = get_schema_url(parser)
    schema_temp_file = donwload_schema_file(schema_url)

    # compile xsd schema
    generate_java_binding_classes('uk.ac.ebi.eva.clinvar.model.jaxb', parser, schema_temp_file)

    remove_schema_file(schema_temp_file)


def get_schema_url(parser):
    with gzip.open(parser.input_file, 'rt') as xml_file:
        schema_url = None
        for line in xml_file:
            if SCHEMA_LOCATION_ATTRIBUTE in line:
                schema_url = line.split(SCHEMA_LOCATION_ATTRIBUTE)[1].split('"')[1]
                break

        if schema_url is None:
            print('Error: XSD schema URL not found in ' + parser.input_file)
            sys.exit(1)

    return schema_url


def donwload_schema_file(schema_url):
    schema_temp_file = schema_url.split('/')[-1]
    print('Downloading ' + schema_url + ' ... ')
    urllib.request.urlretrieve(schema_url, schema_temp_file)
    print('Done\n')
    return schema_temp_file


def generate_java_binding_classes(package_name, parser, schema_temp_file):
    java_sources_dir = parser.java_sources_dir
    if os.path.isdir(java_sources_dir + '/' + package_name.replace('.', '/')):
        print('Package ' + package_name + ' already exist. Skipping Jaxb classes generation ...\n')
    else:
        # execute xjc to compile the XSD schema
        print('Generating JAXB classes in ' + package_name + ' ...')
        subprocess.run(['xjc', '-p', package_name, '-d', java_sources_dir, schema_temp_file])
        print('Done\n')<commit_msg>Delete previous version of the Java XML binding classes when generating them for a new Clinvar version<commit_after>import gzip
import argparse
import sys
import urllib.request
import shutil
import subprocess
import os

SCHEMA_LOCATION_ATTRIBUTE = 'SchemaLocation'


def launch():
    parser = ArgParser(sys.argv)

    # get clinvar schema xsd file
    schema_url = get_schema_url(parser)
    schema_temp_file = donwload_schema_file(schema_url)

    # compile xsd schema
    generate_java_binding_classes('uk.ac.ebi.eva.clinvar.model.jaxb', parser, schema_temp_file)

    remove_schema_file(schema_temp_file)


def get_schema_url(parser):
    with gzip.open(parser.input_file, 'rt') as xml_file:
        schema_url = None
        for line in xml_file:
            if SCHEMA_LOCATION_ATTRIBUTE in line:
                schema_url = line.split(SCHEMA_LOCATION_ATTRIBUTE)[1].split('"')[1]
                break

        if schema_url is None:
            print('Error: XSD schema URL not found in ' + parser.input_file)
            sys.exit(1)

    return schema_url


def donwload_schema_file(schema_url):
    schema_temp_file = schema_url.split('/')[-1]
    print('Downloading ' + schema_url + ' ... ')
    urllib.request.urlretrieve(schema_url, schema_temp_file)
    print('Done\n')
    return schema_temp_file


def generate_java_binding_classes(package_name, parser, schema_temp_file):
    java_sources_dir = parser.java_sources_dir
    package_folder = java_sources_dir + '/' + package_name.replace('.', '/')
    if os.path.isdir(package_folder):
        print('Deleting previous version of ' + package_name + '...\n')
        shutil.rmtree(package_folder)
    # execute xjc to compile the XSD schema
    print('Generating JAXB classes in ' + package_name + ' ...')
    subprocess.run(['xjc', '-p', package_name, '-d', java_sources_dir, schema_temp_file])
    print('Done\n')
{'fraction_non_alphanumeric': 0.10239471511147812, 'fraction_numerical': 0.002202036884117809, 'mean_word_length': 3.4317073170731707, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4412239', 'n_tokens_mistral': 1180, 'n_tokens_neox': 1156, 'n_words': 252}