Skip to content

Commit d4d670c

Browse files
committed
Remove unnecessary comments
1 parent 0f8300e commit d4d670c

File tree

1 file changed

+5
-54
lines changed

1 file changed

+5
-54
lines changed

apollo/server/routes/admin_supported_products.py

Lines changed: 5 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,13 @@ async def get_entity_or_error_response(
4242
) -> Union[Model, Response]:
4343
"""Get an entity by ID or filters, or return error template response."""
4444

45-
# Build the query
4645
if entity_id is not None:
4746
query = model_class.get_or_none(id=entity_id)
4847
elif filters:
4948
query = model_class.get_or_none(**filters)
5049
else:
5150
raise ValueError("Either entity_id or filters must be provided")
5251

53-
# Add prefetch_related if specified
5452
if prefetch_related:
5553
query = query.prefetch_related(*prefetch_related)
5654

@@ -158,7 +156,6 @@ async def admin_supported_products(
158156
params=params,
159157
)
160158

161-
# Get statistics for each product
162159
for product in products.items:
163160
mirrors_count = await SupportedProductsRhMirror.filter(supported_product=product).count()
164161
repomds_count = await SupportedProductsRpmRepomd.filter(
@@ -195,7 +192,6 @@ async def export_all_configs(
195192
production_only: Optional[bool] = Query(None)
196193
):
197194
"""Export configurations for all supported products as JSON with optional filtering"""
198-
# Build query with filters
199195
query = SupportedProductsRhMirror.all()
200196
if major_version is not None:
201197
query = query.filter(match_major_version=major_version)
@@ -207,7 +203,6 @@ async def export_all_configs(
207203
"rpm_repomds"
208204
).all()
209205

210-
# Filter repositories by production status if specified
211206
config_data = []
212207
for mirror in mirrors:
213208
mirror_data = await _get_mirror_config_data(mirror)
@@ -251,14 +246,11 @@ async def _import_configuration(import_data: List[Dict[str, Any]], replace_exist
251246
mirror_data = config["mirror"]
252247
repositories_data = config["repositories"]
253248

254-
# Find or create product
255249
product = await SupportedProduct.get_or_none(name=product_data["name"])
256250
if not product:
257-
# For import, we should require products to exist already
258251
skipped_count += 1
259252
continue
260253

261-
# Check if mirror already exists
262254
existing_mirror = await SupportedProductsRhMirror.get_or_none(
263255
supported_product=product,
264256
name=mirror_data["name"],
@@ -291,7 +283,6 @@ async def _import_configuration(import_data: List[Dict[str, Any]], replace_exist
291283
await mirror.save()
292284
created_count += 1
293285

294-
# Create repositories
295286
for repo_data in repositories_data:
296287
repo = SupportedProductsRpmRepomd(
297288
supported_products_rh_mirror=mirror,
@@ -337,10 +328,8 @@ async def import_configurations(
337328
status_code=302
338329
)
339330

340-
# Validate import data
341331
validation_errors = await _validate_import_data(import_data)
342332
if validation_errors:
343-
# Limit the number of errors shown to avoid overwhelming the user
344333
max_errors = 20
345334
if len(validation_errors) > max_errors:
346335
shown_errors = validation_errors[:max_errors]
@@ -353,7 +342,6 @@ async def import_configurations(
353342
status_code=302
354343
)
355344

356-
# Import the data
357345
try:
358346
results = await _import_configuration(import_data, replace_existing)
359347
success_message = f"Import completed: {results['created']} created, {results['updated']} updated, {results['skipped']} skipped"
@@ -424,10 +412,7 @@ async def admin_supported_product_delete(
424412
}
425413
)
426414

427-
# Check for existing mirrors (which would contain blocks, overrides, and repomds)
428415
mirrors_count = await SupportedProductsRhMirror.filter(supported_product=product).count()
429-
430-
# Check for existing advisory packages and affected products
431416
packages_count = await AdvisoryPackage.filter(supported_product=product).count()
432417
affected_products_count = await AdvisoryAffectedProduct.filter(supported_product=product).count()
433418

@@ -491,7 +476,6 @@ async def admin_supported_product_mirror_new_post(
491476
return product
492477

493478
form_data_raw = await request.form()
494-
# Checkbox sends "true" when checked, nothing when unchecked
495479
active_value = "true" if "true" in form_data_raw.getlist("active") else "false"
496480

497481
form_data = {
@@ -592,7 +576,6 @@ async def admin_supported_product_mirror_post(
592576
return mirror
593577

594578
form_data = await request.form()
595-
# Checkbox sends "true" when checked, nothing when unchecked
596579
active_value = "true" if "true" in form_data.getlist("active") else "false"
597580

598581
try:
@@ -622,7 +605,6 @@ async def admin_supported_product_mirror_post(
622605
mirror.active = (active_value == "true")
623606
await mirror.save()
624607

625-
# Re-fetch the mirror with all required relations after saving
626608
mirror = await SupportedProductsRhMirror.get_or_none(
627609
id=mirror_id,
628610
supported_product_id=product_id
@@ -660,7 +642,6 @@ async def admin_supported_product_mirror_delete(
660642
if isinstance(mirror, Response):
661643
return mirror
662644

663-
# Check for existing blocks and overrides using shared logic
664645
blocks_count, overrides_count = await check_mirror_dependencies(mirror)
665646

666647
if blocks_count > 0 or overrides_count > 0:
@@ -688,51 +669,43 @@ async def admin_supported_product_mirrors_bulk_delete(
688669
"""Bulk delete multiple mirrors by calling individual delete logic for each mirror"""
689670
base_url = f"/admin/supported-products/{product_id}"
690671

691-
# Parse and validate mirror IDs
692672
if not mirror_ids or not mirror_ids.strip():
693673
return create_error_redirect(base_url, "No mirror IDs provided")
694674

695675
try:
696676
mirror_id_list = [int(id_str.strip()) for id_str in mirror_ids.split(",") if id_str.strip()]
697677
if not mirror_id_list:
698678
return create_error_redirect(base_url, "No valid mirror IDs provided")
699-
# Validate all IDs are positive
700679
for id_val in mirror_id_list:
701680
if id_val <= 0:
702681
return create_error_redirect(base_url, "All mirror IDs must be positive numbers")
703682
except ValueError:
704683
return create_error_redirect(base_url, "Invalid mirror IDs: must be comma-separated numbers")
705684

706-
# Get all mirrors to delete
707685
mirrors = await SupportedProductsRhMirror.filter(
708686
id__in=mirror_id_list, supported_product_id=product_id
709687
).prefetch_related("supported_product")
710688

711689
if not mirrors:
712690
return create_error_redirect(base_url, "No mirrors found with provided IDs")
713691

714-
# Process each mirror individually using existing single delete logic
715692
successful_deletes = []
716693
failed_deletes = []
717694

718695
for mirror in mirrors:
719-
# Check for existing blocks and overrides using shared logic
720696
blocks_count, overrides_count = await check_mirror_dependencies(mirror)
721697

722698
if blocks_count > 0 or overrides_count > 0:
723-
# Mirror has dependencies, cannot delete
724699
error_parts = format_dependency_error_parts(blocks_count, overrides_count)
725700
error_reason = f"{' and '.join(error_parts)}"
726701
failed_deletes.append({"name": mirror.name, "reason": error_reason})
727702
else:
728-
# Mirror can be deleted
729703
try:
730704
await mirror.delete()
731705
successful_deletes.append(mirror.name)
732706
except Exception as e:
733707
failed_deletes.append({"name": mirror.name, "reason": f"deletion failed: {str(e)}"})
734708

735-
# Build result message with clear formatting
736709
message_parts = []
737710

738711
if successful_deletes:
@@ -746,15 +719,12 @@ async def admin_supported_product_mirrors_bulk_delete(
746719

747720
message = ". ".join(message_parts)
748721

749-
# If we had any successful deletes, treat as success even if some failed
750722
if successful_deletes:
751723
return create_success_redirect(base_url, message)
752724
else:
753-
# All deletes failed
754725
return create_error_redirect(base_url, message)
755726

756727

757-
# Repository (repomd) management routes
758728
@router.get("/{product_id}/mirrors/{mirror_id}/repomds/new", response_class=HTMLResponse)
759729
async def admin_supported_product_mirror_repomd_new(
760730
request: Request,
@@ -810,7 +780,7 @@ async def admin_supported_product_mirror_repomd_new_post(
810780
"admin_supported_product_repomd_new.jinja", {
811781
"request": request,
812782
"mirror": mirror,
813-
"error": validation_errors[0], # Show first error
783+
"error": validation_errors[0],
814784
"form_data": form_data
815785
}
816786
)
@@ -894,7 +864,7 @@ async def admin_supported_product_mirror_repomd_post(
894864
"admin_supported_product_repomd.jinja", {
895865
"request": request,
896866
"repomd": repomd,
897-
"error": validation_errors[0], # Show first error
867+
"error": validation_errors[0],
898868
}
899869
)
900870

@@ -936,7 +906,6 @@ async def admin_supported_product_mirror_repomd_delete(
936906
if isinstance(repomd, Response):
937907
return repomd
938908

939-
# Check for existing advisory packages using this repository
940909
packages_count = await AdvisoryPackage.filter(
941910
supported_products_rh_mirror=repomd.supported_products_rh_mirror,
942911
repo_name=repomd.repo_name
@@ -954,7 +923,6 @@ async def admin_supported_product_mirror_repomd_delete(
954923
return RedirectResponse(f"/admin/supported-products/{product_id}/mirrors/{mirror_id}", status_code=302)
955924

956925

957-
# Blocks management routes
958926
@router.get("/{product_id}/mirrors/{mirror_id}/blocks", response_class=HTMLResponse)
959927
async def admin_supported_product_mirror_blocks(
960928
request: Request,
@@ -976,17 +944,14 @@ async def admin_supported_product_mirror_blocks(
976944
if isinstance(mirror, Response):
977945
return mirror
978946

979-
# Build query for blocked advisories
980947
query = SupportedProductsRhBlock.filter(
981948
supported_products_rh_mirror=mirror
982949
).prefetch_related("red_hat_advisory")
983950

984-
# Apply search if provided
985951
if search:
986952
query = query.filter(red_hat_advisory__name__icontains=search)
987953

988-
# Set page size and get paginated results
989-
params.size = min(params.size or 50, 100) # Default 50, max 100
954+
params.size = min(params.size or 50, 100)
990955
blocks = await paginate(
991956
query.order_by("-red_hat_advisory__red_hat_issued_at"), params=params
992957
)
@@ -1023,7 +988,6 @@ async def admin_supported_product_mirror_block_new(
1023988
if isinstance(mirror, Response):
1024989
return mirror
1025990

1026-
# Get advisories that are not already blocked
1027991
existing_blocks = await SupportedProductsRhBlock.filter(
1028992
supported_products_rh_mirror=mirror
1029993
).values_list("red_hat_advisory_id", flat=True)
@@ -1032,11 +996,9 @@ async def admin_supported_product_mirror_block_new(
1032996
if search:
1033997
query = query.filter(name__icontains=search)
1034998

1035-
# Set page size and get paginated results
1036-
params.size = min(params.size or 50, 100) # Default 50, max 100
999+
params.size = min(params.size or 50, 100)
10371000
advisories = await paginate(query.order_by("-red_hat_issued_at"), params=params)
10381001

1039-
# Calculate total pages for pagination component
10401002
advisories_pages = (
10411003
math.ceil(advisories.total / advisories.size) if advisories.size > 0 else 1
10421004
)
@@ -1078,7 +1040,6 @@ async def admin_supported_product_mirror_block_new_post(
10781040
if isinstance(advisory, Response):
10791041
return advisory
10801042

1081-
# Check if block already exists
10821043
existing_block = await SupportedProductsRhBlock.get_or_none(
10831044
supported_products_rh_mirror=mirror, red_hat_advisory=advisory
10841045
)
@@ -1128,7 +1089,6 @@ async def admin_supported_product_mirror_block_delete(
11281089
)
11291090

11301091

1131-
# Overrides management routes (similar structure to blocks)
11321092
@router.get("/{product_id}/mirrors/{mirror_id}/overrides/new", response_class=HTMLResponse)
11331093
async def admin_supported_product_mirror_override_new(
11341094
request: Request,
@@ -1147,7 +1107,6 @@ async def admin_supported_product_mirror_override_new(
11471107
if isinstance(mirror, Response):
11481108
return mirror
11491109

1150-
# Get advisories that don't already have overrides
11511110
existing_overrides = await SupportedProductsRpmRhOverride.filter(
11521111
supported_products_rh_mirror=mirror
11531112
).values_list("red_hat_advisory_id", flat=True)
@@ -1156,11 +1115,9 @@ async def admin_supported_product_mirror_override_new(
11561115
if search:
11571116
query = query.filter(name__icontains=search)
11581117

1159-
# Set page size and get paginated results
1160-
params.size = min(params.size or 50, 100) # Default 50, max 100
1118+
params.size = min(params.size or 50, 100)
11611119
advisories = await paginate(query.order_by("-red_hat_issued_at"), params=params)
11621120

1163-
# Calculate total pages for pagination component
11641121
advisories_pages = (
11651122
math.ceil(advisories.total / advisories.size) if advisories.size > 0 else 1
11661123
)
@@ -1202,7 +1159,6 @@ async def admin_supported_product_mirror_override_new_post(
12021159
if isinstance(advisory, Response):
12031160
return advisory
12041161

1205-
# Check if override already exists
12061162
existing_override = await SupportedProductsRpmRhOverride.get_or_none(
12071163
supported_products_rh_mirror=mirror,
12081164
red_hat_advisory=advisory
@@ -1369,7 +1325,6 @@ async def export_product_config(
13691325
media_type="text/plain"
13701326
)
13711327

1372-
# Build query with filters
13731328
query = SupportedProductsRhMirror.filter(supported_product_id=product_id)
13741329
if major_version is not None:
13751330
query = query.filter(match_major_version=major_version)
@@ -1381,7 +1336,6 @@ async def export_product_config(
13811336
"rpm_repomds"
13821337
).all()
13831338

1384-
# Filter repositories by production status if specified
13851339
config_data = []
13861340
for mirror in mirrors:
13871341
mirror_data = await _get_mirror_config_data(mirror)
@@ -1432,19 +1386,16 @@ async def admin_supported_product_mirror_overrides(
14321386
if isinstance(mirror, Response):
14331387
return mirror
14341388

1435-
# Build query for overrides with search
14361389
query = SupportedProductsRpmRhOverride.filter(
14371390
supported_products_rh_mirror_id=mirror_id
14381391
).prefetch_related("red_hat_advisory")
14391392

14401393
if search:
14411394
query = query.filter(red_hat_advisory__name__icontains=search)
14421395

1443-
# Apply ordering and pagination
14441396
query = query.order_by("-created_at")
14451397
overrides = await paginate(query, params)
14461398

1447-
# Calculate total pages for pagination component
14481399
overrides_pages = (
14491400
math.ceil(overrides.total / overrides.size) if overrides.size > 0 else 1
14501401
)

0 commit comments

Comments
 (0)