diff --git a/messages/v1/messages/source.create.yml b/messages/v1/messages/source.create.yml new file mode 100644 index 0000000..7f696c6 --- /dev/null +++ b/messages/v1/messages/source.create.yml @@ -0,0 +1,25 @@ +--- +uri: source.create + +description: | + Créer une source. + +pattern: rpc + +public: true + +parameters: + source_name: + type: String + shortarg: n + description: | + Nom de la source. + source_url: + type: String + shortarg: u + description: | + URL de téléchargement de la source. + +response: + type: 'Source' + description: Information sur la source. diff --git a/messages/v1/messages/source.dataset.updated.yml b/messages/v1/messages/source.dataset.update.yml similarity index 61% rename from messages/v1/messages/source.dataset.updated.yml rename to messages/v1/messages/source.dataset.update.yml index 0a6f393..02d421d 100644 --- a/messages/v1/messages/source.dataset.updated.yml +++ b/messages/v1/messages/source.dataset.update.yml @@ -1,4 +1,4 @@ -uri: source.dataset.updated +uri: source.dataset.update description: | Initialise la table pour les versions. @@ -8,14 +8,10 @@ pattern: rpc public: true parameters: - source_name: - type: String + source_id: + type: Number shortarg: s - description: Nom de la source. - source_url: - type: String - shortarg: u - description: URL de la source. + description: ID de la source. release_name: type: String shortarg: r diff --git a/messages/v1/messages/source.get.yml b/messages/v1/messages/source.get.yml new file mode 100644 index 0000000..c38f556 --- /dev/null +++ b/messages/v1/messages/source.get.yml @@ -0,0 +1,20 @@ +--- +uri: source.get + +description: | + Retourne une source. + +pattern: rpc + +public: true + +parameters: + source_name: + type: String + shortarg: n + description: | + Nom de la source. + +response: + type: 'Source' + description: Information sur la source. diff --git a/messages/v1/messages/old/servermodel.source.list.yml b/messages/v1/messages/source.list.yml similarity index 51% rename from messages/v1/messages/old/servermodel.source.list.yml rename to messages/v1/messages/source.list.yml index 86f753c..f6d5d24 100644 --- a/messages/v1/messages/old/servermodel.source.list.yml +++ b/messages/v1/messages/source.list.yml @@ -1,18 +1,13 @@ --- -uri: servermodel.source.list +uri: source.list description: | Retourne la liste des sources. -sampleuse: | - zephir-client servermodel.source.list - pattern: rpc public: true -domain: servermodel-domain - response: - type: '[]Dict' + type: '[]Source' description: Liste des sources disponibles. diff --git a/messages/v1/types/source.yml b/messages/v1/types/source.yml new file mode 100644 index 0000000..9e0983c --- /dev/null +++ b/messages/v1/types/source.yml @@ -0,0 +1,20 @@ +--- +title: Source +type: object +description: Description d'un source. +properties: + source_id: + type: number + description: ID de la source. + ref: Source.SourceId + source_name: + type: string + description: Nom de la source. + source_url: + type: string + description: URL de téléchargement de la source. + +required: + - source_id + - source_name + - source_url diff --git a/src/risotto/config.py b/src/risotto/config.py index 44dfdc2..71bcacb 100644 --- a/src/risotto/config.py +++ b/src/risotto/config.py @@ -22,5 +22,6 @@ def get_config(): 'global': {'message_root_path': 'messages', 'debug': DEBUG, 'internal_user': 'internal', - 'rougail_dtd_path': '../rougail/data/creole.dtd'} + 'rougail_dtd_path': '../rougail/data/creole.dtd'}, + 'source': {'root_path': '/srv/seed'} } diff --git a/src/risotto/services/servermodel/servermodel.py b/src/risotto/services/servermodel/servermodel.py index fbf3f09..745d954 100644 --- a/src/risotto/services/servermodel/servermodel.py +++ b/src/risotto/services/servermodel/servermodel.py @@ -42,7 +42,7 @@ class Risotto(Controller): def parse_parents(self, servermodels: Dict, - servermodel: Dist, + servermodel: Dict, parents: List=None) -> List: if parents is None: parents = [servermodel] @@ -95,7 +95,7 @@ class Risotto(Controller): if not servermodels[new_servermodel]['done']: servermodel_description = servermodels[new_servermodel] parent = servermodel_description['parent'] - if not servermodelparent_id and parent None: + if not servermodelparent_id and parent is not None: # parent is a str, so get ID servermodelparent_id = [await self.get_servermodel_id_by_name(risotto_context, parent, diff --git a/src/risotto/services/source/source.py b/src/risotto/services/source/source.py index 56ff5f7..7d50dcf 100644 --- a/src/risotto/services/source/source.py +++ b/src/risotto/services/source/source.py @@ -1,5 +1,7 @@ +from typing import Dict, List from ...controller import Controller from ...register import register +from ...context import Context VERSION_INIT = """ -- Création de la table Source @@ -21,19 +23,55 @@ CREATE TABLE Release ( RELEASE_QUERY = """SELECT ReleaseId as release_id, SourceName as source_name, SourceURL as source_url, ReleaseName as release_name FROM Release, Source WHERE Source.SourceId=Release.ReleaseSourceId""" class Risotto(Controller): - - @register('v1.source.dataset.updated', None, database=True) - async def version_update(self, risotto_context, source_name, source_url, release_name): + @register('v1.source.create', None, database=True) + async def source_create(self, + risotto_context: Context, + source_name: str, + source_url: str) -> Dict: source_upsert = """INSERT INTO Source(SourceName, SourceURL) VALUES ($1, $2) ON CONFLICT (SourceName) DO UPDATE SET SourceURL = $2 RETURNING SourceId """ + source_id = await risotto_context.connection.fetchval(source_upsert, + source_name, + source_url) + return {'source_name': source_name, + 'source_url': source_url, + 'source_id': source_id} + + @register('v1.source.get', None, database=True) + async def source_get(self, + risotto_context: Context, + source_name: str) -> Dict: + source_get = """SELECT SourceId as source_id, SourceName as source_name, SourceURL as source_url + FROM Source + WHERE SourceName = $1 + """ + return dict(await risotto_context.connection.fetchrow(source_get, + source_name)) + + @register('v1.source.list', None, database=True) + async def source_list(self, + risotto_context: Context) -> List[Dict]: + source_list = """SELECT SourceId as source_id, SourceName as source_name, SourceURL as source_url + FROM Source + """ + result = await risotto_context.connection.fetch(source_list) + return [dict(r) for r in result] + + @register('v1.source.dataset.update', None, database=True) + async def version_update(self, + risotto_context: Context, + source_id: int, + release_name: str): release_insert = """INSERT INTO Release(ReleaseName, ReleaseSourceId) VALUES ($1, $2) RETURNING ReleaseId """ - source_id = await risotto_context.connection.fetchval(source_upsert, source_name, source_url) - result = await risotto_context.connection.fetchval(release_insert, release_name, source_id) - return {'release_id': result, 'source_name': source_name, 'source_url': source_url, 'release_name': release_name} + release_id = await risotto_context.connection.fetchval(release_insert, + release_name, + source_id) + return {'release_id': release_id, + 'release_name': release_name} @register('v1.source.release.list', None, database=True) async def release_list(self, risotto_context):