# Path: ros_buildfarm/common.py
# def get_os_package_name(rosdistro_name, ros_package_name):
#     return '%s%s' % \
#         (get_os_package_name_prefix(rosdistro_name),
#          ros_package_name.replace('_', '-'))


import os
import subprocess
from ros_buildfarm.common import get_os_package_name
    from rosdistro import get_cached_distribution
    from rosdistro import get_index
    from catkin_pkg.package import parse_package
# limitations under the License.




def _get_source_tag(
        rosdistro_name, pkg_name, pkg_version, os_name, os_code_name):
    assert os_name in ['fedora', 'rhel']
    return 'rpm/%s-%s_%s' % (
        get_os_package_name(rosdistro_name, pkg_name),
        pkg_version, os_code_name)


def build_sourcerpm(
        rosdistro_index_url, rosdistro_name, pkg_name, os_name, os_code_name,
        sources_dir):
    index = get_index(rosdistro_index_url)
    dist_file = get_cached_distribution(index, rosdistro_name)
    if pkg_name not in dist_file.release_packages:
        return 'Not a released package name: %s' % pkg_name

    pkg = dist_file.release_packages[pkg_name]
    repo_name = pkg.repository_name
    repo = dist_file.repositories[repo_name]
    if not repo.release_repository.version:
        return "Repository '%s' has no release version" % repo_name

    pkg_version = repo.release_repository.version
    tag = _get_source_tag(
        rosdistro_name, pkg_name, pkg_version, os_name, os_code_name)

# Path: ros_buildfarm/common.py
# def get_os_package_name(rosdistro_name, ros_package_name):
#     return '%s%s' % \
#         (get_os_package_name_prefix(rosdistro_name),
#          ros_package_name.replace('_', '-'))


# Path: ros_buildfarm/sourcerpm_job.py
import os
import subprocess
from ros_buildfarm.common import get_os_package_name
    from rosdistro import get_cached_distribution
    from rosdistro import get_index
    from catkin_pkg.package import parse_package

# limitations under the License.




def _get_source_tag(
        rosdistro_name, pkg_name, pkg_version, os_name, os_code_name):
    assert os_name in ['fedora', 'rhel']
    return 'rpm/%s-%s_%s' % (
        get_os_package_name(rosdistro_name, pkg_name),
        pkg_version, os_code_name)


def build_sourcerpm(
        rosdistro_index_url, rosdistro_name, pkg_name, os_name, os_code_name,
        sources_dir):
    index = get_index(rosdistro_index_url)
    dist_file = get_cached_distribution(index, rosdistro_name)
    if pkg_name not in dist_file.release_packages:
        return 'Not a released package name: %s' % pkg_name

    pkg = dist_file.release_packages[pkg_name]
    repo_name = pkg.repository_name
    repo = dist_file.repositories[repo_name]
    if not repo.release_repository.version:
        return "Repository '%s' has no release version" % repo_name

    pkg_version = repo.release_repository.version
    tag = _get_source_tag(
        rosdistro_name, pkg_name, pkg_version, os_name, os_code_name)

    os_pkg_name = get_os_package_name(rosdistro_name, pkg_name)