Changeset View
Changeset View
Standalone View
Standalone View
swh/scanner/db.py
# Copyright (C) 2020 The Software Heritage developers | # Copyright (C) 2020 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 | ||||
""" | """ | ||||
This module is an interface to interact with the local database | This module is an interface to interact with the local database | ||||
where the SWHIDs will be saved for the local API. | where the SWHIDs will be saved for the local API. | ||||
SWHIDs can be added directly from an input file. | SWHIDs can be added directly from an input file. | ||||
""" | """ | ||||
from io import TextIOWrapper | from io import TextIOWrapper | ||||
import logging | import logging | ||||
from pathlib import Path | from pathlib import Path | ||||
import re | |||||
import sqlite3 | import sqlite3 | ||||
from typing import Iterable | from typing import Iterable | ||||
from swh.core.utils import grouper | from swh.core.utils import grouper | ||||
from swh.model.swhids import SWHID_RE | |||||
from .exceptions import DBError | from .exceptions import DBError | ||||
# XXX copied and simplified from swh.model.identifiers (WIP), replace this in favor of | |||||
# swh.model.identifiers.SWHID_RE when it is landed there | |||||
SWHID_RE = re.compile("^swh:1:(ori|snp|rel|rev|dir|cnt):[0-9a-f]{40}$") | |||||
class Db: | class Db: | ||||
"""Local database interface""" | """Local database interface""" | ||||
def __init__(self, db_file: Path): | def __init__(self, db_file: Path): | ||||
self.db_file: Path = db_file | self.db_file: Path = db_file | ||||
self.conn: sqlite3.Connection = sqlite3.connect( | self.conn: sqlite3.Connection = sqlite3.connect( | ||||
db_file, check_same_thread=False | db_file, check_same_thread=False | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |