Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 22 Jun 2013 15:20:05 GMT
From:      mattbw@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r253357 - soc2013/mattbw/dummy
Message-ID:  <201306221520.r5MFK5OJ022708@socsvn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mattbw
Date: Sat Jun 22 15:20:04 2013
New Revision: 253357
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=253357

Log:
  adds untested group support; some of the groups may be a bit contentious but are temporary for now.

Added:
  soc2013/mattbw/dummy/groups.c
  soc2013/mattbw/dummy/groups.h
Modified:
  soc2013/mattbw/dummy/Makefile
  soc2013/mattbw/dummy/get-details.c

Modified: soc2013/mattbw/dummy/Makefile
==============================================================================
--- soc2013/mattbw/dummy/Makefile	Sat Jun 22 13:11:27 2013	(r253356)
+++ soc2013/mattbw/dummy/Makefile	Sat Jun 22 15:20:04 2013	(r253357)
@@ -2,7 +2,7 @@
 
 LIB=		pk_backend_pkgng
 SHLIB_MAJOR=	1
-SRCS=		pk-backend-pkgng.c get-details.c
+SRCS=		pk-backend-pkgng.c get-details.c groups.c
 
 USE_PK_PKGCONF=	0
 

Modified: soc2013/mattbw/dummy/get-details.c
==============================================================================
--- soc2013/mattbw/dummy/get-details.c	Sat Jun 22 13:11:27 2013	(r253356)
+++ soc2013/mattbw/dummy/get-details.c	Sat Jun 22 15:20:04 2013	(r253357)
@@ -24,6 +24,8 @@
 #include "pk-backend.h"
 #include "pkg.h"
 
+#include "groups.h"
+
 /*
  * Checks two strings with strcmp and emits TRUE if they match. If either
  * string is NULL, emit TRUE as well (this is so that missing PackageID
@@ -67,6 +69,7 @@
 			const char     *data;
 			const char     *description;
 			const char     *name;
+			const char     *origin;
 			const char     *reponame;
 			const char     *version;
 			const char     *www;
@@ -76,11 +79,12 @@
 			pkg_get(match,
 				PKG_ARCH, &arch,
 				PKG_DESC, &description,
+				PKG_FLATSIZE, &flatsize,
 				PKG_NAME, &name,
+				PKG_ORIGIN, &origin,
 				PKG_REPONAME, &reponame,
 				PKG_VERSION, &version,
-				PKG_WWW, &www,
-				PKG_FLATSIZE, &size);
+				PKG_WWW, &www);
 
 			switch (pkg_type(match)) {
 			case PKG_FILE:
@@ -113,7 +117,7 @@
 				pk_backend_details(backend,
 						   new_id,
 						   NULL,
-						   PK_GROUP_ENUM_PROGRAMMING,
+						   group_from_origin(origin),
 						   description,
 						   www,
 						   flatsize);
@@ -122,6 +126,7 @@
 			}
 		}
 	} while (err == EPKG_OK && found == FALSE);
+	pkg_free(match);
 
 	return found;
 }

Added: soc2013/mattbw/dummy/groups.c
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/mattbw/dummy/groups.c	Sat Jun 22 15:20:04 2013	(r253357)
@@ -0,0 +1,145 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw@FreeBSD.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdlib.h> /* NULL */
+#include <string.h> /* strdup */
+
+#include "glib.h" /* g_strcmp0 */
+#include "pk-backend.h" /* PkGroupEnum, PK_* */
+
+struct group_mapping {
+	const char *dir;
+	PkGroupEnum group;
+};
+
+/* Mappings between ports directories (as in the first part of PKG_ORIGIN) and
+ * PackageKit enums.
+ *
+ * Some of these mappings are a bit iffy, peer review would be greatly
+ * appreciated.
+ */ 
+static struct group_mapping group_mappings[] = {
+	{"accessibility", PK_GROUP_ENUM_ACCESSIBILITY},
+	{"arabic", PK_GROUP_ENUM_LOCALIZATION},
+	{"archivers", PK_GROUP_ENUM_ACCESSORIES},
+	{"astro", PK_GROUP_ENUM_SCIENCE},
+	{"audio", PK_GROUP_ENUM_MULTIMEDIA},
+	{"benchmarks", PK_GROUP_ENUM_PROGRAMMING},
+	{"biology", PK_GROUP_ENUM_SCIENCE},
+	{"cad", PK_GROUP_ENUM_SCIENCE}, /* dubious */
+	{"chinese", PK_GROUP_ENUM_LOCALIZATION},
+	{"comms", PK_GROUP_ENUM_COMMUNICATION},
+	{"converters", PK_GROUP_ENUM_ACCESSORIES}, /* dubious */
+	{"databases", PK_GROUP_ENUM_SERVERS}, /* dubious */
+	{"deskutils", PK_GROUP_ENUM_ACCESSORIES},
+	{"devel", PK_GROUP_ENUM_PROGRAMMING},
+	{"distfiles", PK_GROUP_ENUM_OTHER}, /* ?? */
+	{"dns", PK_GROUP_ENUM_NETWORK},
+	{"editors", PK_GROUP_ENUM_OFFICE}, /* dubious */
+	{"emulators", PK_GROUP_ENUM_OTHER}, /* ?? */
+	{"finance", PK_GROUP_ENUM_OFFICE}, /* dubious */
+	{"french", PK_GROUP_ENUM_LOCALIZATION},
+	{"ftp", PK_GROUP_ENUM_NETWORK},
+	{"games", PK_GROUP_ENUM_GAMES},
+	{"german", PK_GROUP_ENUM_LOCALIZATION},
+	{"graphics", PK_GROUP_ENUM_GRAPHICS},
+	{"hebrew", PK_GROUP_ENUM_LOCALIZATION},
+	{"hungarian", PK_GROUP_ENUM_LOCALIZATION},
+	{"irc", PK_GROUP_ENUM_COMMUNICATION},
+	{"japanese", PK_GROUP_ENUM_LOCALIZATION},
+	{"java", PK_GROUP_ENUM_PROGRAMMING},
+	{"korean", PK_GROUP_ENUM_LOCALIZATION},
+	{"lang", PK_GROUP_ENUM_PROGRAMMING},
+	{"mail", PK_GROUP_ENUM_COMMUNICATION},
+	{"math", PK_GROUP_ENUM_SCIENCE},
+	{"misc", PK_GROUP_ENUM_OTHER},
+	{"multimedia", PK_GROUP_ENUM_MULTIMEDIA},
+	{"net", PK_GROUP_ENUM_NETWORK},
+	{"net-im", PK_GROUP_ENUM_COMMUNICATION},
+	{"net-mgmt", PK_GROUP_ENUM_NETWORK},
+	{"net-p2p", PK_GROUP_ENUM_NETWORK}, /* possibly COMMUNICATION */
+	{"news", PK_GROUP_ENUM_COMMUNICATION}, /* ?? */
+	{"packages", PK_GROUP_ENUM_OTHER}, /* ?? */
+	{"palm", PK_GROUP_ENUM_OTHER},
+	{"polish", PK_GROUP_ENUM_LOCALIZATION},
+	{"ports-mgmt", PK_GROUP_ENUM_ADMIN_TOOLS}, /* dubious? */
+	{"portuguese", PK_GROUP_ENUM_LOCALIZATION},
+	{"print", PK_GROUP_ENUM_OFFICE}, /* dubious */
+	{"russian", PK_GROUP_ENUM_LOCALIZATION},
+	{"science", PK_GROUP_ENUM_SCIENCE},
+	{"security", PK_GROUP_ENUM_SECURITY},
+	{"shells", PK_GROUP_ENUM_ACCESSORIES}, /* dubious */
+	{"sysutils", PK_GROUP_ENUM_ADMIN_TOOLS},
+	{"textproc", PK_GROUP_ENUM_PUBLISHING}, /* dubious */
+	{"ukrainian", PK_GROUP_ENUM_LOCALIZATION},
+	{"vietnamese", PK_GROUP_ENUM_LOCALIZATION},
+	{"www", PK_GROUP_ENUM_NETWORK}, /* could be COMMUNICATION?  prob. not */
+	/* Some of the X directories could be better classified possibly */
+	{"x11", PK_GROUP_ENUM_DESKTOP_OTHER},
+	{"x11-clocks", PK_GROUP_ENUM_DESKTOP_OTHER},
+	{"x11-drivers", PK_GROUP_ENUM_DESKTOP_OTHER},
+	{"x11-fm", PK_GROUP_ENUM_DESKTOP_OTHER},
+	{"x11-fonts", PK_GROUP_ENUM_FONTS},
+	{"x11-servers", PK_GROUP_ENUM_DESKTOP_OTHER},
+	{"x11-themes", PK_GROUP_ENUM_DESKTOP_OTHER},
+	{"x11-toolkits", PK_GROUP_ENUM_DESKTOP_OTHER},
+	{"x11-wm", PK_GROUP_ENUM_DESKTOP_OTHER},
+	/* Default (for new/unspecified ports directories */
+	{NULL, PK_GROUP_ENUM_UNKNOWN}
+};
+
+/* Maps from port/origin directories to PackageKit groups. */
+PkGroupEnum
+group_from_port_dir(const char *port_dir)
+{
+	int i;
+
+	i = 0;
+	while (group_mappings[i].dir != NULL &&
+			g_strcmp0(group_mappings[i].dir, port_dir) != 0)
+		i++;
+	return group_mappings[i].group;
+}	
+
+/* Maps from package origins to PackageKit groups. */
+PkGroupEnum
+group_from_origin(const char *origin)
+{
+	char *dir;
+	int i;
+	PkGroupEnum group;
+
+	/* Find the separation between dir and port name */
+	for (i = 0; origin[i] != '/' && origin[i] != '\0'; i++)
+		;
+
+	/* Is this a valid origin? If not, we want the default group */
+	if (origin[i] == '\0')
+		dir = NULL;
+	else
+		dir = strndup(origin, i);
+
+	group = group_from_port_dir(dir);
+
+	if (dir)
+		free(dir);
+
+	return group;
+}

Added: soc2013/mattbw/dummy/groups.h
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ soc2013/mattbw/dummy/groups.h	Sat Jun 22 15:20:04 2013	(r253357)
@@ -0,0 +1,34 @@
+/*-
+ * Copyright (C) 2013 Matt Windsor <mattbw@FreeBSD.org>
+ *
+ * Licensed under the GNU General Public License Version 2
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef _PKGNG_BACKEND_GROUPS_H_
+#define _PKGNG_BACKEND_GROUPS_H_
+
+#include "pk-backend.h"
+
+PkGroupEnum group_from_port_dir(const char *port_dir);
+
+PkGroupEnum group_from_origin(const char *origin);
+
+#endif /* _PKGNG_BACKEND_GROUPS_H_ */
+
+
+
+



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201306221520.r5MFK5OJ022708>