Changeset View
Changeset View
Standalone View
Standalone View
swh/lister/debian/__init__.py
# Copyright (C) 2019 The Software Heritage developers | # Copyright (C) 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 typing import Any, List, Mapping, Optional | from typing import Any, List, Mapping | ||||
def debian_init(db_engine, lister=None, | def debian_init(db_engine, lister=None, | ||||
override_conf: Optional[Mapping[str, Any]] = None, | override_conf: Mapping[str, Any] = {}, | ||||
distributions: List[str] = ['stretch', 'buster'], | distributions: List[str] = ['stretch', 'buster'], | ||||
area_names: List[str] = ['main', 'contrib', 'non-free']): | area_names: List[str] = ['main', 'contrib', 'non-free']): | ||||
"""Initialize the debian data model. | """Initialize the debian data model. | ||||
Args: | Args: | ||||
db_engine: SQLAlchemy manipulation database object | db_engine: SQLAlchemy manipulation database object | ||||
lister: Debian lister instance. None by default. | lister: Debian lister instance. None by default. | ||||
override_conf: Override conf to pass to instantiate a lister. | override_conf: Override conf to pass to instantiate a lister | ||||
None by default | |||||
distributions: Default distribution to build | distributions: Default distribution to build | ||||
""" | """ | ||||
distribution_name = 'Debian' | |||||
from swh.storage.schemata.distribution import ( | from swh.storage.schemata.distribution import ( | ||||
Distribution, Area) | Distribution, Area) | ||||
if lister is None: | if lister is None: | ||||
from .lister import DebianLister | from .lister import DebianLister | ||||
lister = DebianLister(override_config=override_conf) | lister = DebianLister(distribution=distribution_name, | ||||
override_config=override_conf) | |||||
if not lister.db_session\ | if not lister.db_session\ | ||||
.query(Distribution)\ | .query(Distribution)\ | ||||
.filter(Distribution.name == 'Debian')\ | .filter(Distribution.name == distribution_name)\ | ||||
.one_or_none(): | .one_or_none(): | ||||
d = Distribution( | d = Distribution( | ||||
name='Debian', | name=distribution_name, | ||||
type='deb', | type='deb', | ||||
mirror_uri='http://deb.debian.org/debian/') | mirror_uri='http://deb.debian.org/debian/') | ||||
lister.db_session.add(d) | lister.db_session.add(d) | ||||
areas = [] | areas = [] | ||||
for distribution_name in distributions: | for distribution_name in distributions: | ||||
for area_name in area_names: | for area_name in area_names: | ||||
areas.append(Area( | areas.append(Area( | ||||
Show All 13 Lines |