kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit bf4361092c6df89910b528f5b5d3220aff3cf308
parent 9c337ded1e1716aba1d7bfc01268c790181e25f3
Author: Joris Vink <joris@coders.se>
Date:   Mon,  9 Apr 2018 13:05:38 +0200

Add pyko, not linked to build.

Diffstat:
pyko/.gitignore | 6++++++
pyko/Makefile | 19+++++++++++++++++++
pyko/README.md | 39+++++++++++++++++++++++++++++++++++++++
pyko/conf/build.conf | 17+++++++++++++++++
pyko/conf/pyko.conf | 1+
pyko/src/pyko.c | 37+++++++++++++++++++++++++++++++++++++
6 files changed, 119 insertions(+), 0 deletions(-)

diff --git a/pyko/.gitignore b/pyko/.gitignore @@ -0,0 +1,6 @@ +*.o +.flavor +.objs +pyko.so +assets.h +cert diff --git a/pyko/Makefile b/pyko/Makefile @@ -0,0 +1,19 @@ +# pyko Makefile + +BIN=pyko +PREFIX?=/usr/local +INSTALL_DIR=$(PREFIX)/bin + +KODEV?=../kodev/kodev + +build: + $(KODEV) build + +clean: + $(KODEV) clean + +install: + install -m 555 $(BIN) $(INSTALL_DIR)/$(BIN) + +uninstall: + rm -f $(INSTALL_DIR)/$(BIN) diff --git a/pyko/README.md b/pyko/README.md @@ -0,0 +1,39 @@ +About +----- +Pyko is a single binary kore build aimed at starting kore python applications +in a more easy and straight forward manner. + +Building +-------- +This kore application builds with PYTHON=1 and PGSQL=1 automatically. +See the kore README file on what dependencies are required for this. + +From the root kore directory run: + +``` + $ make -C kodev + $ make -C pyko + $ sudo make -C pyko install +``` + +App layout +---------- +Your python application directory must have the following layout: + +``` + app/ + kore.conf <- actual kore configuration + __init__.py <- usual python init stuff +``` + +Usage +----- +``` + $ pyko -frn python_app +``` + +``` + -f = foreground + -n = skip chroot + -r = skip privilege drop +``` diff --git a/pyko/conf/build.conf b/pyko/conf/build.conf @@ -0,0 +1,17 @@ +# pyko build config + +single_binary=yes +kore_source=../ +kore_flavor=PYTHON=1 PGSQL=1 + +cflags=-std=c99 -pedantic +cflags=-Wall -Wmissing-declarations -Wshadow +cflags=-Wstrict-prototypes -Wmissing-prototypes +cflags=-Wpointer-arith -Wcast-qual -Wsign-compare + +dev { + cflags=-g +} + +prod { +} diff --git a/pyko/conf/pyko.conf b/pyko/conf/pyko.conf @@ -0,0 +1 @@ +# pyko configuration diff --git a/pyko/src/pyko.c b/pyko/src/pyko.c @@ -0,0 +1,37 @@ +#include <sys/types.h> +#include <sys/stat.h> + +#include <kore/kore.h> + +#include <stdio.h> +#include <limits.h> + +void +kore_parent_configure(int argc, char **argv) +{ + struct stat st; + int len; + FILE *fp; + char config[PATH_MAX]; + + if (argc != 1) + fatal("Usage: pyko [python app]"); + + if (stat(argv[0], &st) == -1) + fatal("stat(%s): %s", argv[0], errno_s); + + if (!S_ISDIR(st.st_mode)) + fatal("python module directory required"); + + len = snprintf(config, sizeof(config), "%s/kore.conf", argv[0]); + if (len == -1 || (size_t)len >= sizeof(config)) + fatal("failed to create configuration path"); + + if ((fp = fopen(config, "r")) == NULL) + fatal("failed to open configuration '%s'", config); + + kore_module_load(argv[0], NULL, KORE_MODULE_PYTHON); + + /* kore_parse_config_file() will call fclose(). */ + kore_parse_config_file(fp); +}