# 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/release_common.py
# def dpkg_parsechangelog(source_dir, fields):
#     cmd = ['dpkg-parsechangelog']
#     output = subprocess.check_output(cmd, cwd=source_dir)
#     values = {}
#     for line in output.decode().splitlines():
#         for field in fields:
#             prefix = '%s: ' % field
#             if line.startswith(prefix):
#                 values[field] = line[len(prefix):]
#     assert len(fields) == len(values.keys())
#     return [values[field] for field in fields]


import os
import subprocess
import sys
import traceback
from time import gmtime, strftime
from ros_buildfarm.common import get_os_package_name
from ros_buildfarm.release_common import dpkg_parsechangelog
        from rosdistro import get_distribution_cache
        from rosdistro import get_index
    from catkin_pkg.package import parse_package
            'source', '--download-only', '--only-source',
            debian_package_name + '=' + debian_package_versions[0]]
        print("Invoking '%s'" % ' '.join(cmd))
        subprocess.check_call(cmd, cwd=sourcepkg_dir)

    # extract sourcedeb
    filenames = _get_package_dsc_filename(sourcepkg_dir, debian_package_name)
    assert len(filenames) == 1, filenames
    dsc_filename = filenames[0]
    cmd = ['dpkg-source', '-x', dsc_filename]
    print("Invoking '%s'" % ' '.join(cmd))
    subprocess.check_call(cmd, cwd=sourcepkg_dir)

    # ensure that one source subfolder exists
    subfolders = _get_package_subfolders(sourcepkg_dir, debian_package_name)
    assert len(subfolders) == 1, subfolders
    source_dir = subfolders[0]

    # output package maintainers for job notification
    pkg = parse_package(source_dir)
    maintainer_emails = set([])
    for m in pkg.maintainers:
        maintainer_emails.add(m.email)
    if maintainer_emails:
        print('Package maintainer emails: %s' %
              ' '.join(sorted(maintainer_emails)))


def append_build_timestamp(rosdistro_name, package_name, sourcepkg_dir):
    # ensure that one source subfolder exists

# 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/release_common.py
# def dpkg_parsechangelog(source_dir, fields):
#     cmd = ['dpkg-parsechangelog']
#     output = subprocess.check_output(cmd, cwd=source_dir)
#     values = {}
#     for line in output.decode().splitlines():
#         for field in fields:
#             prefix = '%s: ' % field
#             if line.startswith(prefix):
#                 values[field] = line[len(prefix):]
#     assert len(fields) == len(values.keys())
#     return [values[field] for field in fields]


# Path: ros_buildfarm/binarydeb_job.py
import os
import subprocess
import sys
import traceback
from time import gmtime, strftime
from ros_buildfarm.common import get_os_package_name
from ros_buildfarm.release_common import dpkg_parsechangelog
        from rosdistro import get_distribution_cache
        from rosdistro import get_index
    from catkin_pkg.package import parse_package

            'source', '--download-only', '--only-source',
            debian_package_name + '=' + debian_package_versions[0]]
        print("Invoking '%s'" % ' '.join(cmd))
        subprocess.check_call(cmd, cwd=sourcepkg_dir)

    # extract sourcedeb
    filenames = _get_package_dsc_filename(sourcepkg_dir, debian_package_name)
    assert len(filenames) == 1, filenames
    dsc_filename = filenames[0]
    cmd = ['dpkg-source', '-x', dsc_filename]
    print("Invoking '%s'" % ' '.join(cmd))
    subprocess.check_call(cmd, cwd=sourcepkg_dir)

    # ensure that one source subfolder exists
    subfolders = _get_package_subfolders(sourcepkg_dir, debian_package_name)
    assert len(subfolders) == 1, subfolders
    source_dir = subfolders[0]

    # output package maintainers for job notification
    pkg = parse_package(source_dir)
    maintainer_emails = set([])
    for m in pkg.maintainers:
        maintainer_emails.add(m.email)
    if maintainer_emails:
        print('Package maintainer emails: %s' %
              ' '.join(sorted(maintainer_emails)))


def append_build_timestamp(rosdistro_name, package_name, sourcepkg_dir):
    # ensure that one source subfolder exists

    debian_package_name = get_os_package_name(rosdistro_name, package_name)