# Path: lib/exception.py
# class BaseException(Exception):
# class RequiredParameterMissing(BaseException):
# class DistributionError(BaseException):
# class DistributionDetectionError(DistributionError):
# class DistributionNotSupportedError(DistributionError):
# class DistributionVersionNotSupportedError(DistributionError):
# class PackageError(BaseException):
# class PackageSpecError(PackageError):
# class PackageDescriptorError(PackageError):
# class PackageDirectoryIsEmpty(PackageError):
# class RepositoryError(BaseException):
# class SubprocessError(BaseException):
# class TimeoutError(BaseException):
# class FilesToValidateNotFound(BaseException):
# class NoPackagesUpdated(BaseException):
#     DEFAULT_MESSAGE = "Failed to build packages"
#     DEFAULT_MESSAGE = "Required parameter '%(parameter)s' is missing"
#     DEFAULT_MESSAGE = "Distribution not Supported"
#     DEFAULT_MESSAGE = "Failed to detect system's GNU/Linux distribution"
#     DEFAULT_MESSAGE = "%(distribution)s distribution is not supported"
#     DEFAULT_MESSAGE = "%(distribution)s version %(version)s is not supported"
#     DEFAULT_MESSAGE = "Failed to gather %(package)s's information"
#     DEFAULT_MESSAGE = (
#         "%(package)s's spec for %(distro)s %(distro_version)s not Found.")
#     DEFAULT_MESSAGE = "Missing data in %(package)s's YAML descriptor"
#     DEFAULT_MESSAGE = "No packages to build. Packages directory is empty."
#     DEFAULT_MESSAGE = (
#         "Failed to setup %(repo_name)s's repository at %(repo_path)s.")
#     DEFAULT_MESSAGE = (
#         "%(cmd)s returned non-zero exit code: ret:%(returncode)i, "
#         "stdout: %(stdout)s, stderr: %(stderr)s")
#     DEFAULT_MESSAGE = (
#         "Timeout failure on %(func_name)s after %(num_attempts)s attempts. "
#         "Initial timeout: %(initial_timeout)s, final timeout: "
#         "%(final_timeout)s.")
#     DEFAULT_MESSAGE = (
#         "Files to be validated not found in base directory.")
#     DEFAULT_MESSAGE = (
#         "No packages were updated since last commit.")
#     def __init__(self, message=None, **kwargs):
# 
# Path: lib/repository.py
# CONF = config.get_config().CONF
# LOG = logging.getLogger(__name__)
# MAIN_REMOTE_NAME = "origin"
#         REPO_REMOTE_NAME = "push-remote"
# class PushError(Exception):
# class GitRepository(git.Repo):
# class SvnRepository():
#     def __init__(self, push_info):
# def get_git_repository(remote_repo_url, parent_dir_path, name=None):
# def get_svn_repository(remote_repo_url, repo_path):
#     def clone_from(cls, remote_repo_url, repo_path, proxy=None, *args, **kwargs):
#     def __init__(self, repo_path, *args, **kwargs):
#     def name(self):
#     def checkout(self, ref_name, refspecs=None):
#     def _get_reference(self, ref_name):
#     def _update_submodules(self):
#     def archive(self, archive_name, build_dir):
#     def commit_changes(self, commit_message, committer_name, committer_email):
#     def push_head_commits(self, remote_repo_url, remote_repo_branch):
#     def force_create_remote(self, name, url):
#     def checkout_from(cls, remote_repo_url, repo_path):
#     def __init__(self, remote_repo_url, local_repo_path):
#     def name(self):
#     def checkout(self, revision):
# 
# Path: lib/constants.py
# REPOSITORIES_DIR = 'repositories'


import logging
import os
from lib import exception
from lib import repository
from lib.constants import REPOSITORIES_DIR
                        REPOSITORIES_DIR)
    url = config.get('packages_metadata_repo_url')
    name = "versions_{subcommand}".format(
        subcommand=config.get('subcommand'))
    try:
        versions_repo = repository.get_git_repository(url, path, name)
    except exception.RepositoryError:
        LOG.error("Failed to clone versions repository")
        raise

    return versions_repo


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)

# Path: lib/exception.py
# class BaseException(Exception):
# class RequiredParameterMissing(BaseException):
# class DistributionError(BaseException):
# class DistributionDetectionError(DistributionError):
# class DistributionNotSupportedError(DistributionError):
# class DistributionVersionNotSupportedError(DistributionError):
# class PackageError(BaseException):
# class PackageSpecError(PackageError):
# class PackageDescriptorError(PackageError):
# class PackageDirectoryIsEmpty(PackageError):
# class RepositoryError(BaseException):
# class SubprocessError(BaseException):
# class TimeoutError(BaseException):
# class FilesToValidateNotFound(BaseException):
# class NoPackagesUpdated(BaseException):
#     DEFAULT_MESSAGE = "Failed to build packages"
#     DEFAULT_MESSAGE = "Required parameter '%(parameter)s' is missing"
#     DEFAULT_MESSAGE = "Distribution not Supported"
#     DEFAULT_MESSAGE = "Failed to detect system's GNU/Linux distribution"
#     DEFAULT_MESSAGE = "%(distribution)s distribution is not supported"
#     DEFAULT_MESSAGE = "%(distribution)s version %(version)s is not supported"
#     DEFAULT_MESSAGE = "Failed to gather %(package)s's information"
#     DEFAULT_MESSAGE = (
#         "%(package)s's spec for %(distro)s %(distro_version)s not Found.")
#     DEFAULT_MESSAGE = "Missing data in %(package)s's YAML descriptor"
#     DEFAULT_MESSAGE = "No packages to build. Packages directory is empty."
#     DEFAULT_MESSAGE = (
#         "Failed to setup %(repo_name)s's repository at %(repo_path)s.")
#     DEFAULT_MESSAGE = (
#         "%(cmd)s returned non-zero exit code: ret:%(returncode)i, "
#         "stdout: %(stdout)s, stderr: %(stderr)s")
#     DEFAULT_MESSAGE = (
#         "Timeout failure on %(func_name)s after %(num_attempts)s attempts. "
#         "Initial timeout: %(initial_timeout)s, final timeout: "
#         "%(final_timeout)s.")
#     DEFAULT_MESSAGE = (
#         "Files to be validated not found in base directory.")
#     DEFAULT_MESSAGE = (
#         "No packages were updated since last commit.")
#     def __init__(self, message=None, **kwargs):
# 
# Path: lib/repository.py
# CONF = config.get_config().CONF
# LOG = logging.getLogger(__name__)
# MAIN_REMOTE_NAME = "origin"
#         REPO_REMOTE_NAME = "push-remote"
# class PushError(Exception):
# class GitRepository(git.Repo):
# class SvnRepository():
#     def __init__(self, push_info):
# def get_git_repository(remote_repo_url, parent_dir_path, name=None):
# def get_svn_repository(remote_repo_url, repo_path):
#     def clone_from(cls, remote_repo_url, repo_path, proxy=None, *args, **kwargs):
#     def __init__(self, repo_path, *args, **kwargs):
#     def name(self):
#     def checkout(self, ref_name, refspecs=None):
#     def _get_reference(self, ref_name):
#     def _update_submodules(self):
#     def archive(self, archive_name, build_dir):
#     def commit_changes(self, commit_message, committer_name, committer_email):
#     def push_head_commits(self, remote_repo_url, remote_repo_branch):
#     def force_create_remote(self, name, url):
#     def checkout_from(cls, remote_repo_url, repo_path):
#     def __init__(self, remote_repo_url, local_repo_path):
#     def name(self):
#     def checkout(self, revision):
# 
# Path: lib/constants.py
# REPOSITORIES_DIR = 'repositories'


# Path: lib/versions_repository.py
import logging
import os
from lib import exception
from lib import repository
from lib.constants import REPOSITORIES_DIR

                        REPOSITORIES_DIR)
    url = config.get('packages_metadata_repo_url')
    name = "versions_{subcommand}".format(
        subcommand=config.get('subcommand'))
    try:
        versions_repo = repository.get_git_repository(url, path, name)
    except exception.RepositoryError:
        LOG.error("Failed to clone versions repository")
        raise

    return versions_repo


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: