r4418 - in trunk/src/target/opkg: . libopkg tests
thomas at docs.openmoko.org
thomas at docs.openmoko.org
Fri May 9 12:52:44 CEST 2008
Author: thomas
Date: 2008-05-09 12:52:43 +0200 (Fri, 09 May 2008)
New Revision: 4418
Modified:
trunk/src/target/opkg/configure.ac
trunk/src/target/opkg/libopkg/opkg.c
trunk/src/target/opkg/libopkg/opkg.h
trunk/src/target/opkg/tests/libopkg_test.c
Log:
opkg: implement opkg_find_package()
Modified: trunk/src/target/opkg/configure.ac
===================================================================
--- trunk/src/target/opkg/configure.ac 2008-05-08 20:28:53 UTC (rev 4417)
+++ trunk/src/target/opkg/configure.ac 2008-05-09 10:52:43 UTC (rev 4418)
@@ -1,6 +1,6 @@
# Process this file with autoconf to produce a configure script
AC_INIT(libopkg/libopkg.c)
-AM_INIT_AUTOMAKE([opkg], [0.1.2])
+AM_INIT_AUTOMAKE([opkg], [0.1.3])
AM_CONFIG_HEADER(libopkg/config.h)
AC_CANONICAL_HOST
Modified: trunk/src/target/opkg/libopkg/opkg.c
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.c 2008-05-08 20:28:53 UTC (rev 4417)
+++ trunk/src/target/opkg/libopkg/opkg.c 2008-05-09 10:52:43 UTC (rev 4418)
@@ -45,11 +45,33 @@
__FILE__, __LINE__, __PRETTY_FUNCTION__, # expr); abort (); }
#define progress(d, p) d.percentage = p; if (progress_callback) progress_callback (opkg, &d, user_data);
-#define OLD_PKG_TO_NEW(pkg) opkg_package_new_with_values (pkg->name, pkg->version, pkg->architecture, pkg->description, pkg->tags, pkg->url, (pkg->size ? atoi (pkg->size) : 0), (pkg->state_status == SS_INSTALLED));
+#define SSTRCMP(x,y) (x && y) ? strcmp (x, y) : 0
/** Private Functions ***/
+static opkg_package_t*
+old_pkg_to_new (pkg_t *old)
+{
+ opkg_package_t *new;
+ new = opkg_package_new ();
+
+#define sstrdup(x) (x) ? strdup (x) : NULL;
+
+ new->name = sstrdup (old->name);
+ new->version = pkg_version_str_alloc (old);
+ new->architecture = sstrdup (old->architecture);
+ new->repository = sstrdup (old->src->name);
+ new->description = sstrdup (old->description);
+ new->tags = sstrdup (old->tags);
+ new->url = sstrdup (old->url);
+
+ new->size = (old->size) ? atoi (old->size) : 0;
+ new->installed = (old->state_status == SS_INSTALLED);
+
+ return new;
+}
+
static int
opkg_configure_packages(opkg_conf_t *conf, char *pkg_name)
{
@@ -143,28 +165,6 @@
return p;
}
-opkg_package_t *
-opkg_package_new_with_values (const char *name, const char *version,
- const char *arch, const char *desc, const char *tags, const char *url, int size, int installed)
-{
- opkg_package_t *package;
- package = opkg_package_new ();
-
-#define sstrdup(x) (x) ? strdup (x) : NULL;
-
- package->name = sstrdup (name);
- package->version = sstrdup (version);
- package->architecture = sstrdup (arch);
- package->description = sstrdup (desc);
- package->tags = sstrdup (tags);
- package->url = sstrdup (url);
-
- package->size = size;
- package->installed = (installed != 0);
-
- return package;
-}
-
void
opkg_package_free (opkg_package_t *p)
{
@@ -376,7 +376,7 @@
return 1;
}
pdata.action = OPKG_INSTALL;
- pdata.package = OLD_PKG_TO_NEW (new);
+ pdata.package = old_pkg_to_new (new);
progress (pdata, 0);
@@ -441,7 +441,7 @@
}
pdata.action = OPKG_REMOVE;
- pdata.package = OLD_PKG_TO_NEW (pkg);
+ pdata.package = old_pkg_to_new (pkg);
progress (pdata, 0);
@@ -515,7 +515,7 @@
}
pdata.action = OPKG_INSTALL;
- pdata.package = OLD_PKG_TO_NEW (pkg);
+ pdata.package = old_pkg_to_new (pkg);
progress (pdata, 0);
opkg_upgrade_pkg (opkg->conf, pkg);
@@ -550,7 +550,7 @@
{
pkg = installed->pkgs[i];
- pdata.package = OLD_PKG_TO_NEW (pkg);
+ pdata.package = old_pkg_to_new (pkg);
progress (pdata, 99 * i / installed->len);
opkg_package_free (pdata.package);
@@ -759,7 +759,7 @@
pkg = all->pkgs[i];
- package = OLD_PKG_TO_NEW (pkg);
+ package = old_pkg_to_new (pkg);
callback (opkg, package, user_data);
}
@@ -800,7 +800,7 @@
if (cmp < 0)
{
- package = OLD_PKG_TO_NEW (new);
+ package = old_pkg_to_new (new);
callback (opkg, package, user_data);
}
}
@@ -810,3 +810,58 @@
return 0;
}
+opkg_package_t*
+opkg_find_package (opkg_t *opkg, const char *name, const char *ver, const char *arch, const char *repo)
+{
+ pkg_vec_t *all;
+ opkg_package_t *package = NULL;
+ int i;
+#define sstrcmp(x,y) (x && y) ? strcmp (x, y) : 0
+
+ opkg_assert (opkg);
+
+ all = pkg_vec_alloc ();
+ pkg_hash_fetch_available (&opkg->conf->pkg_hash, all);
+ for (i = 0; i < all->len; i++)
+ {
+ pkg_t *pkg;
+ char *pkgv;
+
+ pkg = all->pkgs[i];
+
+ /* check name */
+ if (sstrcmp (pkg->name, name))
+ continue;
+
+ /* check version */
+ pkgv = pkg_version_str_alloc (pkg);
+ if (sstrcmp (pkgv, ver))
+ {
+ free (pkgv);
+ continue;
+ }
+ free (pkgv);
+
+ /* check architecture */
+ if (arch)
+ {
+ if (sstrcmp (pkg->architecture, arch))
+ continue;
+ }
+
+ /* check repository */
+ if (repo)
+ {
+ if (sstrcmp (pkg->src->name, repo))
+ continue;
+ }
+
+ /* match found */
+ package = old_pkg_to_new (pkg);
+ break;
+ }
+
+ pkg_vec_free (all);
+
+ return package;
+}
Modified: trunk/src/target/opkg/libopkg/opkg.h
===================================================================
--- trunk/src/target/opkg/libopkg/opkg.h 2008-05-08 20:28:53 UTC (rev 4417)
+++ trunk/src/target/opkg/libopkg/opkg.h 2008-05-09 10:52:43 UTC (rev 4418)
@@ -50,7 +50,6 @@
};
opkg_package_t* opkg_package_new ();
-opkg_package_t* opkg_package_new_with_values (const char *name, const char *version, const char *arch, const char *desc, const char *tags, const char *url, int size, int installed);
void opkg_package_free (opkg_package_t *package);
opkg_t* opkg_new ();
@@ -67,3 +66,4 @@
int opkg_list_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data);
int opkg_list_upgradable_packages (opkg_t *opkg, opkg_package_callback_t callback, void *user_data);
+opkg_package_t* opkg_find_package (opkg_t *opkg, const char *name, const char *version, const char *architecture, const char *repository);
Modified: trunk/src/target/opkg/tests/libopkg_test.c
===================================================================
--- trunk/src/target/opkg/tests/libopkg_test.c 2008-05-08 20:28:53 UTC (rev 4417)
+++ trunk/src/target/opkg/tests/libopkg_test.c 2008-05-09 10:52:43 UTC (rev 4418)
@@ -2,6 +2,8 @@
#include <stdlib.h>
#include <stdio.h>
+opkg_package_t *find_pkg = NULL;
+
void
progress_callback (opkg_t *opkg, const opkg_progress_data_t *progress, void *data)
{
@@ -23,7 +25,13 @@
printf ("\rPackage count: %d Installed, %d Total Available", install_count, total_count);
fflush (stdout);
- opkg_package_free (pkg);
+ if (!find_pkg)
+ {
+ /* store the first package to print out later */
+ find_pkg = pkg;
+ }
+ else
+ opkg_package_free (pkg);
}
void
@@ -32,10 +40,36 @@
printf ("%s - %s\n", pkg->name, pkg->version);
}
+void
+print_package (opkg_package_t *pkg)
+{
+ printf (
+ "Name: %s\n"
+ "Version: %s\n"
+ "Repository: %s\n"
+ "Architecture: %s\n"
+ "Description: %s\n"
+ "Tags: %s\n"
+ "URL: %s\n"
+ "Size: %d\n"
+ "Installed: %s\n",
+ pkg->name,
+ pkg->version,
+ pkg->repository,
+ pkg->architecture,
+ pkg->description,
+ pkg->tags,
+ pkg->url,
+ pkg->size,
+ (pkg->installed ? "True" : "False")
+ );
+}
+
int
main (int argc, char **argv)
{
opkg_t *opkg;
+ opkg_package_t *pkg;
int err;
opkg = opkg_new ();
@@ -47,6 +81,25 @@
err = opkg_update_package_lists (opkg, progress_callback, "Updating...");
printf ("\nopkg_update_package_lists returned %d\n", err);
+ opkg_list_packages (opkg, package_list_callback, NULL);
+ printf ("\n");
+
+ if (find_pkg)
+ {
+ printf ("Finding package \"%s\"\n", find_pkg->name);
+ pkg = opkg_find_package (opkg, find_pkg->name, find_pkg->version, find_pkg->architecture, find_pkg->repository);
+ if (pkg)
+ {
+ print_package (pkg);
+ opkg_package_free (find_pkg);
+ opkg_package_free (pkg);
+ }
+ else
+ printf ("Package \"%s\" not found!\n", find_pkg->name);
+ }
+ else
+ printf ("No package available to test find_package.\n");
+
err = opkg_install_package (opkg, "aspell", progress_callback, "Installing...");
printf ("\nopkg_install_package returned %d\n", err);
@@ -62,8 +115,7 @@
err = opkg_upgrade_all (opkg, progress_callback, "Upgrading all...");
printf ("\nopkg_upgrade_all returned %d\n", err);
- opkg_list_packages (opkg, package_list_callback, NULL);
- printf ("\n");
+ opkg_free (opkg);
- opkg_free (opkg);
+ return 0;
}
More information about the commitlog
mailing list