

def prepare_pom(root_dir, name, version, out_dir):
    '\n    Writes the pom file using the existing pom (if one exists) in the root directory.\n    Changes are made to the groupId, artifactId, and version as necessary. Also, if python has\n    spark-package-deps.txt, those are added to the pom as well.\n    '
    (group_id, artifact_id) = name.strip().split('/')
    existing_pom_path = os.path.join(root_dir, 'pom.xml')
    if os.path.isfile(existing_pom_path):
        Xml.register_namespace('', 'http://maven.apache.org/POM/4.0.0')
        old_pom = Xml.parse(existing_pom_path)
        project = old_pom.getroot()
        prefix_length = project.tag.find('project')
        assert (prefix_length > (- 1)), ('The root node of the pom file should be <project>, not: %s' % project.tag)
        prefix = project.tag[:prefix_length]
    else:
        attributes = {
            'xmlns': 'http://maven.apache.org/POM/4.0.0',
            'xmlns:xsi': 'http://www.w3.org/2001/XMLSchema-instance',
            'xsi:schemaLocation': 'http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd',
        }
        project = Xml.Element('project', attributes)
        prefix = ''
    pom_add_or_modify_tag(project, (prefix + 'groupId'), group_id, 1)
    pom_add_or_modify_tag(project, (prefix + 'artifactId'), artifact_id, 2)
    pom_add_or_modify_tag(project, (prefix + 'version'), version, 3)
    sp_deps_path = os.path.join(root_dir, 'python', 'spark-package-deps.txt')
    if os.path.isfile(sp_deps_path):
        sp_deps = open(sp_deps_path, 'r')
        for line in sp_deps.readlines():
            line = line.strip()
            if (not line.startswith('#')):
                (dep_group_id, dep_artifact_id, dep_version) = validate_and_return_sp_dep(line)
                dep = {
                    'groupId': dep_group_id,
                    'artifactId': dep_artifact_id,
                    'version': dep_version,
                }
                keys = ['groupId', 'artifactId']
                pom_add_element(project, prefix, 'dependencies', 'dependency', dep, keys, ['groupId', 'artifactId', 'version'])
    repo = {
        'id': 'SparkPackagesRepo',
        'name': 'Spark Packages Repository',
        'url': 'http://dl.bintray.com/spark-packages/maven/',
        'layout': 'default',
    }
    pom_add_element(new_pom, prefix, 'repositories', 'repository', repo, ['url'], ['id', 'name', 'url', 'layout'])
    with open(os.path.join(out_dir, ('%s-%s.pom' % (artifact_id, version))), 'w') as new_pom:
        new_pom.write(pom_pretty_print(Xml.tostring(project, encoding='UTF-8')))

dataset/ETHPy150Open databricks/spark-package-cmd-tool/python/spark_package/spark_package.py prepare_pom/VarMisuse@376/822 `project`->`new_pom`