Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
Show First 20 Lines • Show All 695 Lines • ▼ Show 20 Lines | def occurrence_add(self, occurrences, cur=None): | ||||
occurrences to add. Each dict has the following keys: | occurrences to add. Each dict has the following keys: | ||||
- origin (int): id of the origin corresponding to the | - origin (int): id of the origin corresponding to the | ||||
occurrence | occurrence | ||||
- branch (str): the reference name of the occurrence | - branch (str): the reference name of the occurrence | ||||
- target (sha1_git): the id of the object pointed to by | - target (sha1_git): the id of the object pointed to by | ||||
the occurrence | the occurrence | ||||
- target_type (str): the type of object pointed to by the | - target_type (str): the type of object pointed to by the | ||||
occurrence | occurrence | ||||
- date (datetime.DateTime): the validity date for the given | |||||
occurrence | |||||
""" | """ | ||||
db = self.db | db = self.db | ||||
processed = [] | |||||
for occurrence in occurrences: | |||||
if isinstance(occurrence['date'], str): | |||||
occurrence['date'] = dateutil.parser.parse(occurrence['date']) | |||||
processed.append(occurrence) | |||||
db.mktemp_occurrence_history(cur) | db.mktemp_occurrence_history(cur) | ||||
db.copy_to(processed, 'tmp_occurrence_history', | db.copy_to(occurrences, 'tmp_occurrence_history', | ||||
['origin', 'branch', 'target', 'target_type', 'date'], cur) | ['origin', 'branch', 'target', 'target_type', 'visit'], cur) | ||||
db.occurrence_history_add_from_temp(cur) | db.occurrence_history_add_from_temp(cur) | ||||
@db_transaction_generator | @db_transaction_generator | ||||
def occurrence_get(self, origin_id, cur=None): | def occurrence_get(self, origin_id, cur=None): | ||||
"""Retrieve occurrence information per origin_id. | """Retrieve occurrence information per origin_id. | ||||
Args: | Args: | ||||
origin_id: The occurrence's origin. | origin_id: The occurrence's origin. | ||||
Yields: | Yields: | ||||
List of occurrences matching criterion. | List of occurrences matching criterion. | ||||
""" | """ | ||||
db = self.db | db = self.db | ||||
for line in db.occurrence_get(origin_id, cur): | for line in db.occurrence_get(origin_id, cur): | ||||
yield { | yield { | ||||
'origin': line[0], | 'origin': line[0], | ||||
'branch': line[1], | 'branch': line[1], | ||||
'target': line[2], | 'target': line[2], | ||||
'target_type': line[3], | 'target_type': line[3], | ||||
} | } | ||||
@db_transaction | |||||
def origin_visit_add(self, origin, ts, cur=None): | |||||
"""Add an origin_visit for the origin at ts with status 'ongoing'. | |||||
Args: | |||||
origin: Visited Origin id | |||||
ts: timestamp of such visit | |||||
Returns: | |||||
Dict with keys origin and visit where: | |||||
- origin: origin identifier | |||||
- visit: the visit identifier for the new visit occurrence | |||||
- ts (datetime.DateTime): the visit date | |||||
""" | |||||
if isinstance(ts, str): | |||||
ts = dateutil.parser.parse(ts) | |||||
return { | |||||
'origin': origin, | |||||
'visit': self.db.origin_visit_add(origin, ts, cur) | |||||
} | |||||
@db_transaction | |||||
def origin_visit_update(self, origin, visit_id, status, cur=None): | |||||
"""Update an origin_visit's status. | |||||
Args: | |||||
origin: Visited Origin id | |||||
visit_id: Visit's id | |||||
status: Visit's new status | |||||
Returns: | |||||
None | |||||
""" | |||||
return self.db.origin_visit_update(origin, visit_id, status, cur) | |||||
@db_transaction_generator | @db_transaction_generator | ||||
def origin_visit_get(self, origin, cur=None): | def origin_visit_get(self, origin, cur=None): | ||||
"""Retrieve origin's visit dates. | """Retrieve origin's visit dates. | ||||
Args: | Args: | ||||
origin: The occurrence's origin (identifier). | origin: The occurrence's origin (identifier). | ||||
Yields: | Yields: | ||||
▲ Show 20 Lines • Show All 339 Lines • Show Last 20 Lines |