Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Add the capability to query abstract metadata for packages via pkg {info,search,query,rquery}
Matthew Seaman committed 13 years ago
commit 820e840bfd608a3f1c47dd5d8214f9233d628943
parent c5360e5
10 files changed +132 -55
modified pkg/info.c
@@ -50,8 +50,8 @@ usage_info(void)
{
	fprintf(stderr, "usage: pkg info <pkg-name>\n");
	fprintf(stderr, "       pkg info -a\n");
-
	fprintf(stderr, "       pkg info [-bBDdefgiIklOqRrsx] <pkg-name>\n");
-
	fprintf(stderr, "       pkg info [-bBDdfIlqRrs] -F <pkg-file>\n\n");
+
	fprintf(stderr, "       pkg info [-AbBDdefgiIklOqRrsx] <pkg-name>\n");
+
	fprintf(stderr, "       pkg info [-AbBDdfIlqRrs] -F <pkg-file>\n\n");
	fprintf(stderr, "For more information see 'pkg help info'.\n");
}

@@ -83,11 +83,14 @@ exec_info(int argc, char **argv)
	bool origin_search = false;

	/* TODO: exclusive opts ? */
-
	while ((ch = getopt(argc, argv, "aDegixEIdrklbBsqopOfF:R")) != -1) {
+
	while ((ch = getopt(argc, argv, "aADegixEIdrklbBsqopOfF:R")) != -1) {
		switch (ch) {
		case 'a':
			match = MATCH_ALL;
			break;
+
		case 'A':
+
			opt |= INFO_ABSTRACT_METADATA;
+
			break;
		case 'O':
			origin_search = true;  /* only for ports compat */
			break;
modified pkg/pkg-info.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd March 3, 2013
+
.Dd March 31, 2013
.Dt PKG-INFO 8
.Os
.Sh NAME
@@ -27,10 +27,10 @@
.Nm
.Fl a
.Nm
-
.Op Fl bBDdefgiIklOqRrsx
+
.Op Fl AbBDdefgiIklOqRrsx
.Ar <pkg-name>
.Nm
-
.Op Fl bBDdfIlqRrs
+
.Op Fl AbBDdfIlqRrs
.Fl F Ar <pkg-file>
.Sh DESCRIPTION
.Nm
@@ -41,6 +41,8 @@ The following options are supported by
.Bl -tag -width F1
.It Fl a
Display all installed packages.
+
.It Fl A
+
Display any abstract metadata added to the package.
.It Fl f
Display full information about the packages matching
.Ar <pkg-name> .
modified pkg/pkg-query.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd March 22, 2013
+
.Dd March 31, 2013
.Dt PKG-QUERY 8
.Os
.Sh NAME
@@ -106,7 +106,7 @@ Returns 1 if the matched package is locked against modification or deletion, 0 o
message contain in the matched package
.It Cm \&%t
Timestamp that the package was installed
-
.It Cm \&%? Ns Op drCFODLUGBb
+
.It Cm \&%? Ns Op drCFODLUGBbA
Returns 0 if the list is empty and 1 if the list has information to display
.Bl -tag -width indent
.It Cm d
@@ -131,8 +131,10 @@ for groups
for required shared libraries
.It Cm b
for provided shared libraries
+
.It Cm A
+
for abstract metadata
.El
-
.It Cm \&%# Ns Op drCFODLUGBb
+
.It Cm \&%# Ns Op drCFODLUGBbA
Returns the number of element in the list
.Bl -tag -width indent
.It Cm d
@@ -159,6 +161,8 @@ for shared
for required shared libraries
.It Cm b
for provided shared libraries
+
.It Cm A
+
for abstract metadata
.El
.El
.Ss Multiline patterns:
@@ -205,6 +209,13 @@ Expands to the list of groups needed by the matched package.
Expands to the list of shared libraries used by programs from the matched package.
.It Cm \&%b
Expands to the list of shared libraries provided by the matched package.
+
.It Cm \&A Ns Op kv
+
Expands to the list of abstract metadata items for the matched package,
+
where
+
.Cm k
+
stands for the item key, and
+
.Cm v
+
stands for the item value.
.El
.Sh EVALUATION FORMAT
Packages can be selected by using expressions comparing
@@ -247,7 +258,7 @@ Message of the package (type string)
Timestamp that the package was installed (type integer)
.It Cm \&%i
Additionnal information about the package (type string)
-
.It Cm \&%# Ns Op drCFODLUGBb
+
.It Cm \&%# Ns Op drCFODLUGBbA
Number of elements in the list of information (type integer).
See
.Cm %?
modified pkg/pkg-rquery.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd March 22, 2013
+
.Dd March 31, 2013
.Dt PKG-RQUERY 8
.Os
.Sh NAME
@@ -105,7 +105,7 @@ is in bytes, and
is in human readable format.
.It Cm \&%M
message contain in the matched package
-
.It Cm \&%? Ns Op drCOLBb
+
.It Cm \&%? Ns Op drCOLBbA
Returns 0 if the list is empty and 1 if the list has information to display
.Bl -tag -width indent
.It Cm d
@@ -122,7 +122,9 @@ for licenses
for required shared libraries
.It Cm b
for provided shared libraries
-
.It Cm \&%# Ns Op drCOLBb
+
.It Cm A
+
for abstract metadata
+
.It Cm \&%# Ns Op drCOLBbA
Returns the number of elements in the list
.Bl -tag -width indent
.It Cm d
@@ -139,6 +141,8 @@ for licenses
for required shared libraries
.It Cm b
for provided shared libraries
+
.It Cm A
+
for abstract metadata
.El
.El
.El
@@ -174,6 +178,13 @@ Expands to the list of license(s) for the matched package.
Expands to the list of shared libraries used by programs from the matched package.
.It Cm \&%b
Expands to the list of shared libraries provided by the matched package.
+
.It Cm \&%A Ns Op kv
+
Expands to the list of abstract metadata items associated with the matched
+
package, where
+
.Cm k
+
stands for the item key, and
+
.Cm v
+
stands for the item value.
.El
.Sh EVALUATION FORMAT
.Ss Variables
@@ -198,7 +209,7 @@ Flatsize of the package (type integer)
Automatic status of the package (type integer)
.It Cm \&%M
Message of the package (type string)
-
.It Cm \&%# Ns Op drCOLBb
+
.It Cm \&%# Ns Op drCOLBbA
Number of elements in the list of information (type integer).
See
.Cm %?
modified pkg/pkg-search.8
@@ -15,7 +15,7 @@
.\"     @(#)pkg.8
.\" $FreeBSD$
.\"
-
.Dd March 9, 2013
+
.Dd March 31, 2013
.Dt PKG-SEARCH 8
.Os
.Sh NAME
@@ -233,6 +233,9 @@ or
.Fl "L description"
options, then each output field will be tagged with the field name.
.Bl -tag -width 2n
+
.It Sy abstract-metadata
+
Freeform arbitrary text in key-value format that can be incorporated in
+
any package. 
.It Sy arch
The architecture string indicating what OS version and CPU architecture
the package is suitable for.
@@ -284,6 +287,7 @@ Show a standard set of fields, equivalent to a combination of the
.Sy options ,
.Sy shared-libs-required ,
.Sy shared-libs-provided ,
+
.Sy abstract-metadata ,
.Sy size ,
.Sy pkg-size
and
modified pkg/pkgcli.h
@@ -182,21 +182,22 @@ void usage_ssh(void);
#define INFO_OPTIONS		(1<<10)
#define INFO_SHLIBS_REQUIRED	(1<<11)
#define INFO_SHLIBS_PROVIDED	(1<<12)
-
#define INFO_FLATSIZE		(1<<13)
-
#define INFO_PKGSIZE		(1<<14)
-
#define INFO_DESCR		(1<<15)
+
#define INFO_ABSTRACT_METADATA	(1<<13)
+
#define INFO_FLATSIZE		(1<<14)
+
#define INFO_PKGSIZE		(1<<15)
+
#define INFO_DESCR		(1<<16)

/* Other fields not part of the Full output */
-
#define INFO_MESSAGE		(1<<16)
-
#define INFO_DEPS		(1<<17)
-
#define INFO_RDEPS		(1<<18)
-
#define INFO_FILES		(1<<19)
-
#define INFO_DIRS		(1<<20)
-
#define INFO_USERS		(1<<21)
-
#define INFO_GROUPS		(1<<22)
-
#define INFO_ARCH		(1<<23)
-
#define INFO_REPOURL		(1<<24)
-
#define INFO_LOCKED		(1<<25)
+
#define INFO_MESSAGE		(1<<17)
+
#define INFO_DEPS		(1<<18)
+
#define INFO_RDEPS		(1<<19)
+
#define INFO_FILES		(1<<20)
+
#define INFO_DIRS		(1<<21)
+
#define INFO_USERS		(1<<22)
+
#define INFO_GROUPS		(1<<23)
+
#define INFO_ARCH		(1<<24)
+
#define INFO_REPOURL		(1<<25)
+
#define INFO_LOCKED		(1<<26)

#define INFO_LASTFIELD	INFO_LOCKED
#define INFO_ALL	(((INFO_LASTFIELD) << 1) - 1)
@@ -214,13 +215,14 @@ void usage_ssh(void);
			 INFO_REPOSITORY|INFO_CATEGORIES|INFO_LICENSES|	 \
			 INFO_MAINTAINER|INFO_WWW|INFO_COMMENT|		 \
			 INFO_OPTIONS|INFO_SHLIBS_REQUIRED|		 \
-
			 INFO_SHLIBS_PROVIDED|INFO_FLATSIZE|		 \
-
			 INFO_PKGSIZE|INFO_DESCR)
+
			 INFO_SHLIBS_PROVIDED|INFO_ABSTRACT_METADATA|    \
+
			 INFO_FLATSIZE|INFO_PKGSIZE|INFO_DESCR)

/* Everything that can take more than one line to print */
#define INFO_MULTILINE	(INFO_OPTIONS|INFO_SHLIBS_REQUIRED|	       \
-
			 INFO_SHLIBS_PROVIDED|INFO_DESCR|INFO_MESSAGE| \
-
			 INFO_DEPS|INFO_RDEPS|INFO_FILES|INFO_DIRS)
+
			 INFO_SHLIBS_PROVIDED|INFO_ABSTRACT_METADATA|  \
+
			 INFO_DESCR|INFO_MESSAGE|INFO_DEPS|INFO_RDEPS| \
+
			 INFO_FILES|INFO_DIRS)

bool query_yesno(const char *msg, ...);
bool query_tty_yesno(const char *msg, ...);
modified pkg/query.c
@@ -54,8 +54,9 @@ static struct query_flags accepted_query_flags[] = {
	{ 'G', "",		1, PKG_LOAD_GROUPS },
	{ 'B', "",		1, PKG_LOAD_SHLIBS_REQUIRED },
	{ 'b', "",		1, PKG_LOAD_SHLIBS_PROVIDED },
-
	{ '?', "drCFODLUGBb",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
-
	{ '#', "drCFODLUGBb",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
+
	{ 'A', "kv",            1, PKG_LOAD_ABSTRACT_METADATA },
+
	{ '?', "drCFODLUGBbA",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
+
	{ '#', "drCFODLUGBbA",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
	{ 's', "hb",		0, PKG_LOAD_BASIC },
	{ 'n', "",		0, PKG_LOAD_BASIC },
	{ 'v', "",		0, PKG_LOAD_BASIC },
@@ -198,6 +199,9 @@ format_str(struct pkg *pkg, struct sbuf *dest, const char *qstr, void *data)
				case 'b':
					sbuf_printf(dest, "%d", pkg_list_count(pkg, PKG_SHLIBS_PROVIDED) > 0);
					break;
+
				case 'A':
+
					sbuf_printf(dest, "%d", pkg_list_count(pkg, PKG_ABSTRACT_METADATA) > 0);
+
					break;
				}
				break;
			case '#':
@@ -236,6 +240,9 @@ format_str(struct pkg *pkg, struct sbuf *dest, const char *qstr, void *data)
				case 'b':
					sbuf_printf(dest, "%d", pkg_list_count(pkg, PKG_SHLIBS_PROVIDED));
					break;
+
				case 'A':
+
					sbuf_printf(dest, "%d", pkg_list_count(pkg, PKG_ABSTRACT_METADATA));
+
					break;
				}
				break;
			case 'l':
@@ -303,6 +310,13 @@ format_str(struct pkg *pkg, struct sbuf *dest, const char *qstr, void *data)
			case 'b':
				sbuf_cat(dest, pkg_shlib_name((struct pkg_shlib *)data));
				break;
+
			case 'A':
+
				qstr++;
+
				if (qstr[0] == 'k')
+
					sbuf_cat(dest, pkg_abstract_key((struct pkg_abstract *)data));
+
				else if (qstr[0] == 'v')
+
					sbuf_cat(dest, pkg_abstract_value((struct pkg_abstract *)data));
+
				break;
			case 'M':
				pkg_get(pkg, PKG_MESSAGE, &tmp);
				if (tmp != NULL)
@@ -358,6 +372,7 @@ print_query(struct pkg *pkg, char *qstr, char multiline)
	struct pkg_user *user = NULL;
	struct pkg_group *group = NULL;
	struct pkg_shlib *shlib = NULL;
+
	struct pkg_abstract *abstract = NULL;

	switch (multiline) {
	case 'd':
@@ -426,6 +441,12 @@ print_query(struct pkg *pkg, char *qstr, char multiline)
			printf("%s\n", sbuf_data(output));
		}
		break;
+
	case 'A':
+
		while (pkg_abstract_metadata(pkg, &abstract) == EPKG_OK) {
+
			format_str(pkg, output, qstr, abstract);
+
			printf("%s\n", sbuf_data(output));
+
		}
+
		break;
	default:
		format_str(pkg, output, qstr, dep);
		printf("%s\n", sbuf_data(output));
@@ -566,6 +587,9 @@ format_sql_condition(const char *str, struct sbuf *sqlcond, bool for_remote)
						case 'b':
							sbuf_printf(sqlcond, "(SELECT COUNT(*) FROM %spkg_shlibs_provided AS d WHERE d.package_id=p.id)", dbstr);
							break;
+
						case 'A':
+
							sbuf_printf(sqlcond, "(SELECT COUNT(*) FROM %spkg_abstract AS d WHERE d.package_id=p.id)", dbstr);
+
							break;
						default:
							goto bad_option;
					}
modified pkg/rquery.c
@@ -50,8 +50,9 @@ static struct query_flags accepted_rquery_flags[] = {
	{ 'L', "",		1, PKG_LOAD_LICENSES },
	{ 'B', "",		1, PKG_LOAD_SHLIBS_REQUIRED },
	{ 'b', "",		1, PKG_LOAD_SHLIBS_PROVIDED },
-
	{ '?', "drCOLBb",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
-
	{ '#', "drCOLBb",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
+
	{ 'A', "kv",		1, PKG_LOAD_ABSTRACT_METADATA },
+
	{ '?', "drCOLBbA",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
+
	{ '#', "drCOLBbA",	1, PKG_LOAD_BASIC },	/* dbflags handled in analyse_query_string() */
	{ 's', "hb",		0, PKG_LOAD_BASIC },
	{ 'n', "",		0, PKG_LOAD_BASIC },
	{ 'e', "",		0, PKG_LOAD_BASIC },
modified pkg/search.c
@@ -53,6 +53,7 @@ static const cliopt search_label[] = {
};

static const cliopt modifiers[] = {
+
	{ "abstract-metadata",    'A'  },
	{ "arch",                 'a'  },
	{ "categories",           'C'  },
	{ "comment",              'c'  },
@@ -138,6 +139,9 @@ modifier_opt(const char *optionarg)

	/* output modifiers */
	switch(match_optarg(modifiers, optionarg)) {
+
	case 'A':
+
		opt = INFO_ABSTRACT_METADATA;
+
		break;
	case 'a':
		opt = INFO_ARCH;
		break;
modified pkg/utils.c
@@ -2,7 +2,7 @@
 * Copyright (c) 2011-2012 Baptiste Daroussin <bapt@FreeBSD.org>
 * Copyright (c) 2011-2012 Julien Laffaye <jlaffaye@FreeBSD.org>
 * Copyright (c) 2011-2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
-
 * Copyright (c) 2012 Matthew Seaman <matthew@FreeBSD.org>
+
 * Copyright (c) 2012-2013 Matthew Seaman <matthew@FreeBSD.org>
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, with or without
@@ -183,6 +183,8 @@ info_flags(unsigned int opt)
		flags |= PKG_LOAD_SHLIBS_REQUIRED;
	if (opt & INFO_SHLIBS_PROVIDED)
		flags |= PKG_LOAD_SHLIBS_PROVIDED;
+
	if (opt & INFO_ABSTRACT_METADATA)
+
		flags |= PKG_LOAD_ABSTRACT_METADATA;
	if (opt & INFO_DEPS)
		flags |= PKG_LOAD_DEPS;
	if (opt & INFO_RDEPS)
@@ -196,15 +198,17 @@ info_flags(unsigned int opt)
	if (opt & INFO_GROUPS)
		flags |= PKG_LOAD_GROUPS;
	if (opt & INFO_RAW) {
-
		flags |= PKG_LOAD_CATEGORIES      |
-
			 PKG_LOAD_LICENSES        |
-
			 PKG_LOAD_OPTIONS         |
-
			 PKG_LOAD_SHLIBS_REQUIRED |
-
			 PKG_LOAD_DEPS            |
-
			 PKG_LOAD_FILES           |
-
			 PKG_LOAD_DIRS            |
-
			 PKG_LOAD_USERS           |
-
			 PKG_LOAD_GROUPS          |
+
		flags |= PKG_LOAD_CATEGORIES        |
+
			 PKG_LOAD_LICENSES          |
+
			 PKG_LOAD_OPTIONS           |
+
			 PKG_LOAD_SHLIBS_REQUIRED   |
+
			 PKG_LOAD_SHLIBS_PROVIDED   |
+
			 PKG_LOAD_ABSTRACT_METADATA |
+
			 PKG_LOAD_DEPS              |
+
			 PKG_LOAD_FILES             |
+
			 PKG_LOAD_DIRS              |
+
			 PKG_LOAD_USERS             |
+
			 PKG_LOAD_GROUPS            |
			 PKG_LOAD_SCRIPTS;
	}

@@ -214,15 +218,16 @@ info_flags(unsigned int opt)
void
print_info(struct pkg * const pkg, unsigned int options)
{
-
	struct pkg_category *cat    = NULL;
-
	struct pkg_dep	    *dep    = NULL;
-
	struct pkg_dir	    *dir    = NULL;
-
	struct pkg_file	    *file   = NULL;
-
	struct pkg_group    *group  = NULL;
-
	struct pkg_license  *lic    = NULL;
-
	struct pkg_option   *option = NULL;
-
	struct pkg_shlib    *shlib  = NULL;
-
	struct pkg_user	    *user   = NULL;
+
	struct pkg_category *cat      = NULL;
+
	struct pkg_dep	    *dep      = NULL;
+
	struct pkg_dir	    *dir      = NULL;
+
	struct pkg_file	    *file     = NULL;
+
	struct pkg_group    *group    = NULL;
+
	struct pkg_license  *lic      = NULL;
+
	struct pkg_option   *option   = NULL;
+
	struct pkg_shlib    *shlib    = NULL;
+
	struct pkg_abstract *abstract = NULL;
+
	struct pkg_user	    *user     = NULL;
	bool multirepos_enabled = false;
	bool print_tag = false;
	bool show_locks = false;
@@ -432,6 +437,16 @@ print_info(struct pkg * const pkg, unsigned int options)
					printf("%s%s\n", tab, pkg_shlib_name(shlib));
			}
			break;
+
		case INFO_ABSTRACT_METADATA:
+
			if (pkg_list_count(pkg, PKG_ABSTRACT_METADATA) > 0) {
+
				if (print_tag)
+
					printf("%-15s:\n", "Abstract Metadata");
+
				while (pkg_abstract_metadata(pkg, &abstract) == EPKG_OK)
+
					printf("%s%-15s: %s\n", tab,
+
					       pkg_abstract_key(abstract),
+
					       pkg_abstract_value(abstract));
+
			}
+
			break;
		case INFO_FLATSIZE:
			if (pkg_type(pkg) == PKG_INSTALLED ||
			    pkg_type(pkg) == PKG_FILE)