commit fd53f48cece3c3500b5609861e7fad4fdd1dabf0
parent 5b0772b64699f810b98d3ce6a0007748a723885e
Author: Joris Vink <joris@coders.se>
Date: Mon, 9 Apr 2018 20:50:47 +0200
pyko: allow running without app argument.
If no app argument was given, assume we should use the cwd
and interpret "." as the cwd as well.
makes it easier to do things like:
$ pyko -frn
Diffstat:
1 file changed, 21 insertions(+), 9 deletions(-)
diff --git a/pyko/src/pyko.c b/pyko/src/pyko.c
@@ -21,6 +21,7 @@
#include <stdio.h>
#include <limits.h>
+#include <unistd.h>
void
kore_parent_configure(int argc, char **argv)
@@ -28,28 +29,39 @@ kore_parent_configure(int argc, char **argv)
struct stat st;
int len;
FILE *fp;
- char config[PATH_MAX];
+ char *module, pwd[PATH_MAX], config[PATH_MAX];
- if (argc != 1)
- fatal("Usage: pyko [python app]");
+ if (getcwd(pwd, sizeof(pwd)) == NULL)
+ fatal("getcwd: %s", errno_s);
- if (stat(argv[0], &st) == -1)
- fatal("stat(%s): %s", argv[0], errno_s);
+ if (argc == 0) {
+ module = &pwd[0];
+ } else if (argc == 1) {
+ if (!strcmp(argv[0], "."))
+ module = &pwd[0];
+ else
+ module = argv[0];
+ } else {
+ fatal("Usage: pyko [options] [kore python app]");
+ }
+
+ if (stat(module, &st) == -1)
+ fatal("stat(%s): %s", module, errno_s);
if (!S_ISDIR(st.st_mode))
fatal("python module directory required");
- len = snprintf(config, sizeof(config), "%s/kore.conf", argv[0]);
+ len = snprintf(config, sizeof(config), "%s/kore.conf", module);
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_module_load(module, NULL, KORE_MODULE_PYTHON);
- if (chdir(argv[0]) == -1)
- fatal("chdir(%s): %s", argv[0], errno_s);
+ if (chdir(module) == -1)
+ fatal("chdir(%s): %s", module, errno_s);
/* kore_parse_config_file() will call fclose(). */
kore_parse_config_file(fp);