diff options
| author | bozo.kopic <bozo.kopic@gmail.com> | 2019-04-08 22:47:10 +0200 |
|---|---|---|
| committer | bozo.kopic <bozo.kopic@gmail.com> | 2019-04-08 22:47:10 +0200 |
| commit | f53913389fa435d26307075bf5dab3675b1f17c4 (patch) | |
| tree | f70d5fd95070b6f1f5f427d2d43da7f77d000efa /src_py | |
| parent | 07dae145e814856c8f38f407d91a033b233c081d (diff) | |
dependencies update & minor fixes
Diffstat (limited to 'src_py')
| -rw-r--r-- | src_py/opcut/__init__.py | 0 | ||||
| -rw-r--r-- | src_py/opcut/__main__.py | 7 | ||||
| -rw-r--r-- | src_py/opcut/doit/jsopcut.py | 62 | ||||
| -rw-r--r-- | src_py/opcut/doit/main.py | 5 | ||||
| -rw-r--r-- | src_py/opcut/output.py | 3 | ||||
| -rw-r--r-- | src_py/opcut/server.py | 39 |
6 files changed, 52 insertions, 64 deletions
diff --git a/src_py/opcut/__init__.py b/src_py/opcut/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src_py/opcut/__init__.py diff --git a/src_py/opcut/__main__.py b/src_py/opcut/__main__.py new file mode 100644 index 0000000..549881a --- /dev/null +++ b/src_py/opcut/__main__.py @@ -0,0 +1,7 @@ +import sys + +from opcut.main import main + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/src_py/opcut/doit/jsopcut.py b/src_py/opcut/doit/jsopcut.py index 4fbbe69..0525aa6 100644 --- a/src_py/opcut/doit/jsopcut.py +++ b/src_py/opcut/doit/jsopcut.py @@ -1,14 +1,11 @@ -import json -import yaml -from pathlib import Path +import subprocess from opcut.doit import _common __all__ = ['task_jsopcut_clean', 'task_jsopcut_install_deps', - 'task_jsopcut_remove_deps', 'task_jsopcut_gen', - 'task_jsopcut_gen_validator', 'task_jsopcut_build', - 'task_jsopcut_watch'] + 'task_jsopcut_remove_deps', 'task_jsopcut_build', + 'task_jsopcut_watch', 'task_jsopcut_check'] def task_jsopcut_clean(): @@ -21,7 +18,14 @@ def task_jsopcut_clean(): def task_jsopcut_install_deps(): """JsOpcut - install dependencies""" - return {'actions': ['yarn install']} + def patch(): + subprocess.Popen(['patch', '-r', '/dev/null', '--forward', '-p0', + '-i', 'node_modules.patch'], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL).wait() + + return {'actions': ['yarn install --silent', + patch]} def task_jsopcut_remove_deps(): @@ -30,48 +34,22 @@ def task_jsopcut_remove_deps(): return {'actions': [(_common.rm_rf, ['node_modules'])]} -def task_jsopcut_gen(): - """JsOpcut - generate additional JavaScript modules""" - - return {'actions': None, - 'task_dep': ['jsopcut_gen_validator']} - - -def task_jsopcut_gen_validator(): - """JsOpcut - generate json validator""" - - schema_files = list(Path('schemas_json').glob('**/*.yaml')) - output_file = Path('src_js/opcut/validator.js') - - def parse_schemas(): - for schema_file in schema_files: - with open(schema_file, encoding='utf-8') as f: - yield yaml.safe_load(f) - - def generate_output(): - schemas_json = json.dumps(list(parse_schemas()), indent=4) - with open(output_file, 'w', encoding='utf-8') as f: - f.write( - 'import tv4 from "tv4";\n\n\n' + - schemas_json + '.forEach(i => tv4.addSchema(i.id, i));\n\n\n' + - 'export function validate(data, schemaId) {\n' + - ' return tv4.validate(data, tv4.getSchema(schemaId));\n' + - '}\n') - - return {'actions': [generate_output], - 'file_dep': schema_files, - 'targets': [output_file]} - - def task_jsopcut_build(): """JsOpcut - build""" return {'actions': ['yarn run build'], - 'task_dep': ['jsopcut_install_deps', 'jsopcut_gen']} + 'task_dep': ['jsopcut_install_deps']} def task_jsopcut_watch(): """JsOpcut - build on change""" return {'actions': ['yarn run watch'], - 'task_dep': ['jsopcut_install_deps', 'jsopcut_gen']} + 'task_dep': ['jsopcut_install_deps']} + + +def task_jsopcut_check(): + """JsOpcut - check""" + + return {'actions': ['yarn run check'], + 'task_dep': ['jsopcut_install_deps']} diff --git a/src_py/opcut/doit/main.py b/src_py/opcut/doit/main.py index fb34e8c..68624e9 100644 --- a/src_py/opcut/doit/main.py +++ b/src_py/opcut/doit/main.py @@ -27,8 +27,7 @@ def task_gen_all(): """Generate all""" return {'actions': None, - 'task_dep': ['pyopcut_gen', - 'jsopcut_gen']} + 'task_dep': ['pyopcut_gen']} def task_check_all(): @@ -61,7 +60,7 @@ def task_dist_build(): (_common.cp_r, ['build/jsopcut', 'build/dist/opcut/web']), (_common.cp_r, ['README.rst', 'build/dist/README.rst']), generate_setup_py, - CmdAction('python setup.py bdist_wheel --dist-dir ../../dist', + CmdAction('python setup.py -q bdist_wheel -d ../../dist', cwd='build/dist')], 'task_dep': [ 'gen_all', diff --git a/src_py/opcut/output.py b/src_py/opcut/output.py index 53bbe7a..e070710 100644 --- a/src_py/opcut/output.py +++ b/src_py/opcut/output.py @@ -76,7 +76,8 @@ def _write_used(surface, scale, x0, y0, used): ctx.rectangle(x, y, width, height) ctx.fill() - _write_centered_text(surface, x + width / 2, y + height / 2, used.item.id) + _write_centered_text(surface, x + width / 2, y + height / 2, + used.item.id + (' (r)' if used.rotate else '')) def _write_unused(surface, scale, x0, y0, unused): diff --git a/src_py/opcut/server.py b/src_py/opcut/server.py index 60b2623..0dd607d 100644 --- a/src_py/opcut/server.py +++ b/src_py/opcut/server.py @@ -24,26 +24,29 @@ async def run(addr, pem_path, ui_path): ssl_ctx = None app = aiohttp.web.Application() - app.router.add_route('GET', '/', - lambda req: aiohttp.web.HTTPFound('/index.html')) - app.router.add_route('POST', '/calculate', - functools.partial(_calculate_handler, executor)) - app.router.add_route('POST', '/generate_output', - functools.partial(_generate_output_handler, executor)) - app.router.add_static('/', ui_path) - app_handler = app.make_handler() - - srv = await asyncio.get_event_loop().create_server( - app_handler, host=addr.hostname, port=addr.port, ssl=ssl_ctx) + app.add_routes([ + aiohttp.web.get('/', lambda req: aiohttp.web.HTTPFound('/index.html')), + aiohttp.web.post( + '/calculate', + functools.partial(_calculate_handler, executor)), + aiohttp.web.post( + '/generate_output', + functools.partial(_generate_output_handler, executor)), + aiohttp.web.static('/', ui_path)]) + + runner = aiohttp.web.AppRunner(app) + await runner.setup() + site = aiohttp.web.TCPSite(runner, + host=addr.hostname, + port=addr.port, + ssl_context=ssl_ctx, + shutdown_timeout=0.1) + await site.start() with contextlib.suppress(asyncio.CancelledError): await asyncio.Future() - srv.close() - await srv.wait_closed() - await app.shutdown() - await app_handler.finish_connections(0.1) - await app.cleanup() + await runner.cleanup() async def _calculate_handler(executor, request): @@ -57,7 +60,7 @@ async def _calculate_handler(executor, request): result_json_data = common.result_to_json_data(result) except asyncio.CancelledError: raise - except Exception as e: + except Exception: result_json_data = None return aiohttp.web.json_response({'result': result_json_data}) @@ -75,7 +78,7 @@ async def _generate_output_handler(executor, request): output_json_data = base64.b64encode(output).decode('utf-8') except asyncio.CancelledError: raise - except Exception as e: + except Exception: output_json_data = None return aiohttp.web.json_response({'data': output_json_data}) |
