Skip to content
Snippets Groups Projects
Verified Commit c38a452d authored by Antoine R. Dumont's avatar Antoine R. Dumont
Browse files

archiver.storage: Add content_archive_content_add endpoint

Related T494
parent e962cdd7
No related branches found
No related tags found
No related merge requests found
# Copyright (C) 2015-2016 The Software Heritage developers
# Copyright (C) 2015-2017 The Software Heritage developers
# See the AUTHORS file at the top-level directory of this distribution
# License: GNU General Public License version 3, or any later version
# See top-level LICENSE file for more information
import json
import time
from swh.core import hashutil
......@@ -258,3 +259,29 @@ class ArchiverDb(BaseDb):
cur = self._cursor(cur)
cur.execute(query)
def content_archive_content_add(
self, content_id, sources_present, sources_missing, cur=None):
if isinstance(content_id, bytes):
content_id = '\\x%s' % hashutil.hash_to_hex(content_id)
copies = {}
num_present = 0
for source in sources_present:
copies[source] = {
"status": "present",
"mtime": int(time.time()),
}
num_present += 1
for source in sources_missing:
copies[source] = {
"status": "absent",
}
query = """INSERT INTO content_archive(content_id, copies, num_present)
VALUES('%s', '%s', %s)
""" % (content_id, json.dumps(copies), num_present)
cur = self._cursor(cur)
cur.execute(query)
......@@ -166,3 +166,18 @@ class ArchiverStorage():
"""
self.db.content_archive_insert(content_id, source, status, cur)
@db_transaction
def content_archive_content_add(
self, content_ids, sources_present, sources_missing, cur=None):
"""Insert a new entry in db about content_id.
Args:
content_ids ([bytes|str]): content identifiers
sources_present: name of the source where the contents are present
sources_missing: name of the source where the contents are missing
"""
for content_id in content_ids:
self.db.content_archive_content_add(
content_id, sources_present, sources_missing)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment