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

Method get

etc/scripts/utils_thirdparty.py:1842–1863  ·  view source on GitHub ↗

Return the content fetched from a ``path_or_url`` through the cache. Raise an Exception on errors. Treats the content as text if as_text is True otherwise as treat as binary. `path_or_url` can be a path or a URL to a file.

(self, path_or_url, as_text=True, force=False)

Source from the content-addressed store, hash-verified

1840 os.makedirs(self.directory, exist_ok=True)
1841
1842 def get(self, path_or_url, as_text=True, force=False):
1843 """
1844 Return the content fetched from a ``path_or_url`` through the cache.
1845 Raise an Exception on errors. Treats the content as text if as_text is
1846 True otherwise as treat as binary. `path_or_url` can be a path or a URL
1847 to a file.
1848 """
1849 cache_key = quote_plus(path_or_url.strip("/"))
1850 cached = os.path.join(self.directory, cache_key)
1851
1852 if force or not os.path.exists(cached):
1853 if TRACE_DEEP:
1854 print(f" FILE CACHE MISS: {path_or_url}")
1855 content = get_file_content(path_or_url=path_or_url, as_text=as_text)
1856 wmode = "w" if as_text else "wb"
1857 with open(cached, wmode) as fo:
1858 fo.write(content)
1859 return content
1860 else:
1861 if TRACE_DEEP:
1862 print(f" FILE CACHE HIT: {path_or_url}")
1863 return get_local_file_content(path=cached, as_text=as_text)
1864
1865
1866CACHE = Cache()

Callers

nothing calls this directly

Calls 5

get_file_contentFunction · 0.85
get_local_file_contentFunction · 0.85
joinMethod · 0.45
existsMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected