Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show First 20 Lines • Show All 1,205 Lines • ▼ Show 20 Lines | def snapshot_get_branches(self, snapshot_id, branches_from=b'', | ||||
'id': snapshot_id, | 'id': snapshot_id, | ||||
'branches': branches, | 'branches': branches, | ||||
'next_branch': next_branch, | 'next_branch': next_branch, | ||||
} | } | ||||
return None | return None | ||||
@db_transaction() | @db_transaction() | ||||
def origin_visit_add(self, origin, date, type=None, | def origin_visit_add(self, origin, date, type, | ||||
db=None, cur=None): | db=None, cur=None): | ||||
"""Add an origin_visit for the origin at ts with status 'ongoing'. | """Add an origin_visit for the origin at ts with status 'ongoing'. | ||||
For backward compatibility, `type` is optional and defaults to | |||||
the origin's type. | |||||
Args: | Args: | ||||
origin (Union[int,str]): visited origin's identifier or URL | origin (Union[int,str]): visited origin's identifier or URL | ||||
date (Union[str,datetime]): timestamp of such visit | date (Union[str,datetime]): timestamp of such visit | ||||
type (str): the type of loader used for the visit (hg, git, ...) | type (str): the type of loader used for the visit (hg, git, ...) | ||||
Returns: | Returns: | ||||
dict: dictionary with keys origin and visit where: | dict: dictionary with keys origin and visit where: | ||||
- origin: origin identifier | - origin: origin identifier | ||||
- visit: the visit identifier for the new visit occurrence | - visit: the visit identifier for the new visit occurrence | ||||
""" | """ | ||||
if isinstance(origin, str): | if isinstance(origin, str): | ||||
origin = self.origin_get({'url': origin}, db=db, cur=cur) | origin = self.origin_get({'url': origin}, db=db, cur=cur) | ||||
origin_id = origin['id'] | origin_id = origin['id'] | ||||
else: | else: | ||||
origin = self.origin_get({'id': origin}, db=db, cur=cur) | origin = self.origin_get({'id': origin}, db=db, cur=cur) | ||||
origin_id = origin['id'] | origin_id = origin['id'] | ||||
if isinstance(date, str): | if isinstance(date, str): | ||||
# FIXME: Converge on iso8601 at some point | # FIXME: Converge on iso8601 at some point | ||||
date = dateutil.parser.parse(date) | date = dateutil.parser.parse(date) | ||||
if type is None: | |||||
type = origin['type'] | |||||
visit_id = db.origin_visit_add(origin_id, date, type, cur) | visit_id = db.origin_visit_add(origin_id, date, type, cur) | ||||
if self.journal_writer: | if self.journal_writer: | ||||
# We can write to the journal only after inserting to the | # We can write to the journal only after inserting to the | ||||
# DB, because we want the id of the visit | # DB, because we want the id of the visit | ||||
del origin['id'] | del origin['id'] | ||||
self.journal_writer.write_addition('origin_visit', { | self.journal_writer.write_addition('origin_visit', { | ||||
'origin': origin, 'date': date, 'type': type, | 'origin': origin, 'date': date, 'type': type, | ||||
▲ Show 20 Lines • Show All 653 Lines • Show Last 20 Lines |