Beispiel #1
0
def get_credential_cache():
    """if the user has specified settings to provide a cache for credentials
       files, initialize it. The root for the folder is created if it doesn't
       exist. The path for the specific client is returned, and it's
       not assumed to be either a folder or a file (this is up to the
       developer of the client).
    """
    from sregistry.defaults import CREDENTIAL_CACHE, SREGISTRY_CLIENT

    client_credential_cache = None

    # Check 1: user can disable a credential cache on the client level
    if CREDENTIAL_CACHE is not None:
        env = "SREGISTRY_DISABLE_CREDENTIAL_%s" % SREGISTRY_CLIENT.upper()
        if os.environ.get(env) is not None:
            bot.debug("[%s] cache disabled" % SREGISTRY_CLIENT)
            CREDENTIAL_CACHE = None

    # Check 2: user can disable a credential cache on the client level
    if CREDENTIAL_CACHE is not None:
        if not os.path.exists(CREDENTIAL_CACHE):
            mkdir_p(CREDENTIAL_CACHE)
        client_credential_cache = "%s/%s" % (CREDENTIAL_CACHE,
                                             SREGISTRY_CLIENT)
    if client_credential_cache is not None:
        bot.debug("credentials cache")
    return client_credential_cache
Beispiel #2
0
def test_mkdir_p(tmp_path):
    print("Testing utils.mkdir_p")
    from sregistry.utils import mkdir_p
    dirname = str(tmp_path / "input")
    result = os.path.join(dirname, "level1", "level2", "level3")
    mkdir_p(result)
    assert os.path.exists(result)
Beispiel #3
0
def get_storage_name(self, names, remove_dir=False):
    '''use a parsed names dictionary from get_image_name (above) to return
       the path in storage based on the user's preferences

       Parameters
       ==========
       names: the output from parse_image_name
    '''
    storage_folder = os.path.dirname(names['storage'])
    storage_folder = "%s/%s" % (self.storage, storage_folder)
    mkdir_p(storage_folder)
    file_name = names['storage'].replace('/', '-')
    storage_path = "%s/%s" % (self.storage, file_name)
    if remove_dir is True:
        return file_name
    return storage_path
Beispiel #4
0
def get_download_cache(self, destination, subfolder="docker"):
    """determine the user preference for atomic download of layers. If
       the user has set a singularity cache directory, honor it. Otherwise,
       use the Singularity default.
    """
    # First priority after user specification is Singularity Cache
    if destination is None:
        destination = self._get_setting("SINGULARITY_CACHEDIR", SINGULARITY_CACHE)

        # If not set, the user has disabled (use tmp)
        destination = get_tmpdir(destination)

    if not destination.endswith(subfolder):
        destination = "%s/%s" % (destination, subfolder)

    # Create subfolders, if don't exist
    mkdir_p(destination)
    return destination
Beispiel #5
0
def get_storage_name(self, names, remove_dir=False):
    """use a parsed names dictionary from get_image_name (above) to return
       the path in storage based on the user's preferences

       Parameters
       ==========
       names: the output from parse_image_name
    """
    storage_folder = os.path.join(names["collection"], names["image"])
    storage_filename = names["storage"].replace(storage_folder, "", 1).strip(":")

    # If the client doesn't have a database, default to PWD
    if not hasattr(self, "storage"):
        return os.path.basename(names["storage"])

    storage_folder = os.path.join(self.storage, storage_folder)
    mkdir_p(storage_folder)
    storage_path = os.path.join(storage_folder, storage_filename)
    if remove_dir:
        return storage_filename
    return storage_path