Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show First 20 Lines • Show All 504 Lines • ▼ Show 20 Lines | def content_find(self, content, db=None, cur=None): | ||||
Raises: | Raises: | ||||
ValueError: in case the key of the dictionary is not sha1, sha1_git | ValueError: in case the key of the dictionary is not sha1, sha1_git | ||||
nor sha256. | nor sha256. | ||||
""" | """ | ||||
if not set(content).intersection(ALGORITHMS): | if not set(content).intersection(ALGORITHMS): | ||||
raise ValueError('content keys must contain at least one of: ' | raise ValueError('content keys must contain at least one of: ' | ||||
'sha1, sha1_git, sha256, blake2s256') | 'sha1, sha1_git, sha256, blake2s256') | ||||
c = db.content_find(sha1=content.get('sha1'), | contents = db.content_find(sha1=content.get('sha1'), | ||||
sha1_git=content.get('sha1_git'), | sha1_git=content.get('sha1_git'), | ||||
sha256=content.get('sha256'), | sha256=content.get('sha256'), | ||||
blake2s256=content.get('blake2s256'), | blake2s256=content.get('blake2s256'), | ||||
cur=cur) | cur=cur) | ||||
if c: | if contents: | ||||
return dict(zip(db.content_find_cols, c)) | contents_list = [] | ||||
for cont in contents: | |||||
contents_list.append(dict(zip(db.content_find_cols, cont))) | |||||
return contents_list | |||||
vlorentz: Could you rename the variables here? `c` was a bad choice (before your diff, it's not your… | |||||
return None | return None | ||||
@db_transaction() | @db_transaction() | ||||
def directory_add(self, directories, db, cur): | def directory_add(self, directories, db, cur): | ||||
"""Add directories to the storage | """Add directories to the storage | ||||
Args: | Args: | ||||
directories (iterable): iterable of dictionaries representing the | directories (iterable): iterable of dictionaries representing the | ||||
▲ Show 20 Lines • Show All 1,268 Lines • Show Last 20 Lines |
Could you rename the variables here? c was a bad choice (before your diff, it's not your fault)