Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/db.py
Show First 20 Lines • Show All 618 Lines • ▼ Show 20 Lines | def entity_get_one(self, uuid, cur=None): | ||||
FROM entity | FROM entity | ||||
WHERE uuid = %%s""" % ( | WHERE uuid = %%s""" % ( | ||||
', '.join(self.entity_cols)), | ', '.join(self.entity_cols)), | ||||
(uuid, )) | (uuid, )) | ||||
data = cur.fetchone() | data = cur.fetchone() | ||||
if not data: | if not data: | ||||
return None | return None | ||||
return line_to_bytes(data) | return line_to_bytes(data) | ||||
def archive_ls(self, cur=None): | |||||
""" Get all the archives registered on the server. | |||||
Yields: | |||||
a tuple (server_id, server_url) for each archive server. | |||||
""" | |||||
cur = self._cursor(cur) | |||||
cur.execute("""SELECT id, url | |||||
FROM archives | |||||
""") | |||||
yield from cursor_to_bytes(cur) | |||||
def content_archive_ls(self, cur=None): | |||||
""" Get the archival status of the content | |||||
Get an iterable over all the content that is referenced | |||||
in a backup server. | |||||
Yields: | |||||
the sha1 of each content referenced at least one time | |||||
in the database of archiveal status. | |||||
""" | |||||
cur = self._cursor(cur) | |||||
cur.execute("""SELECT DISTINCT content_id | |||||
FROM content_archive""") | |||||
yield from cursor_to_bytes(cur) | |||||
def content_archive_get(self, content=None, archive=None, cur=None): | |||||
""" Get the archival status of a content in a specific server. | |||||
Retreive from the database the archival status of the given content | |||||
in the given archive server. | |||||
Args: | |||||
content: the sha1 of the content. May be None for any id. | |||||
archive: the database id of the server we're looking into | |||||
may be None for any server. | |||||
Yields: | |||||
A tuple (content_id, server_id, archival status, mtime, tzinfo). | |||||
""" | |||||
query = """SELECT content_id, archive_id, status, mtime | |||||
FROM content_archive | |||||
""" | |||||
conditions = [] | |||||
if content: | |||||
conditions.append("content_id='%s'" % content) | |||||
if archive: | |||||
conditions.append("archive_id='%s'" % archive) | |||||
if conditions: | |||||
query = """%s | |||||
WHERE %s | |||||
""" % (query, ' and '.join(conditions)) | |||||
cur = self._cursor(cur) | |||||
cur.execute(query) | |||||
yield from cursor_to_bytes(cur) |