poldek: poldek/cli/poclidek_demo-poldek.conf (NEW), poldek/cli/poc...
mis
mis at pld-linux.org
Sun Feb 11 21:06:38 CET 2007
Author: mis Date: Sun Feb 11 20:06:38 2007 GMT
Module: poldek Tag: HEAD
---- Log message:
- libpoclidek demo v0.1
---- Files affected:
poldek/poldek/cli:
poclidek_demo-poldek.conf (NONE -> 1.1) (NEW), poclidek_demo.c (NONE -> 1.1) (NEW), .cvsignore (1.2 -> 1.3) , Makefile.am (1.17 -> 1.18)
---- Diffs:
================================================================
Index: poldek/poldek/cli/poclidek_demo-poldek.conf
diff -u /dev/null poldek/poldek/cli/poclidek_demo-poldek.conf:1.1
--- /dev/null Sun Feb 11 21:06:38 2007
+++ poldek/poldek/cli/poclidek_demo-poldek.conf Sun Feb 11 21:06:33 2007
@@ -0,0 +1,17 @@
+vfile external compress = n
+
+keep_downloads = no
+default_fetcher = ftp, http: internal
+
+use_sudo = yes
+hold= xmms* dev* kernel* mount
+ignore = *-smp-*
+mercy = yes
+particle install = yes
+
+#exclude path = usr/share/doc usr/share/doc
+
+[source]
+name = ac-ready
+type = pndir
+path = ftp://ftp.pld-linux.org/dists/ac/ready/i686/
================================================================
Index: poldek/poldek/cli/poclidek_demo.c
diff -u /dev/null poldek/poldek/cli/poclidek_demo.c:1.1
--- /dev/null Sun Feb 11 21:06:38 2007
+++ poldek/poldek/cli/poclidek_demo.c Sun Feb 11 21:06:33 2007
@@ -0,0 +1,148 @@
+/*
+ Copyright (C) 2000 Pawel A. Gajda (mis at k2.net.pl)
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License published by
+ the Free Software Foundation (see file COPYING for details).
+*/
+
+/*
+ $Id$
+*/
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <locale.h>
+
+#include <trurl/trurl.h>
+
+#include "poldek.h"
+#define POCLIDEK_ITSELF
+#include "poclidek.h"
+
+tn_array *execute_packages_command(struct poclidek_ctx *cctx, const char *command)
+{
+ struct poclidek_rcmd *cmd;
+ tn_array *pkgs = NULL;
+
+ cmd = poclidek_rcmd_new(cctx, NULL);
+
+ if (poclidek_rcmd_execline(cmd, command))
+ pkgs = poclidek_rcmd_get_packages(cmd);
+
+ poclidek_rcmd_free(cmd);
+ return pkgs;
+}
+
+tn_buf *execute_command_capture_output(struct poclidek_ctx *cctx, const char *command)
+{
+ struct poclidek_rcmd *cmd;
+ tn_buf *nbuf = NULL;
+
+ cmd = poclidek_rcmd_new(cctx, NULL);
+
+ if (poclidek_rcmd_execline(cmd, command))
+ nbuf = poclidek_rcmd_get_buf(cmd);
+
+ poclidek_rcmd_free(cmd);
+ return nbuf;
+}
+
+int execute_command(struct poclidek_ctx *cctx, const char *command)
+{
+ struct poclidek_rcmd *cmd;
+ int rc;
+
+ cmd = poclidek_rcmd_new(cctx, NULL);
+ rc = poclidek_rcmd_execline(cmd, command);
+ poclidek_rcmd_free(cmd);
+
+ return rc;
+}
+
+
+void printf_nbuf(tn_buf *nbuf)
+{
+ tn_buf_it it; /* n_buf iterator */
+ char *p, line[1024];
+ unsigned n, i;
+
+ i = 0;
+ n_buf_it_init(&it, nbuf);
+
+ while ((p = n_buf_it_gets(&it, &n))) {
+ if (n > sizeof(line) - 1)
+ n = sizeof(line) - 1;
+
+ memcpy(line, p, n);
+ line[n] = '\0';
+ printf(" %.2d: %s\n", i++, line);
+ }
+}
+
+
+
+int main(int argc, char *argv[])
+{
+ struct poldek_ctx *ctx;
+ struct poclidek_ctx *cctx;
+ tn_array *pkgs, *installed_pkgs;
+ tn_buf *nbuf;
+ char command[1024];
+ int i;
+
+ setlocale(LC_MESSAGES, "");
+ setlocale(LC_CTYPE, "");
+
+ poldeklib_init(); /* initialize library */
+
+ ctx = poldek_new(0); /* poldek context */
+ poldek_load_config(ctx, "poclidek_demo-poldek.conf", NULL, 0); /* load test_cli.rc config */
+ //poldek_load_config(ctx, NULL, NULL, 0); /* load default config */
+
+ poldek_setup(ctx); /* setup internals (cache dir, pm, etc) */
+
+ cctx = poclidek_new(ctx); /* poclidek (CLI interface) handler */
+
+ printf("Available packages:\n");
+ pkgs = execute_packages_command(cctx, "ls -q");
+ for (i=0; i < n_array_size(pkgs); i++) {
+ struct pkg *pkg = n_array_nth(pkgs, i);
+ printf(" %s\n", pkg_id(pkg));
+ }
+
+ printf("Installed packages:\n");
+ installed_pkgs = execute_packages_command(cctx, "cd /installed; ls -q");
+ for (i=0; i < n_array_size(pkgs); i++) {
+ struct pkg *pkg = n_array_nth(pkgs, i);
+ printf(" %s\n", pkg_id(pkg));
+ }
+ n_array_free(installed_pkgs);
+
+ /* see cli/desc.c for libpoldek API details */
+ printf("Description of rpm package:\n");
+ nbuf = execute_command_capture_output(cctx, "desc rpm");
+ if (nbuf) {
+ printf_nbuf(nbuf);
+ n_buf_free(nbuf);
+ }
+
+ execute_command(cctx, "cd"); /* back to /all-avail */
+
+ n_snprintf(command, sizeof(command), "install -t %s", pkg_id(n_array_nth(pkgs, 0)));
+ printf("Executing \"%s\"\n", command);
+ execute_command(cctx, command);
+
+ n_snprintf(command, sizeof(command), "get -d /tmp %s", pkg_id(n_array_nth(pkgs, 0)));
+ printf("Executing %s:\n", command);
+ execute_command(cctx, command);
+
+ poclidek_free(cctx);
+ poldek_free(ctx);
+
+ poldeklib_destroy();
+}
================================================================
Index: poldek/poldek/cli/.cvsignore
diff -u poldek/poldek/cli/.cvsignore:1.2 poldek/poldek/cli/.cvsignore:1.3
--- poldek/poldek/cli/.cvsignore:1.2 Wed Jul 14 20:39:39 2004
+++ poldek/poldek/cli/.cvsignore Sun Feb 11 21:06:33 2007
@@ -26,3 +26,4 @@
*.la
test_*
*.log
+poclidek_demo
================================================================
Index: poldek/poldek/cli/Makefile.am
diff -u poldek/poldek/cli/Makefile.am:1.17 poldek/poldek/cli/Makefile.am:1.18
--- poldek/poldek/cli/Makefile.am:1.17 Fri Oct 28 18:15:52 2005
+++ poldek/poldek/cli/Makefile.am Sun Feb 11 21:06:33 2007
@@ -58,9 +58,12 @@
poldek_SOURCES = $(SHELL_MOD_) main.c su.c
poldek_LDADD = libpoclidek.la
-noinst_PROGRAMS = test_cli
+noinst_PROGRAMS = test_cli poclidek_demo
test_cli_SOURCES = test_cli.c
test_cli_LDADD = libpoclidek.la
+
+poclidek_demo_SOURCES = poclidek_demo.c
+poclidek_demo_LDADD = libpoclidek.la
EXTRA_DIST = libpoclidek.sym
================================================================
---- CVS-web:
http://cvs.pld-linux.org/poldek/poldek/cli/.cvsignore?r1=1.2&r2=1.3&f=u
http://cvs.pld-linux.org/poldek/poldek/cli/Makefile.am?r1=1.17&r2=1.18&f=u
More information about the pld-cvs-commit
mailing list