From cc6125ac4c01c083ea30b3a3efeb980b25f9a8d4 Mon Sep 17 00:00:00 2001 From: ngn Date: Fri, 19 Jul 2024 00:28:55 +0300 Subject: [PATCH] new: basic info command --- locale/tr/LC_MESSAGES/pooler.po | 137 ++++++++++++++++++++++---------- src/cmd.h | 3 +- src/cmd/info.c | 115 +++++++++++++++++++++++++++ src/cmd/install.c | 1 - src/cmd/list.c | 11 +-- src/main.c | 11 +-- 6 files changed, 225 insertions(+), 53 deletions(-) create mode 100644 src/cmd/info.c diff --git a/locale/tr/LC_MESSAGES/pooler.po b/locale/tr/LC_MESSAGES/pooler.po index 54eeb97..cd0c63c 100644 --- a/locale/tr/LC_MESSAGES/pooler.po +++ b/locale/tr/LC_MESSAGES/pooler.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2024-07-18 20:09+0300\n" +"POT-Creation-Date: 2024-07-19 00:28+0300\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -72,154 +72,209 @@ msgstr "" msgid "Please answer with y/n" msgstr "" -#: src/main.c:71 +#: src/main.c:72 msgid "Failed to access the root directory, are you running as root?" msgstr "" -#: src/main.c:73 +#: src/main.c:74 #, fuzzy, c-format msgid "Bad root directory (%s): %s" msgstr "Havuz dizini kullanmak başarısız oldu: %s" -#: src/main.c:81 +#: src/main.c:82 #, c-format msgid "Bad datadir (%s): %s" msgstr "" -#: src/main.c:86 +#: src/main.c:87 #, c-format msgid "Bad tmpdir (%s): %s" msgstr "" -#: src/main.c:93 +#: src/main.c:94 #, fuzzy msgid "Failed to add pool " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/main.c:106 +#: src/main.c:107 msgid "Command not found: " msgstr "" -#: src/main.c:108 +#: src/main.c:109 #, c-format msgid "MatterLinux package manager (version %s)" msgstr "" -#: src/main.c:109 +#: src/main.c:110 msgid "Usage: " msgstr "" -#: src/main.c:111 +#: src/main.c:112 msgid "Here is a list of available commands:" msgstr "" -#: src/main.c:117 +#: src/main.c:118 msgid "To list different options, use commands with " msgstr "" -#: src/main.c:118 +#: src/main.c:119 msgid "Here is a list of available global options:" msgstr "" -#: src/main.c:121 src/main.c:122 src/cmd/install.c:23 src/cmd/install.c:24 -#: src/cmd/list.c:13 src/cmd/list.c:14 src/cmd/remove.c:17 src/cmd/remove.c:18 +#: src/main.c:122 src/main.c:123 src/cmd/info.c:14 src/cmd/info.c:15 +#: src/cmd/info.c:16 src/cmd/install.c:22 src/cmd/install.c:23 +#: src/cmd/list.c:10 src/cmd/list.c:11 src/cmd/remove.c:17 src/cmd/remove.c:18 #: src/cmd/update.c:23 #, c-format msgid " " msgstr "" -#: src/main.c:124 +#: src/main.c:125 msgid "" "Licensed under GPLv3, see https://www.gnu.org/licenses/ for more information" msgstr "" -#: src/cmd/install.c:22 +#: src/cmd/info.c:13 src/cmd/list.c:9 +msgid "Listing options for the list command:" +msgstr "" + +#: src/cmd/info.c:36 +msgid "Please specify only a single package name" +msgstr "" + +#: src/cmd/info.c:42 +#, fuzzy +msgid "Please specify a single package" +msgstr "Lütfen konfigürasyonda en az bir havuz belirtin" + +#: src/cmd/info.c:48 src/cmd/info.c:54 src/cmd/install.c:56 src/cmd/remove.c:42 +msgid "Package " +msgstr "" + +#: src/cmd/info.c:59 +#, fuzzy +msgid "Failed to get the changes file for " +msgstr "%s: paket listesini yüklemek başarısız oldu (%s)" + +#: src/cmd/info.c:91 +#, c-format +msgid "Name " +msgstr "" + +#: src/cmd/info.c:92 +#, c-format +msgid "Version " +msgstr "" + +#: src/cmd/info.c:93 +#, c-format +msgid "Desc " +msgstr "" + +#: src/cmd/info.c:94 +#, c-format +msgid "Size " +msgstr "" + +#: src/cmd/info.c:97 +#, c-format +msgid "Depends " +msgstr "" + +#: src/cmd/info.c:100 +#, c-format +msgid "Changes " +msgstr "" + +#: src/cmd/info.c:104 src/cmd/info.c:105 +#, c-format +msgid "Installed " +msgstr "" + +#: src/cmd/info.c:107 src/cmd/info.c:108 +#, c-format +msgid "Up-to-date " +msgstr "" + +#: src/cmd/install.c:21 msgid "Listing options for the install command:" msgstr "" -#: src/cmd/install.c:29 src/cmd/update.c:28 +#: src/cmd/install.c:28 src/cmd/update.c:28 msgid "There are no avaliable pools, have you synced yet?" msgstr "" -#: src/cmd/install.c:49 src/cmd/remove.c:44 +#: src/cmd/install.c:48 src/cmd/remove.c:44 #, fuzzy msgid "Failed to find " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/install.c:57 src/cmd/remove.c:42 -msgid "Package " -msgstr "" - -#: src/cmd/install.c:63 +#: src/cmd/install.c:62 #, fuzzy msgid "Failed to resolve " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/install.c:69 +#: src/cmd/install.c:68 msgid "Nothing to do (no packages to install)" msgstr "" -#: src/cmd/install.c:78 src/cmd/remove.c:64 src/cmd/update.c:48 +#: src/cmd/install.c:77 src/cmd/remove.c:64 src/cmd/update.c:48 #, c-format msgid "Following %d package will be " msgstr "" -#: src/cmd/install.c:80 src/cmd/remove.c:66 src/cmd/update.c:50 +#: src/cmd/install.c:79 src/cmd/remove.c:66 src/cmd/update.c:50 #, c-format msgid "Following %d packages will be " msgstr "" -#: src/cmd/install.c:86 src/cmd/remove.c:73 +#: src/cmd/install.c:85 src/cmd/remove.c:73 msgid "Total of " msgstr "" -#: src/cmd/install.c:87 src/cmd/remove.c:74 src/cmd/update.c:56 +#: src/cmd/install.c:86 src/cmd/remove.c:74 src/cmd/update.c:56 msgid "Continue?" msgstr "" -#: src/cmd/install.c:88 src/cmd/remove.c:75 src/cmd/update.c:57 +#: src/cmd/install.c:87 src/cmd/remove.c:75 src/cmd/update.c:57 msgid "Operation cancelled" msgstr "" -#: src/cmd/install.c:94 src/cmd/update.c:67 +#: src/cmd/install.c:93 src/cmd/update.c:67 #, c-format msgid "(%d/%d) Downloading " msgstr "" -#: src/cmd/install.c:100 src/cmd/update.c:72 +#: src/cmd/install.c:99 src/cmd/update.c:72 #, fuzzy msgid "Failed to download " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/install.c:109 src/cmd/update.c:85 +#: src/cmd/install.c:108 src/cmd/update.c:85 #, c-format msgid "(%d/%d) Installing " msgstr "" -#: src/cmd/install.c:115 src/cmd/update.c:90 +#: src/cmd/install.c:114 src/cmd/update.c:90 #, fuzzy msgid "Failed to install " msgstr "Havuzları sekronize etmek başarısız oldu: %s" -#: src/cmd/install.c:121 +#: src/cmd/install.c:120 #, c-format msgid "Installed %d package" msgstr "" -#: src/cmd/install.c:121 +#: src/cmd/install.c:120 #, c-format msgid "Installed all of the %d packages" msgstr "" -#: src/cmd/list.c:12 -msgid "Listing options for the list command:" -msgstr "" - -#: src/cmd/list.c:23 +#: src/cmd/list.c:24 msgid "There no installed packages" msgstr "" -#: src/cmd/list.c:28 +#: src/cmd/list.c:29 msgid "Listing " msgstr "" diff --git a/src/cmd.h b/src/cmd.h index c115745..4af9ada 100644 --- a/src/cmd.h +++ b/src/cmd.h @@ -13,8 +13,9 @@ typedef struct cmd { cmd_func_t func; } cmd_t; +bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args); bool cmd_sync(lm_ctx_t *ctx, config_t *config, args_t *args); +bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args); bool cmd_install(lm_ctx_t *ctx, config_t *config, args_t *args); bool cmd_remove(lm_ctx_t *ctx, config_t *config, args_t *args); bool cmd_update(lm_ctx_t *ctx, config_t *config, args_t *args); -bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args); diff --git a/src/cmd/info.c b/src/cmd/info.c new file mode 100644 index 0000000..342f0d7 --- /dev/null +++ b/src/cmd/info.c @@ -0,0 +1,115 @@ +#include +#include +#include +#include +#include + +#include "../util.h" +#include "../cmd.h" +#include "../log.h" + +bool cmd_info(lm_ctx_t *ctx, config_t *config, args_t *args){ + if(args_get_bool(args, "help")){ + info(_("Listing options for the list command:")); + printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n")); + printf(_(" "FG_BOLD"--changes"FG_RESET":\topen the changes file for the package\n")); + printf(_(" "FG_BOLD"--database"FG_RESET":\tsearch the database instead of the pools\n")); + return true; + } + + if(!args_get_bool(args, "database")) + lm_ctx_sync(ctx, false, NULL, NULL); + + char *name = NULL, *changes = NULL; + lm_pkg_t pkg, *pkgp = &pkg; + + for(size_t i = 0; i < args->count; i++){ + if(NULL != args->list[i].name || eq(args->list[i].value, "info")) + continue; + + if(NULL == name){ + name = args->list[i].value; + continue; + } + + if(!args_get_bool(args, "grep")) + error(_("Please specify only a single package name")); + return false; + } + + if(NULL == name){ + if(!args_get_bool(args, "grep")) + error(_("Please specify a single package")); + return false; + } + + if(args_get_bool(args, "database") && !lm_ctx_database_find(ctx, &pkg, name, NULL)){ + if(!args_get_bool(args, "grep") && LM_ERR_DbSqlNotFound == lm_error()) + error(_("Package "FG_BOLD"%s"FG_RESET" not found"), name); + return false; + } + + else if(!args_get_bool(args, "database") && (pkgp = lm_ctx_pool_find(ctx, name, NULL)) == NULL){ + if(!args_get_bool(args, "grep") && LM_ERR_PkgNotFound == lm_error()) + error(_("Package "FG_BOLD"%s"FG_RESET" not found"), name); + return false; + } + + if((changes = lm_ctx_database_changes(ctx, pkgp)) == NULL && LM_ERR_DbChangesNotExists != lm_error()){ + error(_("Failed to get the changes file for "FG_BOLD"%s"FG_RESET"_"FG_BOLD FG_GREEN"%s"FG_RESET": %s"), pkgp->name, pkgp->version, lm_strerror()); + return false; + } + + // TODO: open the changes file with the preferred editor if --changes is set + + char depends[lm_package_depend_strlen(pkgp)+1]; + lm_package_depend_tostr(pkgp, depends); + + if(args_get_bool(args, "grep")){ + printf("NAME:%s\n", pkgp->name); + printf("VERSION:%s\n", pkgp->version); + printf("DESC:%s\n", pkgp->desc); + printf("SIZE:%lu\n", pkgp->size); + + if(lm_package_depend_count(pkgp) > 0) + printf("DEPENDS:%s\n", depends); + + if(NULL != changes) + printf("CHANGES:%s\n", changes); + + if(!args_get_bool(args, "database")){ + printf("INSTALLED:%d\n", lm_ctx_database_is_installed(ctx, pkgp, false)); + printf("UPTODATE:%d\n", lm_ctx_database_is_installed(ctx, pkgp, true)); + } + + goto end; + } + + char ssize[LONGSTR_MAX+1]; + size_to_human(ssize, pkgp->size); + + printf(_(FG_BOLD"Name "FG_BLUE"=>"FG_RESET" %s\n"), pkgp->name); + printf(_(FG_BOLD"Version "FG_BLUE"=>"FG_RESET" %s\n"), pkgp->version); + printf(_(FG_BOLD"Desc "FG_BLUE"=>"FG_RESET" %s\n"), pkgp->desc); + printf(_(FG_BOLD"Size "FG_BLUE"=>"FG_RESET" %s\n"), ssize); + + if(lm_package_depend_count(pkgp) > 0) + printf(_(FG_BOLD"Depends "FG_BLUE"=>"FG_RESET" %s\n"), depends); + + if(NULL != changes) + printf(_(FG_BOLD"Changes "FG_BLUE"=>"FG_RESET" %s\n"), changes); + + if(!args_get_bool(args, "database")){ + printf(lm_ctx_database_is_installed(ctx, pkgp, false) ? + _(FG_BOLD"Installed "FG_BLUE"=>"FG_RESET" "FG_GREEN"yes"FG_RESET"\n") : + _(FG_BOLD"Installed "FG_BLUE"=>"FG_RESET" "FG_RED"no"FG_RESET"\n")); + printf(lm_ctx_database_is_installed(ctx, pkgp, true) ? + _(FG_BOLD"Up-to-date "FG_BLUE"=>"FG_RESET" "FG_GREEN"yes"FG_RESET"\n") : + _(FG_BOLD"Up-to-date "FG_BLUE"=>"FG_RESET" "FG_RED"no"FG_RESET"\n")); + } + +end: + if(args_get_bool(args, "database")) + lm_package_free(pkgp); + return true; +} diff --git a/src/cmd/install.c b/src/cmd/install.c index 13a2f41..bff06a9 100644 --- a/src/cmd/install.c +++ b/src/cmd/install.c @@ -1,5 +1,4 @@ #include -#include #include #include "../util.h" diff --git a/src/cmd/list.c b/src/cmd/list.c index a10df0f..daa09a9 100644 --- a/src/cmd/list.c +++ b/src/cmd/list.c @@ -5,9 +5,6 @@ #include "../log.h" bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){ - ssize_t count = 0; - lm_pkg_t pkg; - if(args_get_bool(args, "help")){ info(_("Listing options for the list command:")); printf(_(" "FG_BOLD"--grep"FG_RESET":\tmakes the output \"grepable\"\n")); @@ -15,12 +12,16 @@ bool cmd_list(lm_ctx_t *ctx, config_t *config, args_t *args){ return true; } + ssize_t count = 0; + lm_pkg_t pkg; + while(lm_ctx_database_next(ctx, &pkg)) count++; lm_ctx_database_next_free(ctx, &pkg); - if(count <= 0 && !args_get_bool(args, "grep")){ - info(_("There no installed packages")); + if(count <= 0){ + if(!args_get_bool(args, "grep")) + info(_("There no installed packages")); return true; } diff --git a/src/main.c b/src/main.c index 211bdfb..8e0addf 100644 --- a/src/main.c +++ b/src/main.c @@ -37,11 +37,12 @@ int main(int argc, char *argv[]) { cmd_t commands[] = { - {.name = "list", .desc = "list all the installed packages", .func = cmd_list }, - {.name = "sync", .desc = "update the pool info and package lists", .func = cmd_sync }, - {.name = "install", .desc = "install package(s) from remote pools", .func = cmd_install}, - {.name = "remove", .desc = "remove installed package(s)", .func = cmd_remove }, - {.name = "update", .desc = "update installed package(s)", .func = cmd_update }, + {.name = "info", .desc = "show information about a single package", .func = cmd_info }, + {.name = "list", .desc = "list all the installed packages", .func = cmd_list }, + {.name = "sync", .desc = "update the pool info and package lists", .func = cmd_sync }, + {.name = "install", .desc = "install package(s) from remote pools", .func = cmd_install}, + {.name = "remove", .desc = "remove installed package(s)", .func = cmd_remove }, + {.name = "update", .desc = "update installed package(s)", .func = cmd_update }, }; char *config_file = NULL, *root_dir = NULL;