Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Convert stats plugin to new interface
Baptiste Daroussin committed 13 years ago
commit ef5c44f63a4761cdd9aaffcb433901a631d92db5
parent f071f93
9 files changed +163 -201
modified plugins/Makefile
@@ -1,3 +1,4 @@
SUBDIR+=	command-mystats
+
SUBDIR+=	stats

.include <bsd.subdir.mk>
deleted plugins/pkg-plugin-stats/Makefile
@@ -1,18 +0,0 @@
-
.include <bsd.own.mk>
-

-
LIB=		pkg-plugin-stats
-
INCS=		stats.h
-
#WARNS=		6
-
PREFIX?=	/usr/local
-
LIBDIR=		${PREFIX}/lib
-
INCLUDEDIR=	${PREFIX}/include
-
SHLIB_MAJOR=	0
-

-
SRCS=		stats.c
-

-
CFLAGS+=	-std=c99 -fPIC -shared
-
CFLAGS+=	-I${INCLUDEDIR}
-

-
DEBUG_FLAGS+=  -g -O0
-

-
.include <bsd.lib.mk>
deleted plugins/pkg-plugin-stats/README.md
@@ -1,43 +0,0 @@
-
## General Information
-

-
The *pkg-plugin-stats* plugin is used for displaying package stats during:
-

-
* pre-install
-
* post-install
-
* pre-deinstall
-
* post-deinstall
-

-
## How to build the plugin?
-

-
In order to build the plugin enter into the plugin's directory and run make(1), e.g.:
-

-
	$ cd /path/to/pkg-plugins-stats
-
	$ make
-
	
-
Once the plugin is built you can install it using the following command:
-

-
	$ make install 
-
	
-
The plugin will be installed as a shared library in ${PREFIX}/lib/libpkg-plugin-stats.so
-

-
## Configuring the plugin
-

-
In order to configure the plugin simply copy the *stats.conf* file to the pkgng plugins directory,
-
which by default is set to */usr/local/etc/pkg/plugins*, unless you've specified it elsewhere by 
-
using the *PKG\_PLUGINS\_DIR* option.
-

-
	$ cp /path/to/pkg-plugins-stats/stats.conf /usr/local/etc/pkg/plugins/
-
	
-
## Testing the plugin
-

-
To test the plugin, first check that it is recongnized and
-
loaded by pkgng by executing the `pkg plugins` command:
-

-
	$ pkg plugins
-
	NAME       DESC                                VERSION    LOADED    
-
	stats      Plugin for displaying package stats 1.0        YES     
-

-
If the plugin shows up correctly then you are good to go!
-

-
Now go ahead and install/deintall a package and see it in action! :)
-

deleted plugins/pkg-plugin-stats/stats.c
@@ -1,97 +0,0 @@
-
/*
-
 * Copyright (c) 2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
-
 * All rights reserved.
-
 * 
-
 * Redistribution and use in source and binary forms, with or without
-
 * modification, are permitted provided that the following conditions
-
 * are met:
-
 * 1. Redistributions of source code must retain the above copyright
-
 *    notice, this list of conditions and the following disclaimer
-
 *    in this position and unchanged.
-
 * 2. Redistributions in binary form must reproduce the above copyright
-
 *    notice, this list of conditions and the following disclaimer in the
-
 *    documentation and/or other materials provided with the distribution.
-
 * 
-
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
-
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
-
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 */
-

-
#include <assert.h>
-
#include <stdio.h>
-
#include <unistd.h>
-
#include <inttypes.h>
-
#include <libutil.h>
-

-
#include <pkg.h>
-

-
#include "stats.h"
-

-
#define PLUGIN_NAME "stats"
-

-
int
-
pkg_plugins_init_stats(void)
-
{
-
	/*
-
	 * Hook into the library and provide package stats for the following actions:
-
	 *
-
	 * - pre-install 
-
	 * - post-install
-
	 * - pre-deinstall
-
	 * - post-deinstall
-
	 */
-
	
-
	if (pkg_plugins_hook(PLUGIN_NAME, PKG_PLUGINS_HOOK_PRE_INSTALL, &plugin_stats_callback) != EPKG_OK) {
-
		fprintf(stderr, "Plugin '%s' failed to hook into the library\n", PLUGIN_NAME);
-
		return (EPKG_FATAL);
-
	}
-

-
	if (pkg_plugins_hook(PLUGIN_NAME, PKG_PLUGINS_HOOK_POST_INSTALL, &plugin_stats_callback) != EPKG_OK) {
-
		fprintf(stderr, "Plugin '%s' failed to hook into the library\n", PLUGIN_NAME);
-
		return (EPKG_FATAL);
-
	}
-
	if (pkg_plugins_hook(PLUGIN_NAME, PKG_PLUGINS_HOOK_PRE_DEINSTALL, &plugin_stats_callback) != EPKG_OK) {
-
		fprintf(stderr, "Plugin '%s' failed to hook into the library\n", PLUGIN_NAME);
-
		return (EPKG_FATAL);
-
	}
-
	
-
	if (pkg_plugins_hook(PLUGIN_NAME, PKG_PLUGINS_HOOK_POST_DEINSTALL, &plugin_stats_callback) != EPKG_OK) {
-
		fprintf(stderr, "Plugin '%s' failed to hook into the library\n", PLUGIN_NAME);
-
		return (EPKG_FATAL);
-
	}
-
	
-
	return (EPKG_OK);
-
}
-

-
int
-
pkg_plugins_shutdown_template(void)
-
{
-
	/* nothing to be done here */
-

-
	return (EPKG_OK);
-
}
-

-
int
-
plugin_stats_callback(void *data, struct pkgdb *db)
-
{
-
        int64_t flatsize = 0;
-
        char size[7];
-

-
	assert(db != NULL);
-
	/* assert(data != NULL); */
-

-
	flatsize = pkgdb_stats(db, PKG_STATS_LOCAL_SIZE);
-
	humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0);
-
	printf(">>> Installed packages : %" PRId64 " | Disk space: %s <<<\n",
-
	       pkgdb_stats(db, PKG_STATS_LOCAL_COUNT),
-
	       size);
-

-
	return (EPKG_OK);
-
}
deleted plugins/pkg-plugin-stats/stats.conf
@@ -1,6 +0,0 @@
-
# Configuration file for pkg-plugin-stats
-
enabled=YES
-
name=stats
-
description=Plugin for displaying package stats
-
version=1.0
-
plugin=/usr/local/lib/libpkg-plugin-stats.so
deleted plugins/pkg-plugin-stats/stats.h
@@ -1,37 +0,0 @@
-
/*
-
 * Copyright (c) 2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
-
 * All rights reserved.
-
 * 
-
 * Redistribution and use in source and binary forms, with or without
-
 * modification, are permitted provided that the following conditions
-
 * are met:
-
 * 1. Redistributions of source code must retain the above copyright
-
 *    notice, this list of conditions and the following disclaimer
-
 *    in this position and unchanged.
-
 * 2. Redistributions in binary form must reproduce the above copyright
-
 *    notice, this list of conditions and the following disclaimer in the
-
 *    documentation and/or other materials provided with the distribution.
-
 * 
-
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
-
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
-
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
-
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
-
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
-
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 */
-

-
#ifndef _PKG_PLUGINS_STATS_H
-
#define _PKG_PLUGINS_STATS_H
-

-
/* callback functions */
-
int plugin_stats_callback(void *data, struct pkgdb *db);
-

-
/* plugin init and shutdown functions */
-
int pkg_plugins_init_stats(void);
-
int pkg_plugins_shutdown_stats(void);
-

-
#endif /* !_PKG_PLUGINS_STATS_H */
added plugins/stats/Makefile
@@ -0,0 +1,16 @@
+
.include <bsd.own.mk>
+

+
PREFIX?=	/usr/local
+
LIBDIR=		${PREFIX}/lib/pkg/
+
SHLIB_DIR?=	${LIBDIR}/
+
SHLIB_NAME?=	${PLUGIN_NAME}.so
+

+
PLUGIN_NAME=	stats
+
SRCS=		stats.c
+

+
CFLAGS+=	-I${.CURDIR}/../../libpkg
+

+
beforeinstall:
+
	${INSTALL} -d ${LIBDIR}
+

+
.include <bsd.lib.mk>
added plugins/stats/README.md
@@ -0,0 +1,43 @@
+
## General Information
+

+
The *pkg-plugin-stats* plugin is used for displaying package stats during:
+

+
* pre-install
+
* post-install
+
* pre-deinstall
+
* post-deinstall
+

+
## How to build the plugin?
+

+
In order to build the plugin enter into the plugin's directory and run make(1), e.g.:
+

+
	$ cd /path/to/pkg-plugins-stats
+
	$ make
+
	
+
Once the plugin is built you can install it using the following command:
+

+
	$ make install 
+
	
+
The plugin will be installed as a shared library in ${PREFIX}/lib/libpkg-plugin-stats.so
+

+
## Configuring the plugin
+

+
In order to configure the plugin simply copy the *stats.conf* file to the pkgng plugins directory,
+
which by default is set to */usr/local/etc/pkg/plugins*, unless you've specified it elsewhere by 
+
using the *PKG\_PLUGINS\_DIR* option.
+

+
	$ cp /path/to/pkg-plugins-stats/stats.conf /usr/local/etc/pkg/plugins/
+
	
+
## Testing the plugin
+

+
To test the plugin, first check that it is recongnized and
+
loaded by pkgng by executing the `pkg plugins` command:
+

+
	$ pkg plugins
+
	NAME       DESC                                VERSION    LOADED    
+
	stats      Plugin for displaying package stats 1.0        YES     
+

+
If the plugin shows up correctly then you are good to go!
+

+
Now go ahead and install/deintall a package and see it in action! :)
+

added plugins/stats/stats.c
@@ -0,0 +1,103 @@
+
/*
+
 * Copyright (c) 2012 Marin Atanasov Nikolov <dnaeon@gmail.com>
+
 * All rights reserved.
+
 * 
+
 * Redistribution and use in source and binary forms, with or without
+
 * modification, are permitted provided that the following conditions
+
 * are met:
+
 * 1. Redistributions of source code must retain the above copyright
+
 *    notice, this list of conditions and the following disclaimer
+
 *    in this position and unchanged.
+
 * 2. Redistributions in binary form must reproduce the above copyright
+
 *    notice, this list of conditions and the following disclaimer in the
+
 *    documentation and/or other materials provided with the distribution.
+
 * 
+
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
+
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
+
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
 */
+

+
#include <assert.h>
+
#include <stdio.h>
+
#include <unistd.h>
+
#include <inttypes.h>
+
#include <libutil.h>
+

+
#include <pkg.h>
+

+
#define PLUGIN_NAME "stats"
+

+
static char name[] = "stats";
+
static char version[] = "1.0.0";
+
static char description[] = "Plugin for displaying package stats";
+
static int plugin_stats_callback(void *data, struct pkgdb *db);
+

+
int
+
init(struct pkg_plugin *p)
+
{
+
	/*
+
	 * Hook into the library and provide package stats for the following actions:
+
	 *
+
	 * - pre-install 
+
	 * - post-install
+
	 * - pre-deinstall
+
	 * - post-deinstall
+
	 */
+
	pkg_plugin_set(p, PKG_PLUGIN_NAME, name);
+
	pkg_plugin_set(p, PKG_PLUGIN_DESC, description);
+
	pkg_plugin_set(p, PKG_PLUGIN_VERSION, version);
+

+
	if (pkg_plugins_hook(PLUGIN_NAME, PKG_PLUGIN_HOOK_PRE_INSTALL, &plugin_stats_callback) != EPKG_OK) {
+
		fprintf(stderr, "Plugin '%s' failed to hook into the library\n", PLUGIN_NAME);
+
		return (EPKG_FATAL);
+
	}
+

+
	if (pkg_plugins_hook(PLUGIN_NAME, PKG_PLUGIN_HOOK_POST_INSTALL, &plugin_stats_callback) != EPKG_OK) {
+
		fprintf(stderr, "Plugin '%s' failed to hook into the library\n", PLUGIN_NAME);
+
		return (EPKG_FATAL);
+
	}
+
	if (pkg_plugins_hook(PLUGIN_NAME, PKG_PLUGIN_HOOK_PRE_DEINSTALL, &plugin_stats_callback) != EPKG_OK) {
+
		fprintf(stderr, "Plugin '%s' failed to hook into the library\n", PLUGIN_NAME);
+
		return (EPKG_FATAL);
+
	}
+
	
+
	if (pkg_plugins_hook(PLUGIN_NAME, PKG_PLUGIN_HOOK_POST_DEINSTALL, &plugin_stats_callback) != EPKG_OK) {
+
		fprintf(stderr, "Plugin '%s' failed to hook into the library\n", PLUGIN_NAME);
+
		return (EPKG_FATAL);
+
	}
+
	
+
	return (EPKG_OK);
+
}
+

+
int
+
shutdown(struct pkg_plugin *p __unused)
+
{
+
	/* nothing to be done here */
+

+
	return (EPKG_OK);
+
}
+

+
int
+
plugin_stats_callback(void *data, struct pkgdb *db)
+
{
+
        int64_t flatsize = 0;
+
        char size[7];
+

+
	assert(db != NULL);
+
	/* assert(data != NULL); */
+

+
	flatsize = pkgdb_stats(db, PKG_STATS_LOCAL_SIZE);
+
	humanize_number(size, sizeof(flatsize), flatsize, "B", HN_AUTOSCALE, 0);
+
	printf(">>> Installed packages : %" PRId64 " | Disk space: %s <<<\n",
+
	       pkgdb_stats(db, PKG_STATS_LOCAL_COUNT),
+
	       size);
+

+
	return (EPKG_OK);
+
}