You are not logged in.
Hello,
I hear lots 'bout pacman 3+ delivered with a separate library for package management.
The best docs I could find on the 'net' for arch linux package management was this: http://code.toofishes.net/pacman/doc/modules.html
And it doesn't sound (the URL) that official.
Is there any other documentation written? a short description of how pacman works, what calls to library in what order are made, in place of a "tutorial" would be GREAT.
I am (still) a GTK beginner but I would want to try writing another frontend:)
Thanks,
Vlad
Offline
Unfortunately, documentation doesn't write itself, it requires people writing it ![]()
At least, you have a reference implementation : pacman.
It'll give you an example how to use the library, if you can take the time to understand it.
pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))
Offline
code.toofishes.net is the webpage of one of pacman's developers - anything you find there is probably pretty decent.
Offline
Unfortunately, documentation doesn't write itself, it requires people writing it
I understand that, but it worth a try asking, isn't it?
code.toofishes.net is the webpage of one of pacman's developers
Good to know!
Ok, so i'll first start poking around with pacman's source!
Thanks
Offline
Shining, would it really take that much of your precious time if you posted a code snippet showing how to initialize the library, "mount"/"register"/"load"/"open" (or whatever the term is) a database, get a package by name, and enumerate its dependencies? 15 min. at most, I believe.
Offline
The reference implementation is pacman. Why write another example if you are ignoring the one that is already there...
Offline
And have a look at aqpm, which is even easier to read since it wraps alpm by functionality
Offline
There are three small standalone tool in src/util of pacman source :
http://projects.archlinux.org/?p=pacman … il;hb=HEAD
One I wrote earlier to sort pkg by size :
/*
* sortpkg.c : Display the locally installed packages sorted by size.
*
*/
#include <stdio.h>
#include <alpm.h>
#include <alpm_list.h>
int pkg_cmp(const void *v1, const void *v2)
{
pmpkg_t *p1 = (pmpkg_t *)v1;
pmpkg_t *p2 = (pmpkg_t *)v2;
unsigned long int s1 = alpm_pkg_get_size(p1);
unsigned long int s2 = alpm_pkg_get_size(p2);
return(s2 - s1);
}
int main(int argc, char **argv)
{
pmdb_t *db = NULL;
alpm_list_t *i;
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(pm_errno));
exit(EXIT_FAILURE);
}
alpm_option_set_dbpath("/var/lib/pacman");
db = alpm_db_register_local();
if(db == NULL) {
fprintf(stderr, "error: could not register 'local' database (%s)\n",
alpm_strerror(pm_errno));
exit(EXIT_FAILURE);
}
alpm_list_t *list = alpm_db_getpkgcache(db);
list = alpm_list_msort(list, alpm_list_count(list), pkg_cmp);
for(i = list; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);
printf("%s %lu\n", alpm_pkg_get_name(pkg), alpm_pkg_get_size(pkg)/1024);
}
if(alpm_release() == -1) {
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerror(pm_errno));
}
exit(EXIT_SUCCESS);
}
/* vim: set ts=2 sw=2 noet: */The one Rulatir asked for (only with the local database, but only the "register" part is different with sync ones)
#include <stdio.h>
#include <alpm.h>
#include <alpm_list.h>
void displaydeps(pmpkg_t *pkg) {
alpm_list_t *i;
for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
pmdepend_t *dep = alpm_list_getdata(i);
char *depstring = alpm_dep_get_string(dep);
printf("%s \n", depstring);
}
}
int main(int argc, char **argv)
{
pmdb_t *db = NULL;
alpm_list_t *i;
if(argc != 2) {
printf("usage : displaydeps <pkg>\n");
exit(EXIT_FAILURE);
}
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(pm_errno));
exit(EXIT_FAILURE);
}
alpm_option_set_dbpath("/var/lib/pacman");
db = alpm_db_register_local();
if(db == NULL) {
fprintf(stderr, "error: could not register 'local' database (%s)\n",
alpm_strerror(pm_errno));
exit(EXIT_FAILURE);
}
/* if the package exists, list its dependencies */
pmpkg_t *pkg = alpm_db_get_pkg(db, argv[1]);
if(pkg) {
displaydeps(pkg);
} else {
/* otherwise, search for matching packages */
fprintf(stderr, "error: package %s does not exist\n", argv[1]);
alpm_list_t *targets = alpm_list_add(NULL, argv[1]);
alpm_list_t *res = alpm_db_search(db, targets);
fprintf(stderr, "matching packages :\n");
for(i = res; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);
printf("%s\n", alpm_pkg_get_name(pkg));
}
}
if(alpm_release() == -1) {
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerror(pm_errno));
}
exit(EXIT_SUCCESS);
}
/* vim: set ts=2 sw=2 noet: */pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))
Offline
Not to be a necromancer or anything but I fixed your examples to work with the current libalpm api
/*
* sortpkg.c : Display the locally installed packages sorted by size.
*
*/
#include <stdio.h>
#include <alpm.h>
#include <alpm_list.h>
int pkg_cmp(const void *v1, const void *v2)
{
pmpkg_t *p1 = (pmpkg_t *)v1;
pmpkg_t *p2 = (pmpkg_t *)v2;
unsigned long int s1 = alpm_pkg_get_size(p1);
unsigned long int s2 = alpm_pkg_get_size(p2);
return(s2 - s1);
}
int main(int argc, char **argv)
{
pmdb_t *db = NULL;
alpm_list_t *i;
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(pm_errno));
exit(EXIT_FAILURE);
}
alpm_option_set_dbpath("/var/lib/pacman");
db = alpm_option_get_localdb();
if(db == NULL) {
fprintf(stderr, "error: could not register 'local' database (%s)\n",
alpm_strerror(pm_errno));
exit(EXIT_FAILURE);
}
alpm_list_t *list = alpm_db_get_pkgcache(db);
list = alpm_list_msort(list, alpm_list_count(list), pkg_cmp);
for(i = list; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);
printf("%s %lu\n", alpm_pkg_get_name(pkg), alpm_pkg_get_size(pkg)/1024);
}
if(alpm_release() == -1) {
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerror(pm_errno));
}
exit(EXIT_SUCCESS);
}#include <stdio.h>
#include <alpm.h>
#include <alpm_list.h>
void displaydeps(pmpkg_t *pkg) {
alpm_list_t *i;
for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
pmdepend_t *dep = alpm_list_getdata(i);
char *depstring = alpm_dep_get_name(dep);
printf("%s \n", depstring);
}
}
int main(int argc, char **argv)
{
pmdb_t *db = NULL;
alpm_list_t *i;
if(argc != 2) {
printf("usage : displaydeps <pkg>\n");
exit(EXIT_FAILURE);
}
if(alpm_initialize() == -1) {
fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(pm_errno));
exit(EXIT_FAILURE);
}
alpm_option_set_dbpath("/var/lib/pacman");
db = alpm_option_get_localdb();
if(db == NULL) {
fprintf(stderr, "error: could not register 'local' database (%s)\n",
alpm_strerror(pm_errno));
exit(EXIT_FAILURE);
}
/* if the package exists, list its dependencies */
pmpkg_t *pkg = alpm_db_get_pkg(db, argv[1]);
if(pkg) {
displaydeps(pkg);
} else {
/* otherwise, search for matching packages */
fprintf(stderr, "error: package %s does not exist\n", argv[1]);
alpm_list_t *targets = alpm_list_add(NULL, argv[1]);
alpm_list_t *res = alpm_db_search(db, targets);
fprintf(stderr, "matching packages :\n");
for(i = res; i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);
printf("%s\n", alpm_pkg_get_name(pkg));
}
}
if(alpm_release() == -1) {
fprintf(stderr, "error releasing alpm: %s\n", alpm_strerror(pm_errno));
}
exit(EXIT_SUCCESS);
}Offline

Evil #archlinux@libera.chat channel op and general support dude.
. files on github, Screenshots, Random pics and the rest
Offline