Example #1
0
def gen_package(pkg_targets=(), repo_and_hash="", manifest_fn=""):
    """Generate the entire image package, and place it in the proper directory structure"""
    # Make the cache/ directory if necessary
    cache_path = os.path.join(os.getcwd(), "cache")
    if not os.path.isdir(cache_path):
        os.mkdir(cache_path)

    sha_filenames = []
    for pkg_target in pkg_targets:
        if pkg_target in PACKAGE_MAPPING:
            # Make the type directory
            pkg_type = PACKAGE_MAPPING[pkg_target]["type"]
            type_path = os.path.join(cache_path, pkg_type)
            if not os.path.isdir(type_path):
                os.mkdir(type_path)
            # Make the 'repository-hash' directory
            if not repo_and_hash:
                repo_and_hash = "repo-githash"
            git_path = os.path.join(type_path, repo_and_hash)
            if not os.path.isdir(git_path):
                os.mkdir(git_path)

            # Generate the package and add the the zip filename to the SHA list
            sha_filenames.append(do_gen_package(pkg_target,
                                                install_dir=git_path,
                                                repo_and_hash=repo_and_hash))
        else:
            print("Error: Specify a supported type from {}".format(
                list(PACKAGE_MAPPING.keys())))
    sha_filenames[:] = [sha_fn for sha_fn in sha_filenames if os.path.exists(sha_fn)]
    gen_sha256(sha_filenames, hash_filename="hashes.txt",
               manifest_fn=manifest_fn, repo_and_hash=repo_and_hash)
    # Return the zipfiles we've created
    return sha_filenames
Example #2
0
def gen_package(pkg_targets=(), repo_and_hash="", manifest_fn=""):
    """Generate the entire image package, and place it in the proper directory structure"""
    # Make the cache/ directory if necessary
    cache_path = os.path.join(os.getcwd(), "cache")
    if not os.path.isdir(cache_path):
        os.mkdir(cache_path)

    sha_filenames = []
    for pkg_target in pkg_targets:
        if pkg_target in PACKAGE_MAPPING:
            # Make the type directory
            pkg_type = PACKAGE_MAPPING[pkg_target]["type"]
            type_path = os.path.join(cache_path, pkg_type)
            if not os.path.isdir(type_path):
                os.mkdir(type_path)
            # Make the 'repository-hash' directory
            if not repo_and_hash:
                repo_and_hash = "repo-githash"
            git_path = os.path.join(type_path, repo_and_hash)
            if not os.path.isdir(git_path):
                os.mkdir(git_path)

            # Generate the package and add the the zip filename to the SHA list
            sha_filenames.append(do_gen_package(pkg_target, install_dir=git_path))
        else:
            print("Error: Specify a supported type from {}".format(
                list(PACKAGE_MAPPING.keys())))
    sha_filenames[:] = [sha_fn for sha_fn in sha_filenames if os.path.exists(sha_fn)]
    gen_sha256(sha_filenames, hash_filename="hashes.txt",
               manifest_fn=manifest_fn, repo_and_hash=repo_and_hash)
Example #3
0
def get_target_name(zip_filename):
    """Return the package target that created the given zip_filename"""
    for target, target_info in PACKAGE_MAPPING.items():
        # First we need to strip the Git hash out of the filename
        githash = re.findall(r"-g([\d\w]{7,8})", zip_filename)[0]
        stripped_filename = os.path.basename(zip_filename.replace(githash, "{}"))
        if stripped_filename == target_info.get("package_name", ""):
            return target
    # If it doesn't match any targets
    return ""
Example #4
0
def get_target_name(zip_filename):
    """Return the package target that created the given zip_filename"""
    for target, target_info in PACKAGE_MAPPING.items():
        # First we need to strip the Git hash out of the filename
        githash = re.findall(r"-g([\d\w]{7,8})", zip_filename)[0]
        stripped_filename = os.path.basename(
            zip_filename.replace(githash, "{}"))
        if stripped_filename == target_info.get("package_name", ""):
            return target
    # If it doesn't match any targets
    return ""
Example #5
0
def determine_targets():
    """
    Determine which image packages can be created by the files in the current directory
    :return: list of valid targets
    """
    found_targets = []
    for target, target_info in PACKAGE_MAPPING.items():
        # Grab the list of files required, but remove any files that we're going to build here,
        # like the hash files
        required_files = copy.deepcopy(target_info['files'])
        required_files[:] = [filename for filename in required_files if '.md5' not in filename]

        if all([os.path.exists(img_file) for img_file in required_files]):
            found_targets.append(target)
    return found_targets
Example #6
0
def determine_targets():
    """
    Determine which image packages can be created by the files in the current directory
    :return: list of valid targets
    """
    found_targets = []
    for target, target_info in PACKAGE_MAPPING.items():
        # Grab the list of files required, but remove any files that we're going to build here,
        # like the hash files
        required_files = copy.deepcopy(target_info['files'])
        required_files[:] = [filename for filename in required_files if '.md5' not in filename]

        check_required_files = [os.path.exists(img_file) for img_file in required_files]
        if all(check_required_files):
            found_targets.append(target)
        elif any(check_required_files):
            print("Not all package contents present for {}".format(target),
                  file=sys.stderr)
    return found_targets
Example #7
0
def determine_targets():
    """
    Determine which image packages can be created by the files in the current directory
    :return: list of valid targets
    """
    found_targets = []
    for target, target_info in list(PACKAGE_MAPPING.items()):
        # Grab the list of files required, but remove any files that we're going to build here,
        # like the hash files
        required_files = copy.deepcopy(target_info['files'])
        required_files[:] = [
            filename for filename in required_files if '.md5' not in filename
        ]

        check_required_files = [
            os.path.exists(img_file) for img_file in required_files
        ]
        if all(check_required_files):
            found_targets.append(target)
        elif any(check_required_files):
            print("Not all package contents present for {}".format(target),
                  file=sys.stderr)
    return found_targets