# 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 glob
import os
import subprocess
from ros_buildfarm.common import get_os_package_name
        from rosdistro import get_distribution_cache
        from rosdistro import get_index
    from catkin_pkg.package import parse_package
    # ensure that no source subfolder exists
    rpm_package_name = get_os_package_name(rosdistro_name, package_name)
    if not skip_download_sourcepkg:
        # get expected package version from rosdistro
        index = get_index(rosdistro_index_url)
        dist_cache = get_distribution_cache(index, rosdistro_name)
        dist_file = dist_cache.distribution_file
        assert package_name in dist_file.release_packages
        pkg = dist_file.release_packages[package_name]
        repo = dist_file.repositories[pkg.repository_name]
        package_version = repo.release_repository.version

        cmd = [
            'mock',
            '--resultdir', '%s' % sourcepkg_dir,
            '--no-cleanup-after',
            '--verbose',
            '--root', 'ros_buildfarm',
            '--dnf-cmd', '--', 'download', '--source',
            '--disablerepo', '*',
            '--enablerepo', 'ros-buildfarm-target-source',
            '%s-%s.*' % (rpm_package_name, package_version)]

        print("Invoking '%s'" % ' '.join(cmd))
        subprocess.check_call(cmd, cwd=sourcepkg_dir)


def build_binaryrpm(
        rosdistro_name, package_name, sourcepkg_dir, binarypkg_dir, append_timestamp=False,
        skip_tests=False):

# 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/binaryrpm_job.py
import glob
import os
import subprocess
from ros_buildfarm.common import get_os_package_name
        from rosdistro import get_distribution_cache
        from rosdistro import get_index
    from catkin_pkg.package import parse_package

    # ensure that no source subfolder exists
    rpm_package_name = get_os_package_name(rosdistro_name, package_name)
    if not skip_download_sourcepkg:
        # get expected package version from rosdistro
        index = get_index(rosdistro_index_url)
        dist_cache = get_distribution_cache(index, rosdistro_name)
        dist_file = dist_cache.distribution_file
        assert package_name in dist_file.release_packages
        pkg = dist_file.release_packages[package_name]
        repo = dist_file.repositories[pkg.repository_name]
        package_version = repo.release_repository.version

        cmd = [
            'mock',
            '--resultdir', '%s' % sourcepkg_dir,
            '--no-cleanup-after',
            '--verbose',
            '--root', 'ros_buildfarm',
            '--dnf-cmd', '--', 'download', '--source',
            '--disablerepo', '*',
            '--enablerepo', 'ros-buildfarm-target-source',
            '%s-%s.*' % (rpm_package_name, package_version)]

        print("Invoking '%s'" % ' '.join(cmd))
        subprocess.check_call(cmd, cwd=sourcepkg_dir)


def build_binaryrpm(
        rosdistro_name, package_name, sourcepkg_dir, binarypkg_dir, append_timestamp=False,
        skip_tests=False):

    rpm_package_name = get_os_package_name(rosdistro_name, package_name)