Factor out url_to_cache_filename.
This commit is contained in:
parent
a227ffa07f
commit
d3afa5f6eb
1 changed files with 16 additions and 12 deletions
|
@ -119,6 +119,12 @@ def read_contents_file(f):
|
||||||
yield decoded_path, package.decode("utf-8")
|
yield decoded_path, package.decode("utf-8")
|
||||||
|
|
||||||
|
|
||||||
|
def url_to_cache_filename(url):
|
||||||
|
from urllib.parse import urlparse
|
||||||
|
parsed = urlparse(url)
|
||||||
|
return parsed.hostname + parsed.path.replace("/", "_")
|
||||||
|
|
||||||
|
|
||||||
class AptContentsFileSearcher(FileSearcher):
|
class AptContentsFileSearcher(FileSearcher):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._db = {}
|
self._db = {}
|
||||||
|
@ -143,14 +149,16 @@ class AptContentsFileSearcher(FileSearcher):
|
||||||
self._db[path] = package
|
self._db[path] = package
|
||||||
|
|
||||||
def search_files(self, path, regex=False):
|
def search_files(self, path, regex=False):
|
||||||
c = re.compile(path)
|
if regex:
|
||||||
for p, pkg in sorted(self._db.items()):
|
c = re.compile(path)
|
||||||
if regex:
|
for p, pkg in sorted(self._db.items()):
|
||||||
if c.match(p):
|
if c.match(p):
|
||||||
yield pkg
|
yield pkg
|
||||||
else:
|
else:
|
||||||
if path == p:
|
try:
|
||||||
yield pkg
|
return self._db[path]
|
||||||
|
except KeyError:
|
||||||
|
pass
|
||||||
|
|
||||||
def load_file(self, f):
|
def load_file(self, f):
|
||||||
for path, package in read_contents_file(f):
|
for path, package in read_contents_file(f):
|
||||||
|
@ -158,12 +166,8 @@ class AptContentsFileSearcher(FileSearcher):
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _load_cache_file(cls, url, cache_dir):
|
def _load_cache_file(cls, url, cache_dir):
|
||||||
from urllib.parse import urlparse
|
fn = url_to_cache_filename(url)
|
||||||
|
p = os.path.join(cache_dir, fn + ".lz4")
|
||||||
parsed = urlparse(url)
|
|
||||||
p = os.path.join(
|
|
||||||
cache_dir, parsed.hostname + parsed.path.replace("/", "_") + ".lz4"
|
|
||||||
)
|
|
||||||
if not os.path.exists(p):
|
if not os.path.exists(p):
|
||||||
return None
|
return None
|
||||||
logging.debug("Loading cached contents file %s", p)
|
logging.debug("Loading cached contents file %s", p)
|
||||||
|
|
Loading…
Add table
Reference in a new issue