fosslight-util 2.2.20__tar.gz → 2.2.22__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {fosslight_util-2.2.20/src/fosslight_util.egg-info → fosslight_util-2.2.22}/PKG-INFO +1 -1
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/pyproject.toml +1 -1
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/download.py +360 -81
- fosslight_util-2.2.22/src/fosslight_util/merge.py +467 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22/src/fosslight_util.egg-info}/PKG-INFO +1 -1
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util.egg-info/SOURCES.txt +2 -0
- fosslight_util-2.2.22/tests/test_chromium_gitiles.py +328 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_download_user_agent.py +5 -3
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/LICENSE +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/MANIFEST.in +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/README.md +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/setup.cfg +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/__init__.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/_get_downloadable_url.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/compare_yaml.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/constant.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/correct.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/cover.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/exclude.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/get_pom_license.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/help.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/oss_item.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/output_format.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/parsing_yaml.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/read_excel.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/resources/frequentLicenselist.json +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/resources/frequent_license_nick_list.json +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/resources/licenses.json +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/set_log.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/spdx_licenses.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/time.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/timer_thread.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/write_cyclonedx.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/write_excel.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/write_opossum.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/write_scancodejson.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/write_spdx.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/write_txt.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util/write_yaml.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util.egg-info/dependency_links.txt +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util.egg-info/entry_points.txt +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util.egg-info/requires.txt +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/src/fosslight_util.egg-info/top_level.txt +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_cyclonedx.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_decide_checkout.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_download.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_download_maven.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_download_packagist.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_download_timeout.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_download_version_attempts.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_download_version_hint.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_opossum.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_spdx.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_spdx_licenses.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_text.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_write_excel_hidden_sheet.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_write_output.py +0 -0
- {fosslight_util-2.2.20 → fosslight_util-2.2.22}/tests/test_write_yaml.py +0 -0
|
@@ -361,6 +361,189 @@ def parse_src_link(src_link):
|
|
|
361
361
|
return src_info
|
|
362
362
|
|
|
363
363
|
|
|
364
|
+
_WGET_FINAL_URL = re.compile(r"URL:(https?://\S+)")
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
def _final_url_from_wget_stderr(stderr: str) -> str:
|
|
368
|
+
"""Return the last URL wget printed, which is the file it saved."""
|
|
369
|
+
found = _WGET_FINAL_URL.findall(stderr or "")
|
|
370
|
+
return found[-1] if found else ""
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
def _download_dir_entries(path: str) -> set:
|
|
374
|
+
"""Return absolute paths of the directory's immediate children."""
|
|
375
|
+
if not path or not os.path.isdir(path):
|
|
376
|
+
return set()
|
|
377
|
+
found = set()
|
|
378
|
+
for child in Path(path).iterdir():
|
|
379
|
+
found.add(os.path.abspath(str(child)))
|
|
380
|
+
return found
|
|
381
|
+
|
|
382
|
+
|
|
383
|
+
def _remove_new_download_entries(path: str, keep: set) -> None:
|
|
384
|
+
"""Remove children created by this download and leave ``keep`` in place."""
|
|
385
|
+
if not path or not os.path.isdir(path):
|
|
386
|
+
return
|
|
387
|
+
for child in Path(path).iterdir():
|
|
388
|
+
if os.path.abspath(str(child)) in keep:
|
|
389
|
+
continue
|
|
390
|
+
try:
|
|
391
|
+
if child.is_symlink() or child.is_file():
|
|
392
|
+
child.unlink()
|
|
393
|
+
else:
|
|
394
|
+
shutil.rmtree(child)
|
|
395
|
+
except OSError as error:
|
|
396
|
+
logger.warning(f"Failed to clear download directory {child}: {error}")
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
def _split_gitiles_revision(rest):
|
|
400
|
+
"""Split the path after Gitiles '+' into revision segments and a subdirectory.
|
|
401
|
+
|
|
402
|
+
``refs/tags/<name>`` and ``refs/heads/<name>`` use one segment for the ref
|
|
403
|
+
name. ``refs/remotes/<remote>/<name>`` uses those three segments. Any other
|
|
404
|
+
revision is the first segment (tag, branch, HEAD, or object id).
|
|
405
|
+
"""
|
|
406
|
+
if not rest or rest[0] != "refs":
|
|
407
|
+
if not rest:
|
|
408
|
+
return [], []
|
|
409
|
+
return rest[:1], rest[1:]
|
|
410
|
+
if len(rest) >= 2 and rest[1] in ("tags", "heads"):
|
|
411
|
+
if len(rest) < 3:
|
|
412
|
+
return [], []
|
|
413
|
+
return rest[:3], rest[3:]
|
|
414
|
+
if len(rest) >= 2 and rest[1] == "remotes":
|
|
415
|
+
if len(rest) < 4:
|
|
416
|
+
return [], []
|
|
417
|
+
return rest[:4], rest[4:]
|
|
418
|
+
return [], []
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
def _gitiles_checkout_ref(revision) -> str:
|
|
422
|
+
if (
|
|
423
|
+
len(revision) >= 3
|
|
424
|
+
and revision[0] == "refs"
|
|
425
|
+
and revision[1] in ("tags", "heads")
|
|
426
|
+
):
|
|
427
|
+
return revision[2]
|
|
428
|
+
if len(revision) >= 4 and revision[0] == "refs" and revision[1] == "remotes":
|
|
429
|
+
return revision[3]
|
|
430
|
+
return revision[0] if revision else ""
|
|
431
|
+
|
|
432
|
+
|
|
433
|
+
_GITILES_VERSION_SEGMENT = re.compile(
|
|
434
|
+
r"^(?:v\.?\s*)?\d+(?:\.\d+)*$",
|
|
435
|
+
re.IGNORECASE,
|
|
436
|
+
)
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def gitiles_link_version(url: str) -> str:
|
|
440
|
+
"""Return the version segment in a Chromium Gitiles path.
|
|
441
|
+
|
|
442
|
+
The version is the first ``+`` path segment that is a number or dotted
|
|
443
|
+
number, with an optional leading ``v``. ``refs/heads/releases/114/...``
|
|
444
|
+
yields ``114``. A path with no such segment yields ``""``.
|
|
445
|
+
"""
|
|
446
|
+
raw = (url or "").strip().split(";", 1)[0]
|
|
447
|
+
parsed = urllib.parse.urlparse(raw)
|
|
448
|
+
segments = [
|
|
449
|
+
urllib.parse.unquote(segment)
|
|
450
|
+
for segment in (parsed.path or "").split("/")
|
|
451
|
+
if segment
|
|
452
|
+
]
|
|
453
|
+
try:
|
|
454
|
+
plus_at = segments.index("+")
|
|
455
|
+
except ValueError:
|
|
456
|
+
return ""
|
|
457
|
+
for segment in segments[plus_at + 1:]:
|
|
458
|
+
if _GITILES_VERSION_SEGMENT.match(segment):
|
|
459
|
+
return segment
|
|
460
|
+
return ""
|
|
461
|
+
|
|
462
|
+
|
|
463
|
+
def _gitiles_clone_attempts(link_version: str, checkout_to: str):
|
|
464
|
+
"""Checkout order for a Gitiles clone: link version, ``-c``, default branch.
|
|
465
|
+
|
|
466
|
+
The first two attempts do not fall back to the default branch. The last
|
|
467
|
+
attempt clones that branch and leaves the version empty.
|
|
468
|
+
"""
|
|
469
|
+
attempts = []
|
|
470
|
+
version = (link_version or "").strip()
|
|
471
|
+
requested = (checkout_to or "").strip()
|
|
472
|
+
if version:
|
|
473
|
+
attempts.append((version, False))
|
|
474
|
+
if requested and requested != version:
|
|
475
|
+
attempts.append((requested, False))
|
|
476
|
+
attempts.append(("", True))
|
|
477
|
+
return attempts
|
|
478
|
+
|
|
479
|
+
|
|
480
|
+
def _gitiles_ref_kind(revision) -> str:
|
|
481
|
+
"""Classify a parsed Gitiles revision as tag, branch, commit, or name."""
|
|
482
|
+
if (
|
|
483
|
+
len(revision) >= 3
|
|
484
|
+
and revision[0] == "refs"
|
|
485
|
+
and revision[1] == "tags"
|
|
486
|
+
):
|
|
487
|
+
return "tag"
|
|
488
|
+
if (
|
|
489
|
+
len(revision) >= 3
|
|
490
|
+
and revision[0] == "refs"
|
|
491
|
+
and revision[1] == "heads"
|
|
492
|
+
):
|
|
493
|
+
return "branch"
|
|
494
|
+
if revision and re.fullmatch(r"[0-9a-fA-F]{7,40}", revision[0]):
|
|
495
|
+
return "commit"
|
|
496
|
+
return "name"
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def parse_chromium_gitiles_path(url: str):
|
|
500
|
+
"""Parse a Chromium Gitiles path URL.
|
|
501
|
+
|
|
502
|
+
Returns ``(repo_url, archive_url, checkout_ref, ref_kind)`` when the URL is
|
|
503
|
+
``https://chromium.googlesource.com/{repo}/+/{revision}/{subdirectory}``.
|
|
504
|
+
``archive_url`` is the subdirectory ``+archive`` tarball. ``ref_kind`` is
|
|
505
|
+
``tag``, ``branch``, ``commit``, or ``name``. Other URLs, including a
|
|
506
|
+
revision with no subdirectory, return ``None``.
|
|
507
|
+
"""
|
|
508
|
+
raw = (url or "").strip()
|
|
509
|
+
parsed = urllib.parse.urlparse(raw)
|
|
510
|
+
if parsed.scheme != "https":
|
|
511
|
+
return None
|
|
512
|
+
if (parsed.hostname or "").lower() != "chromium.googlesource.com":
|
|
513
|
+
return None
|
|
514
|
+
segments = [
|
|
515
|
+
urllib.parse.unquote(segment)
|
|
516
|
+
for segment in (parsed.path or "").split("/")
|
|
517
|
+
if segment
|
|
518
|
+
]
|
|
519
|
+
try:
|
|
520
|
+
plus_at = segments.index("+")
|
|
521
|
+
except ValueError:
|
|
522
|
+
return None
|
|
523
|
+
if plus_at == 0:
|
|
524
|
+
return None
|
|
525
|
+
repo_segments = segments[:plus_at]
|
|
526
|
+
if repo_segments[-1].endswith(".git"):
|
|
527
|
+
repo_segments[-1] = repo_segments[-1][:-len(".git")]
|
|
528
|
+
if not repo_segments[-1]:
|
|
529
|
+
return None
|
|
530
|
+
revision, subpath = _split_gitiles_revision(segments[plus_at + 1:])
|
|
531
|
+
if not revision or not subpath:
|
|
532
|
+
return None
|
|
533
|
+
|
|
534
|
+
def _quote_path(parts):
|
|
535
|
+
return "/".join(urllib.parse.quote(part, safe="+") for part in parts)
|
|
536
|
+
|
|
537
|
+
repo_url = "https://chromium.googlesource.com/" + _quote_path(repo_segments)
|
|
538
|
+
archive_url = (
|
|
539
|
+
"https://chromium.googlesource.com/"
|
|
540
|
+
+ _quote_path(repo_segments + ["+archive"] + revision + subpath)
|
|
541
|
+
+ ".tar.gz"
|
|
542
|
+
)
|
|
543
|
+
checkout_ref = _gitiles_checkout_ref(revision)
|
|
544
|
+
return repo_url, archive_url, checkout_ref, _gitiles_ref_kind(revision)
|
|
545
|
+
|
|
546
|
+
|
|
364
547
|
def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_to: str = "",
|
|
365
548
|
compressed_only: bool = False, ssh_key: str = "",
|
|
366
549
|
id: str = "", git_token: str = "",
|
|
@@ -406,74 +589,153 @@ def cli_download_and_extract(link: str, target_dir: str, log_dir: str, checkout_
|
|
|
406
589
|
is_rubygems = src_info.get("rubygems", False)
|
|
407
590
|
attempts = download_version_attempts(link, checkout_to)
|
|
408
591
|
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
downloaded_link = ""
|
|
428
|
-
size_limit_blocked = False
|
|
429
|
-
|
|
430
|
-
# General download: git clone → requests → system wget
|
|
431
|
-
success_git, msg, oss_name, oss_version, clarified_from_git = download_git_clone(
|
|
432
|
-
attempt_link, target_dir, attempt_checkout, tag, branch,
|
|
433
|
-
ssh_key, id, git_token, called_cli, size_limit_gb=size_limit_gb)
|
|
434
|
-
link = change_ssh_link_to_https(attempt_link)
|
|
435
|
-
if success_git:
|
|
436
|
-
downloaded_link = link
|
|
437
|
-
success = True
|
|
438
|
-
size_limit_blocked = _is_size_limit_block_message(msg)
|
|
439
|
-
if size_limit_blocked:
|
|
592
|
+
gitiles = parse_chromium_gitiles_path(link.split(";", 1)[0])
|
|
593
|
+
if gitiles and not is_rubygems:
|
|
594
|
+
repo_url, archive_url, checkout_ref, _ref_kind = gitiles
|
|
595
|
+
existing_entries = _download_dir_entries(target_dir)
|
|
596
|
+
logger.info(
|
|
597
|
+
"Chromium Gitiles path; downloading subdirectory archive: %s",
|
|
598
|
+
archive_url,
|
|
599
|
+
)
|
|
600
|
+
(
|
|
601
|
+
success, downloaded_file, msg_wget, oss_name, oss_version, resolved_link
|
|
602
|
+
) = download_wget(
|
|
603
|
+
archive_url, target_dir, compressed_only, checkout_to,
|
|
604
|
+
size_limit_gb=size_limit_gb,
|
|
605
|
+
allow_latest=False,
|
|
606
|
+
)
|
|
607
|
+
archive_ok = False
|
|
608
|
+
if _is_size_limit_block_message(msg_wget):
|
|
609
|
+
size_limit_blocked = True
|
|
440
610
|
success = False
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
allow_latest=allow_latest,
|
|
611
|
+
msg = msg_wget
|
|
612
|
+
elif success and downloaded_file:
|
|
613
|
+
archive_ok = extract_compressed_file(
|
|
614
|
+
downloaded_file, target_dir, True, True
|
|
446
615
|
)
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
616
|
+
_raise_if_download_timed_out()
|
|
617
|
+
if archive_ok:
|
|
618
|
+
downloaded_link = resolved_link
|
|
619
|
+
success = True
|
|
620
|
+
oss_version = checkout_ref
|
|
621
|
+
clarified_from_git = ""
|
|
622
|
+
msg = ""
|
|
623
|
+
msg_wget = ""
|
|
624
|
+
else:
|
|
625
|
+
msg_wget = (
|
|
626
|
+
f"Failed to extract downloaded file: {downloaded_file}"
|
|
454
627
|
)
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
628
|
+
success = False
|
|
629
|
+
try:
|
|
630
|
+
if os.path.isfile(downloaded_file):
|
|
631
|
+
os.remove(downloaded_file)
|
|
632
|
+
except OSError:
|
|
633
|
+
pass
|
|
634
|
+
if not archive_ok and not size_limit_blocked:
|
|
635
|
+
logger.info(
|
|
636
|
+
"Chromium Gitiles subdirectory archive failed; "
|
|
637
|
+
"cloning repository: %s",
|
|
638
|
+
repo_url,
|
|
639
|
+
)
|
|
640
|
+
link_version = gitiles_link_version(link.split(";", 1)[0])
|
|
641
|
+
clone_attempts = _gitiles_clone_attempts(link_version, checkout_to)
|
|
642
|
+
for ref, allow_default in clone_attempts:
|
|
643
|
+
_remove_new_download_entries(target_dir, existing_entries)
|
|
644
|
+
if _download_dir_entries(target_dir):
|
|
645
|
+
success = False
|
|
646
|
+
msg = (
|
|
647
|
+
"Target directory is not empty; "
|
|
648
|
+
"repository clone was not started."
|
|
461
649
|
)
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
650
|
+
break
|
|
651
|
+
(
|
|
652
|
+
success_git, msg, oss_name, oss_version, clarified_from_git
|
|
653
|
+
) = download_git_clone(
|
|
654
|
+
repo_url, target_dir, ref, "", "",
|
|
655
|
+
ssh_key, id, git_token, called_cli,
|
|
656
|
+
size_limit_gb=size_limit_gb,
|
|
657
|
+
allow_default_branch_fallback=allow_default,
|
|
658
|
+
)
|
|
659
|
+
if _is_size_limit_block_message(msg):
|
|
660
|
+
size_limit_blocked = True
|
|
661
|
+
success = False
|
|
662
|
+
break
|
|
663
|
+
if success_git:
|
|
664
|
+
downloaded_link = change_ssh_link_to_https(repo_url)
|
|
665
|
+
success = True
|
|
666
|
+
msg = ""
|
|
667
|
+
msg_wget = ""
|
|
668
|
+
break
|
|
669
|
+
success = False
|
|
670
|
+
else:
|
|
671
|
+
for attempt_index, (attempt_link, attempt_checkout, allow_latest) in enumerate(attempts):
|
|
672
|
+
if attempt_index:
|
|
673
|
+
parts = []
|
|
674
|
+
if msg:
|
|
675
|
+
parts.append(f"git fail: {msg}")
|
|
676
|
+
if msg_wget:
|
|
677
|
+
parts.append(f"wget fail: {msg_wget}")
|
|
678
|
+
link_version_failure = ", ".join(parts)
|
|
679
|
+
logger.info(
|
|
680
|
+
"Link version download failed; retry with checkout version "
|
|
681
|
+
f"{attempt_checkout}. {link_version_failure}"
|
|
682
|
+
)
|
|
683
|
+
success = True
|
|
684
|
+
msg = ""
|
|
685
|
+
msg_wget = ""
|
|
686
|
+
oss_name = ""
|
|
687
|
+
oss_version = ""
|
|
688
|
+
clarified_from_git = ""
|
|
689
|
+
downloaded_link = ""
|
|
690
|
+
size_limit_blocked = False
|
|
691
|
+
|
|
692
|
+
# General download: git clone → requests → system wget
|
|
693
|
+
success_git, msg, oss_name, oss_version, clarified_from_git = download_git_clone(
|
|
694
|
+
attempt_link, target_dir, attempt_checkout, tag, branch,
|
|
695
|
+
ssh_key, id, git_token, called_cli, size_limit_gb=size_limit_gb)
|
|
696
|
+
link = change_ssh_link_to_https(attempt_link)
|
|
697
|
+
if success_git:
|
|
474
698
|
downloaded_link = link
|
|
475
|
-
|
|
476
|
-
|
|
699
|
+
success = True
|
|
700
|
+
size_limit_blocked = _is_size_limit_block_message(msg)
|
|
701
|
+
if size_limit_blocked:
|
|
702
|
+
success = False
|
|
703
|
+
elif (not is_rubygems) and (not success_git):
|
|
704
|
+
success, downloaded_file, msg_wget, oss_name, oss_version, resolved_link = download_wget(
|
|
705
|
+
link, target_dir, compressed_only, attempt_checkout,
|
|
706
|
+
size_limit_gb=size_limit_gb,
|
|
707
|
+
allow_latest=allow_latest,
|
|
708
|
+
)
|
|
709
|
+
if _is_size_limit_block_message(msg_wget):
|
|
710
|
+
size_limit_blocked = True
|
|
711
|
+
success = False
|
|
712
|
+
msg = msg_wget
|
|
713
|
+
elif success and downloaded_file:
|
|
714
|
+
success = extract_compressed_file(
|
|
715
|
+
downloaded_file, target_dir, True, compressed_only
|
|
716
|
+
)
|
|
717
|
+
if success:
|
|
718
|
+
downloaded_link = resolved_link
|
|
719
|
+
else:
|
|
720
|
+
# Extract failed (e.g. non-archive when compressed_only): fail
|
|
721
|
+
msg_wget = (
|
|
722
|
+
f"Failed to extract downloaded file: {downloaded_file}"
|
|
723
|
+
)
|
|
724
|
+
try:
|
|
725
|
+
if os.path.isfile(downloaded_file):
|
|
726
|
+
os.remove(downloaded_file)
|
|
727
|
+
except OSError:
|
|
728
|
+
pass
|
|
729
|
+
# Download from rubygems.org
|
|
730
|
+
elif is_rubygems and shutil.which("gem"):
|
|
731
|
+
_raise_if_download_timed_out()
|
|
732
|
+
success = gem_download(link, target_dir, attempt_checkout)
|
|
733
|
+
# Do not accept a gem that finished, or was stopped, after the deadline.
|
|
734
|
+
_raise_if_download_timed_out()
|
|
735
|
+
if success:
|
|
736
|
+
downloaded_link = link
|
|
737
|
+
if success or size_limit_blocked:
|
|
738
|
+
break
|
|
477
739
|
if size_limit_blocked:
|
|
478
740
|
# Keep a clear size-limit message for callers/UI (do not wrap as git/wget fail)
|
|
479
741
|
pass
|
|
@@ -1148,6 +1410,7 @@ def download_git_repository(
|
|
|
1148
1410
|
size_limit_gb: Optional[float] = None,
|
|
1149
1411
|
credential_id: str = "",
|
|
1150
1412
|
git_token: str = "",
|
|
1413
|
+
allow_default_branch_fallback: bool = True,
|
|
1151
1414
|
):
|
|
1152
1415
|
success = False
|
|
1153
1416
|
oss_version = ""
|
|
@@ -1184,7 +1447,7 @@ def download_git_repository(
|
|
|
1184
1447
|
|
|
1185
1448
|
msg = err
|
|
1186
1449
|
# If branch/tag clone failed, fall back to default-branch shallow clone
|
|
1187
|
-
if refs_to_checkout:
|
|
1450
|
+
if refs_to_checkout and allow_default_branch_fallback:
|
|
1188
1451
|
logger.info(
|
|
1189
1452
|
f"Shallow clone with ref '{refs_to_checkout}' failed; "
|
|
1190
1453
|
"retrying default branch shallow clone."
|
|
@@ -1209,7 +1472,8 @@ def download_git_repository(
|
|
|
1209
1472
|
|
|
1210
1473
|
def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="",
|
|
1211
1474
|
ssh_key="", id="", git_token="", called_cli=True,
|
|
1212
|
-
size_limit_gb: Optional[float] = None
|
|
1475
|
+
size_limit_gb: Optional[float] = None,
|
|
1476
|
+
allow_default_branch_fallback: bool = True):
|
|
1213
1477
|
git_url = _normalize_git_url_for_clone(git_url)
|
|
1214
1478
|
oss_name = get_github_ossname(git_url)
|
|
1215
1479
|
refs_to_checkout, decided_clarified = _resolve_refs_to_checkout(
|
|
@@ -1235,6 +1499,7 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="",
|
|
|
1235
1499
|
refs_to_checkout, git_url, target_dir, tag, called_cli,
|
|
1236
1500
|
size_limit_gb=size_limit_gb,
|
|
1237
1501
|
credential_id=id, git_token=git_token,
|
|
1502
|
+
allow_default_branch_fallback=allow_default_branch_fallback,
|
|
1238
1503
|
)
|
|
1239
1504
|
else:
|
|
1240
1505
|
git_url = _git_url_with_http_credentials(git_url, credential_id=id, git_token=git_token)
|
|
@@ -1242,6 +1507,7 @@ def download_git_clone(git_url, target_dir, checkout_to="", tag="", branch="",
|
|
|
1242
1507
|
refs_to_checkout, git_url, target_dir, tag, called_cli,
|
|
1243
1508
|
size_limit_gb=size_limit_gb,
|
|
1244
1509
|
credential_id=id, git_token=git_token,
|
|
1510
|
+
allow_default_branch_fallback=allow_default_branch_fallback,
|
|
1245
1511
|
)
|
|
1246
1512
|
if repo_msg and not success:
|
|
1247
1513
|
msg = repo_msg
|
|
@@ -1294,11 +1560,13 @@ def _download_with_system_wget(url, target_dir, size_limit_gb=None):
|
|
|
1294
1560
|
|
|
1295
1561
|
precheck Content-Length, poll directory size while wget runs, then
|
|
1296
1562
|
enforce final file size. Raises SizeLimitExceeded on overflow.
|
|
1297
|
-
Returns
|
|
1563
|
+
Returns ``(local_path, final_url)``. ``final_url`` is the URL wget logged
|
|
1564
|
+
while saving the file, or the request URL when wget printed none.
|
|
1565
|
+
On failure, returns ``(None, "")``.
|
|
1298
1566
|
"""
|
|
1299
1567
|
if not shutil.which("wget"):
|
|
1300
1568
|
logger.warning("system wget not found; skip wget fallback")
|
|
1301
|
-
return None
|
|
1569
|
+
return None, ""
|
|
1302
1570
|
|
|
1303
1571
|
Path(target_dir).mkdir(parents=True, exist_ok=True)
|
|
1304
1572
|
|
|
@@ -1346,7 +1614,7 @@ def _download_with_system_wget(url, target_dir, size_limit_gb=None):
|
|
|
1346
1614
|
)
|
|
1347
1615
|
except Exception as error:
|
|
1348
1616
|
logger.warning(f"system wget - failed to start: {error}")
|
|
1349
|
-
return None
|
|
1617
|
+
return None, ""
|
|
1350
1618
|
|
|
1351
1619
|
limit = _size_limit_bytes(size_limit_gb)
|
|
1352
1620
|
while proc.poll() is None:
|
|
@@ -1378,7 +1646,7 @@ def _download_with_system_wget(url, target_dir, size_limit_gb=None):
|
|
|
1378
1646
|
logger.warning(
|
|
1379
1647
|
f"system wget failed (rc={proc.returncode}): {(stderr or '').strip()}"
|
|
1380
1648
|
)
|
|
1381
|
-
return None
|
|
1649
|
+
return None, ""
|
|
1382
1650
|
|
|
1383
1651
|
try:
|
|
1384
1652
|
candidates = [
|
|
@@ -1386,11 +1654,11 @@ def _download_with_system_wget(url, target_dir, size_limit_gb=None):
|
|
|
1386
1654
|
if p.is_file() and not p.is_symlink()
|
|
1387
1655
|
]
|
|
1388
1656
|
except OSError:
|
|
1389
|
-
return None
|
|
1657
|
+
return None, ""
|
|
1390
1658
|
new_files = [p for p in candidates if p.resolve() not in before]
|
|
1391
1659
|
pick_from = new_files or candidates
|
|
1392
1660
|
if not pick_from:
|
|
1393
|
-
return None
|
|
1661
|
+
return None, ""
|
|
1394
1662
|
local_path = str(max(pick_from, key=lambda p: p.stat().st_size))
|
|
1395
1663
|
|
|
1396
1664
|
try:
|
|
@@ -1399,7 +1667,8 @@ def _download_with_system_wget(url, target_dir, size_limit_gb=None):
|
|
|
1399
1667
|
)
|
|
1400
1668
|
except SizeLimitExceeded:
|
|
1401
1669
|
raise
|
|
1402
|
-
|
|
1670
|
+
saved_url = _final_url_from_wget_stderr(stderr) or url
|
|
1671
|
+
return local_path, saved_url
|
|
1403
1672
|
|
|
1404
1673
|
|
|
1405
1674
|
def download_wget(link, target_dir, compressed_only, checkout_to, size_limit_gb=None,
|
|
@@ -1410,6 +1679,7 @@ def download_wget(link, target_dir, compressed_only, checkout_to, size_limit_gb=
|
|
|
1410
1679
|
oss_version = ""
|
|
1411
1680
|
downloaded_file = ""
|
|
1412
1681
|
resolved_link = ""
|
|
1682
|
+
final_url = ""
|
|
1413
1683
|
owner = _enter_download_watchdog(SIGNAL_TIMEOUT)
|
|
1414
1684
|
|
|
1415
1685
|
try:
|
|
@@ -1459,7 +1729,7 @@ def download_wget(link, target_dir, compressed_only, checkout_to, size_limit_gb=
|
|
|
1459
1729
|
# 2차: requests HTTP download
|
|
1460
1730
|
logger.info(f"HTTP(requests) download: {link}")
|
|
1461
1731
|
try:
|
|
1462
|
-
downloaded_file = download_file(
|
|
1732
|
+
downloaded_file, final_url = download_file(
|
|
1463
1733
|
link, target_dir, size_limit_gb=size_limit_gb
|
|
1464
1734
|
)
|
|
1465
1735
|
except (SizeLimitExceeded, TimeOutException):
|
|
@@ -1469,6 +1739,7 @@ def download_wget(link, target_dir, compressed_only, checkout_to, size_limit_gb=
|
|
|
1469
1739
|
f"requests download failed: {error}; trying system wget"
|
|
1470
1740
|
)
|
|
1471
1741
|
downloaded_file = None
|
|
1742
|
+
final_url = ""
|
|
1472
1743
|
|
|
1473
1744
|
# Out of time: do not start the download over with wget.
|
|
1474
1745
|
_raise_if_download_timed_out()
|
|
@@ -1476,10 +1747,12 @@ def download_wget(link, target_dir, compressed_only, checkout_to, size_limit_gb=
|
|
|
1476
1747
|
# 3차: system wget fallback (former scancode fetch_http wget path)
|
|
1477
1748
|
if not downloaded_file:
|
|
1478
1749
|
logger.info(f"system wget fallback: {link}")
|
|
1479
|
-
downloaded_file = _download_with_system_wget(
|
|
1750
|
+
downloaded_file, final_url = _download_with_system_wget(
|
|
1480
1751
|
link, target_dir, size_limit_gb=size_limit_gb
|
|
1481
1752
|
)
|
|
1482
1753
|
|
|
1754
|
+
if final_url:
|
|
1755
|
+
resolved_link = final_url
|
|
1483
1756
|
if downloaded_file:
|
|
1484
1757
|
_reject_empty_or_html_download(downloaded_file, link)
|
|
1485
1758
|
success = True
|
|
@@ -1545,6 +1818,7 @@ def _download_file_once(url, target_dir, request_headers=None, size_limit_gb=Non
|
|
|
1545
1818
|
head_headers = {}
|
|
1546
1819
|
|
|
1547
1820
|
local_path = None
|
|
1821
|
+
fetched_url = final_url
|
|
1548
1822
|
try:
|
|
1549
1823
|
with requests.get(
|
|
1550
1824
|
final_url,
|
|
@@ -1553,6 +1827,7 @@ def _download_file_once(url, target_dir, request_headers=None, size_limit_gb=Non
|
|
|
1553
1827
|
timeout=_download_request_timeout(SIGNAL_TIMEOUT),
|
|
1554
1828
|
headers=request_headers,
|
|
1555
1829
|
) as r:
|
|
1830
|
+
fetched_url = r.url or final_url
|
|
1556
1831
|
_set_download_timeout_callback(lambda: _shutdown_response_socket(r))
|
|
1557
1832
|
# The deadline may have passed before the callback was set.
|
|
1558
1833
|
_raise_if_download_timed_out()
|
|
@@ -1620,11 +1895,15 @@ def _download_file_once(url, target_dir, request_headers=None, size_limit_gb=Non
|
|
|
1620
1895
|
)
|
|
1621
1896
|
except SizeLimitExceeded:
|
|
1622
1897
|
raise
|
|
1623
|
-
return local_path
|
|
1898
|
+
return local_path, (fetched_url or url)
|
|
1624
1899
|
|
|
1625
1900
|
|
|
1626
1901
|
def download_file(url, target_dir, size_limit_gb=None):
|
|
1627
|
-
"""Download via HTTP(S); retry on 400/403 or HTML interstitial for archives.
|
|
1902
|
+
"""Download via HTTP(S); retry on 400/403 or HTML interstitial for archives.
|
|
1903
|
+
|
|
1904
|
+
Returns ``(local_path, final_url)``. ``final_url`` is the URL after redirects.
|
|
1905
|
+
On failure, returns ``(None, "")``.
|
|
1906
|
+
"""
|
|
1628
1907
|
attempts = _download_http_header_attempts()
|
|
1629
1908
|
last_i = len(attempts) - 1
|
|
1630
1909
|
for i, req_headers in enumerate(attempts):
|
|
@@ -1643,7 +1922,7 @@ def download_file(url, target_dir, size_limit_gb=None):
|
|
|
1643
1922
|
)
|
|
1644
1923
|
continue
|
|
1645
1924
|
logger.warning(f"download_file - failed: {e}")
|
|
1646
|
-
return None
|
|
1925
|
+
return None, ""
|
|
1647
1926
|
except _HtmlWhenBinaryExpected:
|
|
1648
1927
|
if i < last_i:
|
|
1649
1928
|
logger.info(
|
|
@@ -1654,7 +1933,7 @@ def download_file(url, target_dir, size_limit_gb=None):
|
|
|
1654
1933
|
logger.warning(
|
|
1655
1934
|
"download_file: archive URL still returned HTML after retries"
|
|
1656
1935
|
)
|
|
1657
|
-
return None
|
|
1936
|
+
return None, ""
|
|
1658
1937
|
except (requests.exceptions.ConnectionError, requests.exceptions.Timeout) as e:
|
|
1659
1938
|
if i < last_i:
|
|
1660
1939
|
logger.info(
|
|
@@ -1664,12 +1943,12 @@ def download_file(url, target_dir, size_limit_gb=None):
|
|
|
1664
1943
|
)
|
|
1665
1944
|
continue
|
|
1666
1945
|
logger.warning(f"download_file - failed: {e}")
|
|
1667
|
-
return None
|
|
1946
|
+
return None, ""
|
|
1668
1947
|
except Exception as e:
|
|
1669
1948
|
logger.warning(f"download_file - failed: {e}")
|
|
1670
|
-
return None
|
|
1949
|
+
return None, ""
|
|
1671
1950
|
logger.warning("download_file: failed after User-Agent retries")
|
|
1672
|
-
return None
|
|
1951
|
+
return None, ""
|
|
1673
1952
|
|
|
1674
1953
|
|
|
1675
1954
|
def extract_rpm_payload(source_file: str, dest_path: str) -> bool:
|