# Path: lib/build_info.py
# CONF = config.get_config().CONF
# LOG = logging.getLogger(__name__)
# class PackageInfo(object):
#     def __init__(self, pkg):
#     def __getattr__(self, attr):
#     def sources(self):
#     def rpms(self):
# def query_pkgs_info(packages, target_attrs, include_unbuilt=False):
# def write_build_info(build_manager, versions_repo):
# 
# Path: lib/build_manager.py
# CONF = config.get_config().CONF
# LOG = logging.getLogger(__name__)
# class BuildManager(object):
#     def __init__(self, packages_names, distro):
#     def _build_packages(self, distro, packages):
#     def build(self):
# 
# Path: lib/packages_manager.py
# CONF = config.get_config().CONF
# LOG = logging.getLogger(__name__)
# class PackagesManager(object):
#     def __init__(self, packages_names):
#     def prepare_packages(self, packages_class=Package,
#                          download_source_code=True, **packages_keyword_args):
# def discover_packages():
# 
# Path: lib/versions_repository.py
# def setup_versions_repository(config):
#     """
#     Prepare the packages metadata Git repository, cloning it and
#     checking out at the chosen branch.
# 
#     Args:
#         config (dict): configuration dictionary
# 
#     Raises:
#         exception.RepositoryError: if the clone or checkout are
#             unsuccessful
#     """
#     versions_repo = get_versions_repository(config)
#     branch = config.get('packages_metadata_repo_branch')
#     refspecs = config.get('packages_metadata_repo_refspecs')
#     try:
#         versions_repo.checkout(branch, refspecs)
#     except exception.RepositoryError:
#         LOG.error("Failed to checkout versions repository")
#         raise
# 
#     return versions_repo


import logging
from lib import distro_utils
from lib import build_info
from lib import build_manager
from lib import packages_manager
from lib.versions_repository import setup_versions_repository
# Copyright (C) IBM Corp. 2016.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.



LOG = logging.getLogger(__name__)


def run(CONF):
    versions_repo = setup_versions_repository(CONF)
    packages_to_build = (CONF.get('packages') or
                         packages_manager.discover_packages())
    distro = distro_utils.get_distro(
        CONF.get('distro_name'),
        CONF.get('distro_version'),
        CONF.get('architecture'))

    # get packages names

# Path: lib/build_info.py
# CONF = config.get_config().CONF
# LOG = logging.getLogger(__name__)
# class PackageInfo(object):
#     def __init__(self, pkg):
#     def __getattr__(self, attr):
#     def sources(self):
#     def rpms(self):
# def query_pkgs_info(packages, target_attrs, include_unbuilt=False):
# def write_build_info(build_manager, versions_repo):
# 
# Path: lib/build_manager.py
# CONF = config.get_config().CONF
# LOG = logging.getLogger(__name__)
# class BuildManager(object):
#     def __init__(self, packages_names, distro):
#     def _build_packages(self, distro, packages):
#     def build(self):
# 
# Path: lib/packages_manager.py
# CONF = config.get_config().CONF
# LOG = logging.getLogger(__name__)
# class PackagesManager(object):
#     def __init__(self, packages_names):
#     def prepare_packages(self, packages_class=Package,
#                          download_source_code=True, **packages_keyword_args):
# def discover_packages():
# 
# Path: lib/versions_repository.py
# def setup_versions_repository(config):
#     """
#     Prepare the packages metadata Git repository, cloning it and
#     checking out at the chosen branch.
# 
#     Args:
#         config (dict): configuration dictionary
# 
#     Raises:
#         exception.RepositoryError: if the clone or checkout are
#             unsuccessful
#     """
#     versions_repo = get_versions_repository(config)
#     branch = config.get('packages_metadata_repo_branch')
#     refspecs = config.get('packages_metadata_repo_refspecs')
#     try:
#         versions_repo.checkout(branch, refspecs)
#     except exception.RepositoryError:
#         LOG.error("Failed to checkout versions repository")
#         raise
# 
#     return versions_repo


# Path: lib/subcommands/build_packages.py
import logging
from lib import distro_utils
from lib import build_info
from lib import build_manager
from lib import packages_manager
from lib.versions_repository import setup_versions_repository

# Copyright (C) IBM Corp. 2016.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.



LOG = logging.getLogger(__name__)


def run(CONF):
    versions_repo = setup_versions_repository(CONF)
    packages_to_build = (CONF.get('packages') or
                         packages_manager.discover_packages())
    distro = distro_utils.get_distro(
        CONF.get('distro_name'),
        CONF.get('distro_version'),
        CONF.get('architecture'))

    # get packages names

    packages_to_build_names = []