# Path: alibuild_helpers/sync.py
# class NoRemoteSync:
# class PartialDownloadError(Exception):
# class HttpRemoteSync:
# class RsyncRemoteSync:
# class S3RemoteSync:
# class Boto3RemoteSync:
#   def syncToLocal(self, p, spec):
#   def syncToRemote(self, p, spec):
#   def syncDistLinksToRemote(self, link_dir):
#   def __init__(self, downloaded, size):
#   def __str__(self):
#   def __init__(self, remoteStore, architecture, workdir, insecure):
#   def getRetry(self, url, dest=None, returnResult=False, log=True, session=None):
#   def syncToLocal(self, p, spec):
#   def syncToRemote(self, p, spec):
#   def syncDistLinksToRemote(self, link_dir):
#   def __init__(self, remoteStore, writeStore, architecture, workdir):
#   def syncToLocal(self, p, spec):
#   def syncToRemote(self, p, spec):
#   def syncDistLinksToRemote(self, link_dir):
#   def __init__(self, remoteStore, writeStore, architecture, workdir):
#   def syncToLocal(self, p, spec):
#   def syncToRemote(self, p, spec):
#   def syncDistLinksToRemote(self, link_dir):
#   def __init__(self, remoteStore, writeStore, architecture, workdir):
#   def _s3_init(self):
#   def _s3_listdir(self, dirname):
#   def _s3_key_exists(self, key):
#   def syncToLocal(self, p, spec):
#   def syncToRemote(self, p, spec):
#   def syncDistLinksToRemote(self, link_dir):
# 
# Path: alibuild_helpers/utilities.py
# def resolve_links_path(architecture, package):
#   """Return the path where symlinks for the given package are to be stored.
# 
#   The returned path is relative to the working directory (normally sw/) or the
#   root of the remote store.
#   """
#   return "/".join(("TARS", architecture, package))
# 
# def resolve_store_path(architecture, spec_hash):
#   """Return the path where a tarball with the given hash is to be stored.
# 
#   The returned path is relative to the working directory (normally sw/) or the
#   root of the remote store.
#   """
#   return "/".join(("TARS", architecture, "store", spec_hash[:2], spec_hash))


import sys
import unittest
from io import BytesIO
    from unittest.mock import patch, MagicMock   # In Python 3, mock is built-in
    from mock import patch, MagicMock   # Python 2
from alibuild_helpers import sync
from alibuild_helpers.utilities import resolve_links_path, resolve_store_path
        from botocore.exceptions import ClientError
                syncer.syncToLocal("zlib", self.spec)
                syncer.syncToRemote("zlib", self.spec)
                syncer.syncDistLinksToRemote("/sw/dist")

        self.spec["hash"] = self.spec["remote_revision_hash"] = NONEXISTENT_HASH
        self.spec["remote_hashes"] = [NONEXISTENT_HASH]
        for syncer in syncers:
            syncer.syncToLocal("zlib", self.spec)


class Boto3TestCase(unittest.TestCase):
    def setUp(self):
        self.spec = DUMMY_SPEC.copy()

    def mock_s3(self):

        def paginate_listdir(Bucket, Delimiter, Prefix):
            if "/store/" in Prefix:
                store_path = resolve_store_path(ARCHITECTURE, self.spec["remote_revision_hash"])
                if self.spec["remote_revision_hash"] == GOOD_HASH:
                    return [{"Contents": [{"Key": store_path + Delimiter +
                                           "zlib-v1.2.3-1.slc7_x86-64.tar.gz"}]}]
                elif self.spec["remote_revision_hash"] == BAD_HASH:
                    return [{"Contents": [{"Key": store_path + Delimiter +
                                           "zlib-v1.2.3-2.slc7_x86-64.tar.gz"}]}]
                elif self.spec["remote_revision_hash"] == NONEXISTENT_HASH:
                    return [{}]
            elif Prefix.endswith("/" + self.spec["package"] + "/"):
                links_path = resolve_links_path(ARCHITECTURE, self.spec["package"])
                return [{"Contents": [

# Path: alibuild_helpers/sync.py
# class NoRemoteSync:
# class PartialDownloadError(Exception):
# class HttpRemoteSync:
# class RsyncRemoteSync:
# class S3RemoteSync:
# class Boto3RemoteSync:
#   def syncToLocal(self, p, spec):
#   def syncToRemote(self, p, spec):
#   def syncDistLinksToRemote(self, link_dir):
#   def __init__(self, downloaded, size):
#   def __str__(self):
#   def __init__(self, remoteStore, architecture, workdir, insecure):
#   def getRetry(self, url, dest=None, returnResult=False, log=True, session=None):
#   def syncToLocal(self, p, spec):
#   def syncToRemote(self, p, spec):
#   def syncDistLinksToRemote(self, link_dir):
#   def __init__(self, remoteStore, writeStore, architecture, workdir):
#   def syncToLocal(self, p, spec):
#   def syncToRemote(self, p, spec):
#   def syncDistLinksToRemote(self, link_dir):
#   def __init__(self, remoteStore, writeStore, architecture, workdir):
#   def syncToLocal(self, p, spec):
#   def syncToRemote(self, p, spec):
#   def syncDistLinksToRemote(self, link_dir):
#   def __init__(self, remoteStore, writeStore, architecture, workdir):
#   def _s3_init(self):
#   def _s3_listdir(self, dirname):
#   def _s3_key_exists(self, key):
#   def syncToLocal(self, p, spec):
#   def syncToRemote(self, p, spec):
#   def syncDistLinksToRemote(self, link_dir):
# 
# Path: alibuild_helpers/utilities.py
# def resolve_links_path(architecture, package):
#   """Return the path where symlinks for the given package are to be stored.
# 
#   The returned path is relative to the working directory (normally sw/) or the
#   root of the remote store.
#   """
#   return "/".join(("TARS", architecture, package))
# 
# def resolve_store_path(architecture, spec_hash):
#   """Return the path where a tarball with the given hash is to be stored.
# 
#   The returned path is relative to the working directory (normally sw/) or the
#   root of the remote store.
#   """
#   return "/".join(("TARS", architecture, "store", spec_hash[:2], spec_hash))


# Path: tests/test_sync.py
import sys
import unittest
from io import BytesIO
    from unittest.mock import patch, MagicMock   # In Python 3, mock is built-in
    from mock import patch, MagicMock   # Python 2
from alibuild_helpers import sync
from alibuild_helpers.utilities import resolve_links_path, resolve_store_path
        from botocore.exceptions import ClientError

                syncer.syncToLocal("zlib", self.spec)
                syncer.syncToRemote("zlib", self.spec)
                syncer.syncDistLinksToRemote("/sw/dist")

        self.spec["hash"] = self.spec["remote_revision_hash"] = NONEXISTENT_HASH
        self.spec["remote_hashes"] = [NONEXISTENT_HASH]
        for syncer in syncers:
            syncer.syncToLocal("zlib", self.spec)


class Boto3TestCase(unittest.TestCase):
    def setUp(self):
        self.spec = DUMMY_SPEC.copy()

    def mock_s3(self):

        def paginate_listdir(Bucket, Delimiter, Prefix):
            if "/store/" in Prefix:
                store_path = resolve_store_path(ARCHITECTURE, self.spec["remote_revision_hash"])
                if self.spec["remote_revision_hash"] == GOOD_HASH:
                    return [{"Contents": [{"Key": store_path + Delimiter +
                                           "zlib-v1.2.3-1.slc7_x86-64.tar.gz"}]}]
                elif self.spec["remote_revision_hash"] == BAD_HASH:
                    return [{"Contents": [{"Key": store_path + Delimiter +
                                           "zlib-v1.2.3-2.slc7_x86-64.tar.gz"}]}]
                elif self.spec["remote_revision_hash"] == NONEXISTENT_HASH:
                    return [{}]
            elif Prefix.endswith("/" + self.spec["package"] + "/"):
                links_path = resolve_links_path(ARCHITECTURE, self.spec["package"])
                return [{"Contents": [

                    {"Key": links_path + Delimiter + "zlib-v1.2.3-1.slc7_x86-64.tar.gz"},