[OpenWrt-Devel] [PATCH v2] opkg: Extend 'opkg list' command to optionally display package size
Hannu Nyman
hannu.nyman at iki.fi
Wed Sep 16 04:09:43 EDT 2015
'opkg list' command only displays the available packages' name, version and
description. It would be useful to also see the approximate size of the
available package.
This patch extends "opkg list" command with "--size" to optionally show also
the *.ipk size.
* Default behaviour is to list the available packages as earlier:
"name - version - description"
* with "--size" the output of is "name - version - size - description".
Signed-off-by: Hannu Nyman <hannu.nyman at iki.fi>
---
Patch v2: bump opkg PKG_RELEASE and rebase
This patch superseeds https://patchwork.ozlabs.org/patch/512231/
Example:
root at OpenWrt:~# opkg list kr*
krb5-client - 1.13.1-1 - Kerberos 5 Client
krb5-libs - 1.13.1-1 - Kerberos 5 Shared Libraries
krb5-server - 1.13.1-1 - Kerberos 5 Server
root at OpenWrt:~# opkg list --size kr*
krb5-client - 1.13.1-1 - 37297 - Kerberos 5 Client
krb5-libs - 1.13.1-1 - 667427 - Kerberos 5 Shared Libraries
krb5-server - 1.13.1-1 - 122460 - Kerberos 5 Server
Example implementation that utilises this opkg change to show the
.ipk size to the user in GUI:
https://github.com/openwrt/luci/issues/19#issuecomment-136397807
Index: package/system/opkg/Makefile
===================================================================
--- package/system/opkg/Makefile (revision 46946)
+++ package/system/opkg/Makefile (working copy)
@@ -12,7 +12,7 @@
PKG_NAME:=opkg
PKG_REV:=9c97d5ecd795709c8584e972bfdf3aee3a5b846d
PKG_VERSION:=$(PKG_REV)
-PKG_RELEASE:=9
+PKG_RELEASE:=10
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=$(PKG_REV)
Index: package/system/opkg/patches/250-add-print-package-size.patch
===================================================================
--- package/system/opkg/patches/250-add-print-package-size.patch (revision 0)
+++ package/system/opkg/patches/250-add-print-package-size.patch (working copy)
@@ -0,0 +1,74 @@
+--- a/libopkg/opkg_conf.c
++++ b/libopkg/opkg_conf.c
+@@ -69,6 +69,7 @@ opkg_option_t options[] = {
+ { "proxy_passwd", OPKG_OPT_TYPE_STRING, &_conf.proxy_passwd },
+ { "proxy_user", OPKG_OPT_TYPE_STRING, &_conf.proxy_user },
+ { "query-all", OPKG_OPT_TYPE_BOOL, &_conf.query_all },
++ { "size", OPKG_OPT_TYPE_BOOL, &_conf.size },
+ { "tmp_dir", OPKG_OPT_TYPE_STRING, &_conf.tmp_dir },
+ { "verbosity", OPKG_OPT_TYPE_INT, &_conf.verbosity },
+ #if defined(HAVE_OPENSSL)
+--- a/libopkg/opkg_conf.h
++++ b/libopkg/opkg_conf.h
+@@ -88,6 +88,7 @@ struct opkg_conf
+ int query_all;
+ int verbosity;
+ int noaction;
++ int size;
+ int download_only;
+ char *cache;
+
+--- a/src/opkg-cl.c
++++ b/src/opkg-cl.c
+@@ -52,6 +52,7 @@ enum {
+ ARGS_OPT_AUTOREMOVE,
+ ARGS_OPT_CACHE,
+ ARGS_OPT_FORCE_SIGNATURE,
++ ARGS_OPT_SIZE,
+ };
+
+ static struct option long_options[] = {
+@@ -98,6 +99,7 @@ static struct option long_options[] = {
+ {"offline-root", 1, 0, 'o'},
+ {"add-arch", 1, 0, ARGS_OPT_ADD_ARCH},
+ {"add-dest", 1, 0, ARGS_OPT_ADD_DEST},
++ {"size", 0, 0, ARGS_OPT_SIZE},
+ {"test", 0, 0, ARGS_OPT_NOACTION},
+ {"tmp-dir", 1, 0, 't'},
+ {"tmp_dir", 1, 0, 't'},
+@@ -212,6 +214,9 @@ args_parse(int argc, char *argv[])
+ }
+ free(tuple);
+ break;
++ case ARGS_OPT_SIZE:
++ conf->size = 1;
++ break;
+ case ARGS_OPT_NOACTION:
+ conf->noaction = 1;
+ break;
+@@ -315,6 +320,7 @@ usage()
+ printf("\t--download-only No action -- download only\n");
+ printf("\t--nodeps Do not follow dependencies\n");
+ printf("\t--nocase Perform case insensitive pattern matching\n");
++ printf("\t--size Print package size when listing available packages\n");
+ printf("\t--force-removal-of-dependent-packages\n");
+ printf("\t Remove package and all dependencies\n");
+ printf("\t--autoremove Remove packages that were installed\n");
+--- a/libopkg/opkg_cmd.c
++++ b/libopkg/opkg_cmd.c
+@@ -47,10 +47,12 @@ static void
+ print_pkg(pkg_t *pkg)
+ {
+ char *version = pkg_version_str_alloc(pkg);
++ printf("%s - %s", pkg->name, version);
++ if (conf->size)
++ printf(" - %lu", pkg->size);
+ if (pkg->description)
+- printf("%s - %s - %s\n", pkg->name, version, pkg->description);
+- else
+- printf("%s - %s\n", pkg->name, version);
++ printf(" - %s", pkg->description);
++ printf("\n");
+ free(version);
+ }
+
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list