Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/storage.py
# Copyright (C) 2015-2019 The Software Heritage developers | # Copyright (C) 2015-2019 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 | ||||
from collections import defaultdict | from collections import defaultdict | ||||
import copy | import copy | ||||
from concurrent.futures import ThreadPoolExecutor | from concurrent.futures import ThreadPoolExecutor | ||||
from contextlib import contextmanager | |||||
import datetime | import datetime | ||||
import itertools | import itertools | ||||
import json | import json | ||||
import dateutil.parser | import dateutil.parser | ||||
import psycopg2 | import psycopg2 | ||||
import psycopg2.pool | import psycopg2.pool | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | def get_db(self): | ||||
return self._db | return self._db | ||||
else: | else: | ||||
return Db.from_pool(self._pool) | return Db.from_pool(self._pool) | ||||
def put_db(self, db): | def put_db(self, db): | ||||
if db is not self._db: | if db is not self._db: | ||||
db.put_conn() | db.put_conn() | ||||
@contextmanager | |||||
def db(self): | |||||
db = None | |||||
try: | |||||
db = self.get_db() | |||||
yield db | |||||
finally: | |||||
if db: | |||||
self.put_db(db) | |||||
@db_transaction() | @db_transaction() | ||||
def check_config(self, *, check_write, db, cur): | def check_config(self, *, check_write, db, cur): | ||||
"""Check that the storage is configured and ready to go.""" | """Check that the storage is configured and ready to go.""" | ||||
if not self.objstorage.check_config(check_write=check_write): | if not self.objstorage.check_config(check_write=check_write): | ||||
return False | return False | ||||
# Check permissions on one of the tables | # Check permissions on one of the tables | ||||
▲ Show 20 Lines • Show All 1,844 Lines • Show Last 20 Lines |