MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / fetch_and_save

Function fetch_and_save

etc/scripts/utils_thirdparty.py:1951–1971  ·  view source on GitHub ↗

Fetch content at ``path_or_url`` URL or path and save this to ``dest_dir/filername``. Return the fetched content. Raise an Exception on errors. Treats the content as text if as_text is True otherwise as treat as binary.

(
    path_or_url,
    dest_dir,
    filename,
    as_text=True,
)

Source from the content-addressed store, hash-verified

1949
1950
1951def fetch_and_save(
1952 path_or_url,
1953 dest_dir,
1954 filename,
1955 as_text=True,
1956):
1957 """
1958 Fetch content at ``path_or_url`` URL or path and save this to
1959 ``dest_dir/filername``. Return the fetched content. Raise an Exception on
1960 errors. Treats the content as text if as_text is True otherwise as treat as
1961 binary.
1962 """
1963 content = CACHE.get(
1964 path_or_url=path_or_url,
1965 as_text=as_text,
1966 )
1967 output = os.path.join(dest_dir, filename)
1968 wmode = "w" if as_text else "wb"
1969 with open(output, wmode) as fo:
1970 fo.write(content)
1971 return content
1972
1973
1974################################################################################

Callers 2

downloadMethod · 0.85
fetch_license_filesMethod · 0.85

Calls 3

getMethod · 0.65
joinMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected