aboutsummaryrefslogtreecommitdiffstats
path: root/templates
diff options
context:
space:
mode:
authorEdi Feschiyan <553226+refresher@users.noreply.github.com>2020-06-18 13:12:31 +0300
committerEdi Feschiyan <553226+refresher@users.noreply.github.com>2020-06-18 13:12:31 +0300
commit80159d8789fe2ea0b36d84b83348813f67e18652 (patch)
treea997c5013257bdb7d02518d86c21595c15a33ced /templates
parent8a8b87e65c0b3d579f8ea420e23a9cd07528dfe1 (diff)
Rearranging files for distribution, setup.py modifications
Diffstat (limited to 'templates')
-rw-r--r--templates/cookiecutter.json8
-rw-r--r--templates/service/cookiecutter.json6
-rw-r--r--templates/service/{{cookiecutter.file_name}}.py9
-rw-r--r--templates/test/{{cookiecutter.file_name}}.py0
-rw-r--r--templates/{{cookiecutter.services_dir}}/{{cookiecutter.service_slug}}.py17
-rw-r--r--templates/{{cookiecutter.tests_dir}}/test_{{cookiecutter.service_slug}}.py23
6 files changed, 48 insertions, 15 deletions
diff --git a/templates/cookiecutter.json b/templates/cookiecutter.json
new file mode 100644
index 0000000..c4afdd6
--- /dev/null
+++ b/templates/cookiecutter.json
@@ -0,0 +1,8 @@
+{
+ "services_dir": "services",
+ "tests_dir": "tests",
+ "service_slug": "service",
+ "aglsystemdservice": "agl-service-something",
+ "classname": "NewService",
+ "api": "serviceapi"
+}
diff --git a/templates/service/cookiecutter.json b/templates/service/cookiecutter.json
deleted file mode 100644
index f37ea1f..0000000
--- a/templates/service/cookiecutter.json
+++ /dev/null
@@ -1,6 +0,0 @@
-{
- "aglsystemdservice": "agl-service-something",
- "classname": "NewService",
- "api": "serviceapi",
- "verblist": ["subscribe", "unsubscribe"]
-} \ No newline at end of file
diff --git a/templates/service/{{cookiecutter.file_name}}.py b/templates/service/{{cookiecutter.file_name}}.py
deleted file mode 100644
index 6defd28..0000000
--- a/templates/service/{{cookiecutter.file_name}}.py
+++ /dev/null
@@ -1,9 +0,0 @@
-from aglbaseservice import AGLBaseService, AFBResponse
-import asyncio
-import os
-
-class {{cookiecutter.classname}}(AGLBaseService):
-
- def __init__(self, ip, port=None, service='{{cookiecutter.aglsystemdservice}}'):
- super().__init__(api='{{cookiecutter.api}}', ip=ip, port=port, service=service)
-
diff --git a/templates/test/{{cookiecutter.file_name}}.py b/templates/test/{{cookiecutter.file_name}}.py
deleted file mode 100644
index e69de29..0000000
--- a/templates/test/{{cookiecutter.file_name}}.py
+++ /dev/null
diff --git a/templates/{{cookiecutter.services_dir}}/{{cookiecutter.service_slug}}.py b/templates/{{cookiecutter.services_dir}}/{{cookiecutter.service_slug}}.py
new file mode 100644
index 0000000..dab3a68
--- /dev/null
+++ b/templates/{{cookiecutter.services_dir}}/{{cookiecutter.service_slug}}.py
@@ -0,0 +1,17 @@
+from pyagl.services.base import AGLBaseService, AFBResponse
+import asyncio
+import os
+
+
+class {{cookiecutter.classname}}(AGLBaseService):
+ service = '{{cookiecutter.aglsystemdservice}}'
+ parser = AGLBaseService.getparser()
+
+ def __init__(self, ip, port=None, service='{{cookiecutter.aglsystemdservice}}'):
+ super().__init__(api='{{cookiecutter.api}}', ip=ip, port=port, service=service)
+ # more init stuff specific to the new service
+
+async def main(loop):
+ args = {{cookiecutter.classname}}.parser.parse_args()
+ svc = {{cookiecutter.classname}}(args.ipaddr)
+
diff --git a/templates/{{cookiecutter.tests_dir}}/test_{{cookiecutter.service_slug}}.py b/templates/{{cookiecutter.tests_dir}}/test_{{cookiecutter.service_slug}}.py
new file mode 100644
index 0000000..e193205
--- /dev/null
+++ b/templates/{{cookiecutter.tests_dir}}/test_{{cookiecutter.service_slug}}.py
@@ -0,0 +1,23 @@
+import asyncio
+import os
+import pytest
+import logging
+from pyagl.services.base import AFBResponse, AFBT
+from concurrent.futures import TimeoutError
+
+from pyagl.services.{{cookiecutter.service_slug}} import {{cookiecutter.classname}}
+pytestmark = pytest.mark.asyncio
+
+@pytest.fixture(scope='module')
+def event_loop():
+ loop = asyncio.get_event_loop()
+ yield loop
+ loop.close()
+
+@pytest.fixture(scope='module')
+async def service():
+ address = os.environ.get('AGL_TGT_IP', 'localhost')
+ port = os.environ.get('AGL_TGT_PORT', None)
+ svc = await {{cookiecutter.classname}}(ip=address, port=port)
+ yield svc
+ await svc.websocket.close()