Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 52 additions & 44 deletions publish-to-cgw-wrapper/publish_to_cgw_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,16 @@ def generate_metadata(
version_id,
version_name,
mirror_openshift_Push,
component_index,
):
"""
Generate metadata for files listed in 'files' and present in the content_dir.
Also includes metadata for checksum files starting with 'sha256' or component name.

Ordering scheme:
- Checksum files get fixed orders 1, 2, 3.
- Regular files get order = component_index * 1000 + file_position.
This keeps each component's files in a unique range.
"""

logging.info(f"Generating metadata for files in {content_dir}")
Expand All @@ -204,51 +210,51 @@ def generate_metadata(
if mirror_openshift_Push:
shortURL_base = "/pub/cgw"

# Build file_lookup from source field (using basename of source)
file_lookup = {os.path.basename(file["source"]) for file in files}
metadata = []
dir_contents = set(os.listdir(content_dir))

for file_name in os.listdir(content_dir):
if file_name in file_lookup:
logging.info(f"Processing file: {file_name}")
metadata.append(
{
**default_values_per_component,
"shortURL": f"{shortURL_base}/{product_code}/{version_name}/{file_name}",
"productVersionId": version_id,
"downloadURL": generate_download_url(content_dir, file_name),
"label": file_name,
}
)
elif file_name.startswith("sha256") or file_name.startswith(component_name):
logging.info(f"Processing file: {file_name}")
label = None
if file_name.endswith(".gpg"):
label = "Checksum - GPG"
elif file_name.endswith(".sig"):
label = "Checksum - Signature"
elif file_name.endswith(".txt"):
label = "Checksum"

if label:
metadata.append(
{
**default_values_per_component,
"productVersionId": version_id,
"downloadURL": generate_download_url(content_dir, file_name),
"shortURL": (
f"{shortURL_base}/{product_code}/{version_name}/{file_name}"
),
"label": label,
}
)
else:
# Skip files that arent listed in files and aren't a checksum.
logging.warning(
f"Skipping file: {file_name} "
"as it's not listed in component 'files' and not a checksum."
)
# Checksum files always get fixed orders 1, 2, 3
checksum_files = [
("sha256sum.txt", "Checksum", 1),
("sha256sum.txt.gpg", "Checksum - GPG", 2),
("sha256sum.txt.sig", "Checksum - Signature", 3),
]

# Regular files get order = component_index * 1000 + position
rpa_files = [
(os.path.basename(f["source"]), os.path.basename(f["source"]))
for f in files
if os.path.basename(f["source"]) in dir_contents
]

metadata = []
for name, label, order in checksum_files:
if name not in dir_contents:
continue
logging.info(f"Processing file: {name} (order={order}, label={label})")
metadata.append(
{
**default_values_per_component,
"shortURL": f"{shortURL_base}/{product_code}/{version_name}/{name}",
"productVersionId": version_id,
"downloadURL": generate_download_url(content_dir, name),
"label": label,
"order": order,
}
)

for i, (file_name, label) in enumerate(rpa_files):
order = component_index * 1000 + i
logging.info(f"Processing file: {file_name} (order={order}, label={label})")
metadata.append(
{
**default_values_per_component,
"shortURL": f"{shortURL_base}/{product_code}/{version_name}/{file_name}",
"productVersionId": version_id,
"downloadURL": generate_download_url(content_dir, file_name),
"label": label,
"order": order,
}
)

return metadata

Expand Down Expand Up @@ -365,7 +371,7 @@ def create_files(*, host, session, product_id, version_id, metadata):
raise RuntimeError(f"Failed to create file: {e}")


def process_component(*, host, session, component, dry_run=False):
def process_component(*, host, session, component, dry_run=False, component_index):
"""
Process a component retrieve product/version ID,
generate metadata, create files, and return the result
Expand Down Expand Up @@ -405,6 +411,7 @@ def process_component(*, host, session, component, dry_run=False):
version_id=product_version_id,
version_name=productVersionName,
mirror_openshift_Push=mirror_openshift_Push,
component_index=component_index,
)

if dry_run:
Expand Down Expand Up @@ -483,6 +490,7 @@ def main():
session=session,
component=component,
dry_run=args.dry_run,
component_index=num,
)
if result_data is None:
continue
Expand Down
Loading