You are not logged in.

#1 2010-12-01 02:08:27

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

expac - alpm data extraction tool

Sick of sed? Annoyed at awk? Gagging on grep? expac is for you!

expac formats package data the way you want it to. No more need for parsing the output of pacman -Qi. Want to know the depends of a package in a neat list with your own delimiter? Done!

$ expac %D -l'\n' pacman
bash
libarchive>=2.7.1
libfetch>=2.25
pacman-mirrorlist

This is great! ...but falc! I don't want those versions in there! Won't I have to go get some sort of parsing tool to get rid of them? Nope! expac can do that too! Just slide in the %E in place of %D. It's got everything!

The local database is the default, but you can access the sync databases too! Just use the familiar -S option, and you're on your way! expac also searches with regex, and it'll accept repo/pkg style arguments as well.

Ok, but seriously. I thought this would be nice for folks who want to interface with alpm from a script but who don't want the overhead of having to parse pacman's less flexible output. This is meant to be light, and provide raw output for use in conjunction with other utilities.

But there are, of course, other uses. Maybe you want custom formatted pacman searches. Ever wanted to see install or download sizes in search results? Easy!

expac '%r/%n %v [%k|%m]\n    %d' -Ss foo

Now you've got both! The format string is capable of handling all the common backslashed escape codes, which also means that adding color is a breeze.

I think I've only touched the tip of the iceberg as far as what you could do this with programmatically with tremendous ease. Just an example...

$ declare -A deps
$ eval $(expac 'deps[%n]="%D"' -Qs 'x.*git')
$ echo ${deps[x264-git]}
libxcomposite libxdamage libxrender

The focus here is to make the output as flexible as possible. Build and install dates are allowed custom format strings, so you can very easily get them in epoch times for easy sorting and manipulation elsewhere. The end-of-package delimiter can be changed from the default newline to whatever you want.

I've released this into the AUR, and there's of course a github repo for it. Below you'll find, from the man page, a list of all the supported tokens:

%B    backup files
%C    conflicts with
%D    depends on
%E    depends on (no version strings)
%F    files (only with -Q)
%G    groups
%L    licenses
%N    required by
%O    optional deps
%P    provides
%R    replaces
%S    provides (no version strings)
%a    architecture
%b    build date
%d    description
%f    filename (only with -S)
%i    has install scriptlet
%k    download size
%l    install date (only with -Q)
%m    install size
%n    package name
%p    packager name
%r    repo
%s    md5sum
%u    project URL
%v    version
%w    install reason
%%    literal %

Bugs? There's no bugs. But if I happen to be wrong, drop a note here, email me, yell at me on IRC, or open a github issue.

Thanks to Keenerd for breaking this, telling me my code sucks, and putting up with my not-so-internal monologue while writing this.

Last edited by falconindy (2010-12-01 22:06:16)

Offline

#2 2010-12-01 03:07:57

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,365
Website

Re: expac - alpm data extraction tool

This is awesome.   I like seeing more and more software being built around libalpm rather than scraping pacman's output or the db directly.

Offline

#3 2010-12-01 04:43:35

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: expac - alpm data extraction tool

Nifty! I like your style, falconindy.


This silver ladybug at line 28...

Offline

#4 2010-12-01 04:50:34

jowilkin
Member
Registered: 2009-05-07
Posts: 243

Re: expac - alpm data extraction tool

Allan wrote:

This is awesome.   I like seeing more and more software being built around libalpm rather than scraping pacman's output or the db directly.

Ain't that the truth.

Offline

#5 2014-01-21 17:00:27

demian
Member
From: Frankfurt, Germany
Registered: 2009-05-06
Posts: 709

Re: expac - alpm data extraction tool

very interesting. bump for awareness and this question:

is there a way to specify the date format?
currently "Wed Dec 8 10:00:50 2013" which makes sorting hard.

P.S.: Nvm, it's even in the manual: --timefmt

Cheers

Last edited by demian (2014-01-21 17:02:56)


no place like /home
github

Offline

#6 2014-01-21 17:04:18

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: expac - alpm data extraction tool

You can use e.g. '--timefmt=%s':

man expac wrote:

       -t, --timefmt <format>
           Output time described by the specified format. This string is passed directly to strftime(3). The default format is %c.

Offline

#7 2014-01-21 17:57:13

x33a
Forum Fellow
Registered: 2009-08-15
Posts: 4,587

Re: expac - alpm data extraction tool

Wow, karol ninja'd lol

Offline

#8 2017-06-25 09:45:59

glyons
Member
From: Europa
Registered: 2016-10-14
Posts: 37

Re: expac - alpm data extraction tool

Question Regarding the build date flag

%b    build date

When I run

expac --timefmt=%s '%b\t%n' | sort -n

I should see the the  sorted  packages installed by pacman by their original installation date
oldest to newest  but i see latest updated/upgraded dates packages as well in the sort.

Is that the correct and expected output of that flag?

from man page

      List the oldest 10 installed packages (by build date):

         $ expac --timefmt=%s '%b\t%n' | sort -n | head -10

I want to use expac to view oldest and newest packages by their original install date not upgrades or updates, if possible.

EDIT:
the %l flag also includes latest upgrades in the results.

Last edited by glyons (2017-06-25 12:06:52)

Offline

#9 2017-06-25 09:56:14

Raynman
Member
Registered: 2011-10-22
Posts: 1,539

Re: expac - alpm data extraction tool

Install date is %l. But if by "original installation date" you mean the install date of the first version of the package that you ever installed, I think you should resort to parsing pacman.log.

Offline

#10 2017-06-25 12:16:37

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: expac - alpm data extraction tool

Yep, parsing pacman.log is your only option here. Pacman simply doesn't store the information you want.

Offline

Board footer

Powered by FluxBB