Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 890 Lines • ▼ Show 20 Lines | def origin_search(self, url_pattern, offset=0, limit=50, | ||||
if regexp: | if regexp: | ||||
pat = re.compile(url_pattern) | pat = re.compile(url_pattern) | ||||
origins = [orig for orig in origins if pat.match(orig['url'])] | origins = [orig for orig in origins if pat.match(orig['url'])] | ||||
else: | else: | ||||
origins = [orig for orig in origins if url_pattern in orig['url']] | origins = [orig for orig in origins if url_pattern in orig['url']] | ||||
if with_visit: | if with_visit: | ||||
origins = [orig for orig in origins | origins = [orig for orig in origins | ||||
if len(self._origin_visits[orig['id']-1]) > 0] | if len(self._origin_visits[orig['id']-1]) > 0] | ||||
origins = copy.deepcopy(origins[offset:offset+limit]) | origins = copy.deepcopy(origins[offset:offset+limit]) | ||||
return origins | return origins | ||||
vlorentz: What's the difference with the former code? | |||||
Done Inline ActionsI wanted to remove the limit restriction for counting all found origins but I found a better way without changing anlambert: I wanted to remove the limit restriction for counting all found origins but I found a better… | |||||
def origin_count(self, url_pattern, regexp=False, with_visit=False, | |||||
db=None, cur=None): | |||||
"""Count origins whose urls contain a provided string pattern | |||||
or match a provided regular expression. | |||||
The pattern search in origin urls is performed in a case insensitive | |||||
way. | |||||
Args: | |||||
url_pattern (str): the string pattern to search for in origin urls | |||||
regexp (bool): if True, consider the provided pattern as a regular | |||||
expression and return origins whose urls match it | |||||
with_visit (bool): if True, filter out origins with no visit | |||||
Returns: | |||||
int: The number of origins matching the search criterion. | |||||
""" | |||||
return len(self.origin_search(url_pattern, regexp=regexp, | |||||
with_visit=with_visit, | |||||
limit=len(self._origins))) | |||||
def origin_add(self, origins): | def origin_add(self, origins): | ||||
"""Add origins to the storage | """Add origins to the storage | ||||
Args: | Args: | ||||
origins: list of dictionaries representing the individual origins, | origins: list of dictionaries representing the individual origins, | ||||
with the following keys: | with the following keys: | ||||
- type: the origin type ('git', 'svn', 'deb', ...) | - type: the origin type ('git', 'svn', 'deb', ...) | ||||
▲ Show 20 Lines • Show All 405 Lines • Show Last 20 Lines |
What's the difference with the former code?