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 | from typing import Any, List, Mapping | ||||
def debian_init(db_engine, | def debian_init(db_engine, | ||||
override_conf: Mapping[str, Any] = {}, | override_conf: Mapping[str, Any] = {}, | ||||
distributions: List[str] = ['stretch', 'buster'], | suites: List[str] = ['stretch', 'buster', 'bullseye'], | ||||
area_names: List[str] = ['main', 'contrib', 'non-free']): | components: 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 | ||||
override_conf: Override conf to pass to instantiate a lister | override_conf: Override conf to pass to instantiate a lister | ||||
distributions: Default distribution to build | suites: Default suites to build | ||||
components: Default components to build per suite | |||||
olasd: `s/build/register with the lister/`? | |||||
""" | """ | ||||
distribution_name = 'Debian' | distribution_name = 'Debian' | ||||
from swh.lister.debian.models import Distribution, Area | from swh.lister.debian.models import Distribution, Area | ||||
from sqlalchemy.orm import sessionmaker | from sqlalchemy.orm import sessionmaker | ||||
db_session = sessionmaker(bind=db_engine)() | db_session = sessionmaker(bind=db_engine)() | ||||
distrib = db_session.query(Distribution) \ | |||||
existing_distrib = db_session \ | |||||
.query(Distribution) \ | |||||
.filter(Distribution.name == distribution_name) \ | .filter(Distribution.name == distribution_name) \ | ||||
.one_or_none() | .one_or_none() | ||||
if not existing_distrib: | |||||
distrib = Distribution(name=distribution_name, | if distrib is None: | ||||
type='deb', | distrib = Distribution( | ||||
mirror_uri='http://deb.debian.org/debian/') | name=distribution_name, type='deb', | ||||
mirror_uri='http://deb.debian.org/debian/' | |||||
) | |||||
db_session.add(distrib) | db_session.add(distrib) | ||||
for distribution_name in distributions: | for suite in suites: | ||||
for area_name in area_names: | for component in components: | ||||
area = Area( | area = Area( | ||||
name='%s/%s' % (distribution_name, area_name), | name='%s/%s' % (suite, component), | ||||
distribution=distrib, | distribution=distrib, | ||||
) | ) | ||||
Not Done Inline ActionsMaybe this bit should be made idempotent as well. I'm not entirely sure what happens if we call the function twice now. olasd: Maybe this bit should be made idempotent as well. I'm not entirely sure what happens if we call… | |||||
Done Inline Actionsit explodes alright ;) E sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "area_distribution_id_name_key" E DETAIL: Key (distribution_id, name)=(1, wheezy/main) already exists. E E [SQL: INSERT INTO area (distribution_id, name, active) VALUES (%(distribution_id)s, %(name)s, %(active)s) RETURNING area.id] E [parameters: {'distribution_id': 1, 'name': 'wheezy/main', 'active': True}] E (Background on this error at: http://sqlalche.me/e/gkpj) ardumont: it explodes alright ;)
nice catch.
```
E sqlalchemy.exc.IntegrityError: (psycopg2.errors. | |||||
db_session.add(area) | db_session.add(area) | ||||
db_session.commit() | db_session.commit() | ||||
db_session.close() | db_session.close() | ||||
def register() -> Mapping[str, Any]: | def register() -> Mapping[str, Any]: | ||||
from .lister import DebianLister | from .lister import DebianLister | ||||
return {'models': [DebianLister.MODEL], | return {'models': [DebianLister.MODEL], | ||||
'lister': DebianLister, | 'lister': DebianLister, | ||||
'task_modules': ['%s.tasks' % __name__], | 'task_modules': ['%s.tasks' % __name__], | ||||
'init': debian_init} | 'init': debian_init} |
s/build/register with the lister/?