Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/db.py
# Copyright (C) 2015 The Software Heritage developers | # Copyright (C) 2015-2016 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import binascii | import binascii | ||||
import datetime | import datetime | ||||
import functools | import functools | ||||
import json | import json | ||||
▲ Show 20 Lines • Show All 329 Lines • ▼ Show 20 Lines | revision_add_cols = [ | ||||
'directory', 'message', 'author_fullname', 'author_name', | 'directory', 'message', 'author_fullname', 'author_name', | ||||
'author_email', 'committer_fullname', 'committer_name', | 'author_email', 'committer_fullname', 'committer_name', | ||||
'committer_email', 'metadata', 'synthetic', | 'committer_email', 'metadata', 'synthetic', | ||||
] | ] | ||||
revision_get_cols = revision_add_cols + [ | revision_get_cols = revision_add_cols + [ | ||||
'author_id', 'committer_id', 'parents'] | 'author_id', 'committer_id', 'parents'] | ||||
def origin_visit_add(self, origin, ts, cur=None): | |||||
"""Add a new origin_visit for origin origin at timestamp ts with | |||||
status 'ongoing'. | |||||
Args: | |||||
origin: origin concerned by the visit | |||||
ts: the date of the visit | |||||
Returns: | |||||
The new visit index step for that origin | |||||
""" | |||||
cur = self._cursor(cur) | |||||
self._cursor(cur).execute('SELECT swh_origin_visit_add(%s, %s)', | |||||
(origin, ts)) | |||||
return cur.fetchone()[0] | |||||
def origin_visit_update(self, origin, visit_id, status, cur): | |||||
"""Update origin_visit's status.""" | |||||
cur = self._cursor(cur) | |||||
update = """UPDATE origin_visit | |||||
SET status=%s | |||||
WHERE origin=%s AND visit=%s""" | |||||
cur.execute(update, (status, origin, visit_id)) | |||||
origin_visit_get_cols = [ | origin_visit_get_cols = [ | ||||
'origin', 'visit', 'date' | 'origin', 'visit', 'date', 'status' | ||||
] | ] | ||||
def origin_visit_get(self, origin_id, cur=None): | def origin_visit_get(self, origin_id, cur=None): | ||||
"""Retrieve occurrence's history information by origin_id. | """Retrieve all visits for origin with id origin_id. | ||||
Args: | Args: | ||||
origin_id: The occurrence's origin | origin_id: The occurrence's origin | ||||
Yields: | Yields: | ||||
The occurrence's history visits | The occurrence's history visits | ||||
""" | """ | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
cur.execute( | cur.execute( | ||||
'SELECT origin, visit, date FROM origin_visit where origin=%s', | """SELECT origin, visit, date, status | ||||
FROM origin_visit | |||||
WHERE origin=%s""", | |||||
(origin_id, )) | (origin_id, )) | ||||
yield from cursor_to_bytes(cur) | yield from cursor_to_bytes(cur) | ||||
def revision_get_from_temp(self, cur=None): | def revision_get_from_temp(self, cur=None): | ||||
cur = self._cursor(cur) | cur = self._cursor(cur) | ||||
query = 'SELECT %s FROM swh_revision_get()' % ( | query = 'SELECT %s FROM swh_revision_get()' % ( | ||||
', '.join(self.revision_get_cols)) | ', '.join(self.revision_get_cols)) | ||||
▲ Show 20 Lines • Show All 468 Lines • Show Last 20 Lines |