From a9d975389aaf5d79d738517b98161e375e757cba Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Mon, 18 Nov 2024 09:27:35 -0500 Subject: Break down indexer into independent source files * Generate test result output * Add helper function to manage changing file extensions --- src/cli/stasis_indexer/readmes.c | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/cli/stasis_indexer/readmes.c (limited to 'src/cli/stasis_indexer/readmes.c') diff --git a/src/cli/stasis_indexer/readmes.c b/src/cli/stasis_indexer/readmes.c new file mode 100644 index 0000000..75e97a9 --- /dev/null +++ b/src/cli/stasis_indexer/readmes.c @@ -0,0 +1,75 @@ +#include "core.h" +#include "readmes.h" + +int indexer_readmes(struct Delivery ctx[], const size_t nelem) { + struct Delivery **latest = NULL; + latest = get_latest_deliveries(ctx, nelem); + + char indexfile[PATH_MAX] = {0}; + sprintf(indexfile, "%s/README.md", ctx->storage.delivery_dir); + + if (!pushd(ctx->storage.delivery_dir)) { + FILE *indexfp = fopen(indexfile, "w+"); + if (!indexfp) { + fprintf(stderr, "Unable to open %s for writing\n", indexfile); + return -1; + } + struct StrList *archs = get_architectures(*latest, nelem); + struct StrList *platforms = get_platforms(*latest, nelem); + + fprintf(indexfp, "# %s-%s\n\n", ctx->meta.name, ctx->meta.version); + fprintf(indexfp, "## Current Release\n\n"); + for (size_t p = 0; p < strlist_count(platforms); p++) { + char *platform = strlist_item(platforms, p); + for (size_t a = 0; a < strlist_count(archs); a++) { + char *arch = strlist_item(archs, a); + int have_combo = 0; + for (size_t i = 0; i < nelem; i++) { + if (latest[i] && latest[i]->system.platform) { + if (strstr(latest[i]->system.platform[DELIVERY_PLATFORM_RELEASE], platform) && + strstr(latest[i]->system.arch, arch)) { + have_combo = 1; + } + } + } + if (!have_combo) { + continue; + } + fprintf(indexfp, "### %s-%s\n\n", platform, arch); + + fprintf(indexfp, "|Release|Info|Receipt|\n"); + fprintf(indexfp, "|:----:|:----:|:----:|\n"); + for (size_t i = 0; i < nelem; i++) { + char link_name[PATH_MAX]; + char readme_name[PATH_MAX]; + char conf_name[PATH_MAX]; + char conf_name_relative[PATH_MAX]; + if (!latest[i]) { + continue; + } + sprintf(link_name, "latest-py%s-%s-%s.yml", latest[i]->meta.python_compact, latest[i]->system.platform[DELIVERY_PLATFORM_RELEASE], latest[i]->system.arch); + sprintf(readme_name, "README-py%s-%s-%s.md", latest[i]->meta.python_compact, latest[i]->system.platform[DELIVERY_PLATFORM_RELEASE], latest[i]->system.arch); + sprintf(conf_name, "%s.ini", latest[i]->info.release_name); + sprintf(conf_name_relative, "../config/%s-rendered.ini", latest[i]->info.release_name); + if (strstr(link_name, platform) && strstr(link_name, arch)) { + fprintf(indexfp, "|[%s](%s)|[%s](%s)|[%s](%s)|\n", link_name, link_name, readme_name, readme_name, conf_name, conf_name_relative); + } + } + fprintf(indexfp, "\n"); + } + fprintf(indexfp, "\n"); + } + guard_strlist_free(&archs); + guard_strlist_free(&platforms); + fclose(indexfp); + popd(); + } else { + fprintf(stderr, "Unable to enter delivery directory: %s\n", ctx->storage.delivery_dir); + guard_free(latest); + return -1; + } + + // "latest" is an array of pointers to ctxs[]. Do not free the contents of the array. + guard_free(latest); + return 0; +} -- cgit From 0c18b5b15ed6e78cc27580518ae29f20ff23da65 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 6 Dec 2024 08:43:27 -0500 Subject: Fix pointers to Delivery struct * Dynamic allocation only. I'm completely fed up with "lost" addresses. --- src/cli/stasis_indexer/readmes.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src/cli/stasis_indexer/readmes.c') diff --git a/src/cli/stasis_indexer/readmes.c b/src/cli/stasis_indexer/readmes.c index 75e97a9..c98ecfc 100644 --- a/src/cli/stasis_indexer/readmes.c +++ b/src/cli/stasis_indexer/readmes.c @@ -2,7 +2,7 @@ #include "readmes.h" int indexer_readmes(struct Delivery ctx[], const size_t nelem) { - struct Delivery **latest = NULL; + struct Delivery *latest = NULL; latest = get_latest_deliveries(ctx, nelem); char indexfile[PATH_MAX] = {0}; @@ -14,8 +14,8 @@ int indexer_readmes(struct Delivery ctx[], const size_t nelem) { fprintf(stderr, "Unable to open %s for writing\n", indexfile); return -1; } - struct StrList *archs = get_architectures(*latest, nelem); - struct StrList *platforms = get_platforms(*latest, nelem); + struct StrList *archs = get_architectures(latest, nelem); + struct StrList *platforms = get_platforms(latest, nelem); fprintf(indexfp, "# %s-%s\n\n", ctx->meta.name, ctx->meta.version); fprintf(indexfp, "## Current Release\n\n"); @@ -25,9 +25,9 @@ int indexer_readmes(struct Delivery ctx[], const size_t nelem) { char *arch = strlist_item(archs, a); int have_combo = 0; for (size_t i = 0; i < nelem; i++) { - if (latest[i] && latest[i]->system.platform) { - if (strstr(latest[i]->system.platform[DELIVERY_PLATFORM_RELEASE], platform) && - strstr(latest[i]->system.arch, arch)) { + if (latest[i].system.platform) { + if (strstr(latest[i].system.platform[DELIVERY_PLATFORM_RELEASE], platform) && + strstr(latest[i].system.arch, arch)) { have_combo = 1; } } @@ -44,13 +44,13 @@ int indexer_readmes(struct Delivery ctx[], const size_t nelem) { char readme_name[PATH_MAX]; char conf_name[PATH_MAX]; char conf_name_relative[PATH_MAX]; - if (!latest[i]) { + if (!latest[i].meta.name) { continue; } - sprintf(link_name, "latest-py%s-%s-%s.yml", latest[i]->meta.python_compact, latest[i]->system.platform[DELIVERY_PLATFORM_RELEASE], latest[i]->system.arch); - sprintf(readme_name, "README-py%s-%s-%s.md", latest[i]->meta.python_compact, latest[i]->system.platform[DELIVERY_PLATFORM_RELEASE], latest[i]->system.arch); - sprintf(conf_name, "%s.ini", latest[i]->info.release_name); - sprintf(conf_name_relative, "../config/%s-rendered.ini", latest[i]->info.release_name); + sprintf(link_name, "latest-py%s-%s-%s.yml", latest[i].meta.python_compact, latest[i].system.platform[DELIVERY_PLATFORM_RELEASE], latest[i].system.arch); + sprintf(readme_name, "README-py%s-%s-%s.md", latest[i].meta.python_compact, latest[i].system.platform[DELIVERY_PLATFORM_RELEASE], latest[i].system.arch); + sprintf(conf_name, "%s.ini", latest[i].info.release_name); + sprintf(conf_name_relative, "../config/%s.ini", latest[i].info.release_name); if (strstr(link_name, platform) && strstr(link_name, arch)) { fprintf(indexfp, "|[%s](%s)|[%s](%s)|[%s](%s)|\n", link_name, link_name, readme_name, readme_name, conf_name, conf_name_relative); } -- cgit From 41c76e0ca3f34fd46235bac6c2c9eac0497b28fb Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Fri, 6 Dec 2024 08:44:39 -0500 Subject: Improved markdown output and presentation --- src/cli/stasis_indexer/readmes.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/cli/stasis_indexer/readmes.c') diff --git a/src/cli/stasis_indexer/readmes.c b/src/cli/stasis_indexer/readmes.c index c98ecfc..df3614e 100644 --- a/src/cli/stasis_indexer/readmes.c +++ b/src/cli/stasis_indexer/readmes.c @@ -36,9 +36,6 @@ int indexer_readmes(struct Delivery ctx[], const size_t nelem) { continue; } fprintf(indexfp, "### %s-%s\n\n", platform, arch); - - fprintf(indexfp, "|Release|Info|Receipt|\n"); - fprintf(indexfp, "|:----:|:----:|:----:|\n"); for (size_t i = 0; i < nelem; i++) { char link_name[PATH_MAX]; char readme_name[PATH_MAX]; @@ -52,13 +49,26 @@ int indexer_readmes(struct Delivery ctx[], const size_t nelem) { sprintf(conf_name, "%s.ini", latest[i].info.release_name); sprintf(conf_name_relative, "../config/%s.ini", latest[i].info.release_name); if (strstr(link_name, platform) && strstr(link_name, arch)) { - fprintf(indexfp, "|[%s](%s)|[%s](%s)|[%s](%s)|\n", link_name, link_name, readme_name, readme_name, conf_name, conf_name_relative); + fprintf(indexfp, "- Info: [README](%s)\n", readme_name); + fprintf(indexfp, "- Release: [Conda Environment YAML](%s)\n", link_name); + fprintf(indexfp, "- Receipt: [STASIS input file](%s)\n", conf_name_relative); } } fprintf(indexfp, "\n"); } fprintf(indexfp, "\n"); } + + fprintf(indexfp, "## Releases\n"); + for (size_t i = 0; ctx[i].meta.name != NULL; i++) { + struct Delivery *current = &ctx[i]; + fprintf(indexfp, "### %s\n", current->info.release_name); + fprintf(indexfp, "- Info: [README](README-%s.html)\n", current->info.release_name); + fprintf(indexfp, "- Release: [Conda Environment YAML](%s.yml)\n", current->info.release_name); + fprintf(indexfp, "- Receipt: [STASIS input file](%s.ini)\n", current->info.release_name); + } + fprintf(indexfp, "\n"); + guard_strlist_free(&archs); guard_strlist_free(&platforms); fclose(indexfp); -- cgit From b677e21d0b996f8aef760f4c8330712107dad217 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Sat, 7 Dec 2024 18:09:20 -0500 Subject: Show current release followed by all available releases * Include link to archived docker image (i.e. curl -L [..] | docker load) --- src/cli/stasis_indexer/readmes.c | 147 +++++++++++++++++++++++---------------- 1 file changed, 87 insertions(+), 60 deletions(-) (limited to 'src/cli/stasis_indexer/readmes.c') diff --git a/src/cli/stasis_indexer/readmes.c b/src/cli/stasis_indexer/readmes.c index df3614e..77b5178 100644 --- a/src/cli/stasis_indexer/readmes.c +++ b/src/cli/stasis_indexer/readmes.c @@ -2,84 +2,111 @@ #include "readmes.h" int indexer_readmes(struct Delivery ctx[], const size_t nelem) { - struct Delivery *latest = NULL; - latest = get_latest_deliveries(ctx, nelem); + struct Delivery *latest_deliveries = get_latest_deliveries(ctx, nelem); + if (!latest_deliveries) { + if (errno) { + return -1; + } + return 0; + } char indexfile[PATH_MAX] = {0}; sprintf(indexfile, "%s/README.md", ctx->storage.delivery_dir); - if (!pushd(ctx->storage.delivery_dir)) { - FILE *indexfp = fopen(indexfile, "w+"); - if (!indexfp) { - fprintf(stderr, "Unable to open %s for writing\n", indexfile); - return -1; - } - struct StrList *archs = get_architectures(latest, nelem); - struct StrList *platforms = get_platforms(latest, nelem); + FILE *indexfp = fopen(indexfile, "w+"); + if (!indexfp) { + fprintf(stderr, "Unable to open %s for writing\n", indexfile); + return -1; + } + struct StrList *archs = get_architectures(latest_deliveries, nelem); + struct StrList *platforms = get_platforms(latest_deliveries, nelem); - fprintf(indexfp, "# %s-%s\n\n", ctx->meta.name, ctx->meta.version); - fprintf(indexfp, "## Current Release\n\n"); - for (size_t p = 0; p < strlist_count(platforms); p++) { - char *platform = strlist_item(platforms, p); - for (size_t a = 0; a < strlist_count(archs); a++) { - char *arch = strlist_item(archs, a); - int have_combo = 0; - for (size_t i = 0; i < nelem; i++) { - if (latest[i].system.platform) { - if (strstr(latest[i].system.platform[DELIVERY_PLATFORM_RELEASE], platform) && - strstr(latest[i].system.arch, arch)) { - have_combo = 1; - } + fprintf(indexfp, "# %s-%s\n\n", ctx->meta.name, ctx->meta.version); + fprintf(indexfp, "## Current Release\n\n"); + for (size_t p = 0; p < strlist_count(platforms); p++) { + char *platform = strlist_item(platforms, p); + for (size_t a = 0; a < strlist_count(archs); a++) { + char *arch = strlist_item(archs, a); + int have_combo = 0; + for (size_t i = 0; i < nelem; i++) { + if (latest_deliveries[i].system.platform) { + if (strstr(latest_deliveries[i].system.platform[DELIVERY_PLATFORM_RELEASE], platform) && + strstr(latest_deliveries[i].system.arch, arch)) { + have_combo = 1; } } - if (!have_combo) { + } + if (!have_combo) { + continue; + } + fprintf(indexfp, "### %s-%s\n\n", platform, arch); + for (size_t i = 0; i < nelem; i++) { + char link_name[PATH_MAX] = {0}; + char readme_name[PATH_MAX] = {0}; + char conf_name[PATH_MAX] = {0}; + char conf_name_relative[PATH_MAX] = {0}; + if (!latest_deliveries[i].meta.name) { continue; } - fprintf(indexfp, "### %s-%s\n\n", platform, arch); - for (size_t i = 0; i < nelem; i++) { - char link_name[PATH_MAX]; - char readme_name[PATH_MAX]; - char conf_name[PATH_MAX]; - char conf_name_relative[PATH_MAX]; - if (!latest[i].meta.name) { - continue; - } - sprintf(link_name, "latest-py%s-%s-%s.yml", latest[i].meta.python_compact, latest[i].system.platform[DELIVERY_PLATFORM_RELEASE], latest[i].system.arch); - sprintf(readme_name, "README-py%s-%s-%s.md", latest[i].meta.python_compact, latest[i].system.platform[DELIVERY_PLATFORM_RELEASE], latest[i].system.arch); - sprintf(conf_name, "%s.ini", latest[i].info.release_name); - sprintf(conf_name_relative, "../config/%s.ini", latest[i].info.release_name); - if (strstr(link_name, platform) && strstr(link_name, arch)) { - fprintf(indexfp, "- Info: [README](%s)\n", readme_name); - fprintf(indexfp, "- Release: [Conda Environment YAML](%s)\n", link_name); - fprintf(indexfp, "- Receipt: [STASIS input file](%s)\n", conf_name_relative); + sprintf(link_name, "latest-py%s-%s-%s.yml", latest_deliveries[i].meta.python_compact, latest_deliveries[i].system.platform[DELIVERY_PLATFORM_RELEASE], latest_deliveries[i].system.arch); + sprintf(readme_name, "README-py%s-%s-%s.md", latest_deliveries[i].meta.python_compact, latest_deliveries[i].system.platform[DELIVERY_PLATFORM_RELEASE], latest_deliveries[i].system.arch); + sprintf(conf_name, "%s.ini", latest_deliveries[i].info.release_name); + sprintf(conf_name_relative, "../config/%s.ini", latest_deliveries[i].info.release_name); + if (strstr(link_name, platform) && strstr(link_name, arch)) { + fprintf(indexfp, "- Info: [README](%s)\n", readme_name); + fprintf(indexfp, "- Release: [Conda Environment YAML](%s)\n", link_name); + fprintf(indexfp, "- Receipt: [STASIS input file](%s)\n", conf_name_relative); + fprintf(indexfp, "- Docker: "); + struct StrList *docker_images = get_docker_images(&latest_deliveries[i], ""); + if (docker_images + && strlist_count(docker_images) + && !strcmp(latest_deliveries[i].system.platform[DELIVERY_PLATFORM_RELEASE], "linux")) { + fprintf(indexfp, "[Archive](../packages/docker/%s)\n", path_basename(strlist_item(docker_images, 0))); + guard_free(docker_images); + } else { + fprintf(indexfp, "N/A\n"); } } - fprintf(indexfp, "\n"); } fprintf(indexfp, "\n"); } + fprintf(indexfp, "\n"); + } - fprintf(indexfp, "## Releases\n"); - for (size_t i = 0; ctx[i].meta.name != NULL; i++) { - struct Delivery *current = &ctx[i]; - fprintf(indexfp, "### %s\n", current->info.release_name); - fprintf(indexfp, "- Info: [README](README-%s.html)\n", current->info.release_name); - fprintf(indexfp, "- Release: [Conda Environment YAML](%s.yml)\n", current->info.release_name); - fprintf(indexfp, "- Receipt: [STASIS input file](%s.ini)\n", current->info.release_name); + fprintf(indexfp, "## Releases\n"); + for (size_t i = 0; ctx[i].meta.name != NULL; i++) { + struct Delivery *current = &ctx[i]; + fprintf(indexfp, "### %s\n", current->info.release_name); + fprintf(indexfp, "- Info: [README](README-%s.html)\n", current->info.release_name); + fprintf(indexfp, "- Release: [Conda Environment YAML](%s.yml)\n", current->info.release_name); + fprintf(indexfp, "- Receipt: [STASIS input file](../config/%s.ini)\n", current->info.release_name); + fprintf(indexfp, "- Docker: \n"); + + char *pattern = NULL; + asprintf(&pattern, "*%s*", current->info.build_number); + if (!pattern) { + SYSERROR("%s", "Unable to allocate bytes for pattern"); + return -1; } - fprintf(indexfp, "\n"); - guard_strlist_free(&archs); - guard_strlist_free(&platforms); - fclose(indexfp); - popd(); - } else { - fprintf(stderr, "Unable to enter delivery directory: %s\n", ctx->storage.delivery_dir); - guard_free(latest); - return -1; + struct StrList *docker_images = get_docker_images(current, pattern); + if (docker_images + && strlist_count(docker_images) + && !strcmp(current->system.platform[DELIVERY_PLATFORM_RELEASE], "linux")) { + fprintf(indexfp, "[Archive](../packages/docker/%s)\n", path_basename(strlist_item(docker_images, 0))); + guard_free(docker_images); + } else { + fprintf(indexfp, "N/A\n"); + } + guard_free(pattern); } + fprintf(indexfp, "\n"); + + guard_strlist_free(&archs); + guard_strlist_free(&platforms); + fclose(indexfp); - // "latest" is an array of pointers to ctxs[]. Do not free the contents of the array. - guard_free(latest); + // "latest_deliveries" is an array of pointers to ctxs[]. Do not free the contents of the array. + guard_free(latest_deliveries); return 0; } -- cgit