Discussion:
[patch] custom output format
(too old to reply)
Raphaël
2011-07-25 15:39:53 UTC
Permalink
Hi

there are a lot of question about abook,
the first one being: why not Git since Sourceforge provides it ?

Anyway, I'm coming with this patch which aims to:
1) make the abook output format more configurable (command line)
2) allow to setup the output format not only with --convert but also
with --mutt-query.
It also moves mutt-format-specific function to filters.c for consistency.

Sample:
$ ./abook --mutt-query "Max" --outformat custom --outformatstr "!{nick} : {mobile}"
max : +336863331XX

Explanation:
When --outformat is "custom", --outformatstr is parsed to
allow later substitutions with fields.

If no --outformatstr parameter is given (but --outformat is set to
"custom"), it defaults to "{nick} ({name}): {mobile}".

If the first character of --outformatstr is a '!', then for each entry
to be printed a first check is done: if one of the fields requested does
not exists (is NULL), the entry will skipped.



I'll provide a better patch, with documentation and proper code, ... but
I would like to discuss this initial attempt to see which enhancements
can be done so we can end with a long-term solution.



Raph
Roger
2011-07-26 07:30:11 UTC
Permalink
Post by Raphaël
Hi
there are a lot of question about abook,
the first one being: why not Git since Sourceforge provides it ?
1) make the abook output format more configurable (command line)
2) allow to setup the output format not only with --convert but also
with --mutt-query.
It also moves mutt-format-specific function to filters.c for consistency.
$ ./abook --mutt-query "Max" --outformat custom --outformatstr "!{nick} : {mobile}"
max : +336863331XX
When --outformat is "custom", --outformatstr is parsed to
allow later substitutions with fields.
If no --outformatstr parameter is given (but --outformat is set to
"custom"), it defaults to "{nick} ({name}): {mobile}".
If the first character of --outformatstr is a '!', then for each entry
to be printed a first check is done: if one of the fields requested does
not exists (is NULL), the entry will skipped.
I'll provide a better patch, with documentation and proper code, ... but
I would like to discuss this initial attempt to see which enhancements
can be done so we can end with a long-term solution.
Sounds neat.

I usually just do:

$ cat .abook/addressbook |less

And type: /name_to_find


Although I do use Mutt too, I usually have my addressbook encrypted and am
already within console to cat & grep the files faster then my computer can
spawn abook after mounting the cryptfs!

--
Roger
http://rogerx.freeshell.org/
Raphaël
2011-08-01 14:24:09 UTC
Permalink
Post by Roger
Sounds neat.
$ cat .abook/addressbook |less
And type: /name_to_find
The aim of a nice formatting command-line syntax is to allow
others tools/script to benefit from abook (in non-interactive mode).
I have currently the following use-case in mind:

When sending sms with gnokii/bluetooth, I would like the nickname to be
auto-completed from abook (with the mobile phone number)
For this to work, abook should be able to understand which fields have
to be returned (in this case: the NAME (for the completion) + the MOBILE
phone number).
That was the rational for the current patch.


Second point, I also think that abook may handle a specification of the
*fields* to be searched.
Currently --mutt-query hardcodes the following: NAME, EMAIL, NICK.

It may not be enough in some cases, eg, I have contacts which won't get
into my mobile phonebook (email/mutt only contacts).
With custom fields (already existing) + a simple query language :), I should
be able to build a phonebook .vcf file only containing contacts whose
"customfieldX" = "phone", so the next time I'm being stolen my mobile
phone, I'll regenerate it easily.


The alternative (workaround) to a field specification syntax is
to return every fields (to csv) then |grep/awk then repipe to:
|abook --convert --informat csv --outformat custom # (or a manual
regexp substitution tool)
Would it be a misuse of abook ?

Or does one knows of a simple library which would already implements a
simple query language ( <fields> {=|<>|[NOT ]CONTAINS} [AND|OR ...] ).
It would make abook more flexible and a very usable PIM source for others
applications.


As a last point, for every output filter to be also used on the restricted set of
entries (= with --mutt-query) (vs the whole phonebook), they need to
implement 2 functions:
- the already existing XXX_export_database(); (which adds
header/footer/... + custom conditions)
- one which returns the conversion on a per-entry basis, kind of
XXX_export_item();

It would nicely obsoletes the struct abook_output_filter u_filters[]
duplication I've made in the patch, but it would require that every
current output filters to be split into two functions.


advises ?


regards

Raph
Roger
2011-08-01 19:15:23 UTC
Permalink
Post by Raphaël
Post by Roger
Sounds neat.
$ cat .abook/addressbook |less
And type: /name_to_find
The aim of a nice formatting command-line syntax is to allow
others tools/script to benefit from abook (in non-interactive mode).
When sending sms with gnokii/bluetooth, I would like the nickname to be
auto-completed from abook (with the mobile phone number)
For this to work, abook should be able to understand which fields have
to be returned (in this case: the NAME (for the completion) + the MOBILE
phone number).
That was the rational for the current patch.
Second point, I also think that abook may handle a specification of the
*fields* to be searched.
Currently --mutt-query hardcodes the following: NAME, EMAIL, NICK.
...
Post by Raphaël
As a last point, for every output filter to be also used on the restricted set of
entries (= with --mutt-query) (vs the whole phonebook), they need to
- the already existing XXX_export_database(); (which adds
header/footer/... + custom conditions)
- one which returns the conversion on a per-entry basis, kind of
XXX_export_item();
It would nicely obsoletes the struct abook_output_filter u_filters[]
duplication I've made in the patch, but it would require that every
current output filters to be split into two functions.
advises ?
My point being, some of us just want to get full_name, address, phone,
email_address, or a comment quickly as possible via command line rather than
opening up an entire application. Similar to cat & grep usage, of which,
everything else can be piped usually.

I also understand the above rational and it's associated benefits as getting
specific fields to an application is also highly desirable.


Although I getting you side-tracked here, I currently use something like
profiles to subdivide categories of contacts by using bashrc aliases:

alias abook-commercial="abook \
--datafile $HOME/.abook/addressbook-commercial"
alias abook-gov="abook \
--datafile $HOME/.abook/addressbook-gov"
alias abook-im="abook \
--datafile $HOME/.abook/addressbook-im"
alias abook-oss="abook \
--datafile $HOME/.abook/addressbook-oss"
alias abook-personal="abook \
--datafile $HOME/.abook/addressbook-personal"
alias abook-responded="abook \
--datafile $HOME/.abook/addressbook-responded"
alias abook-mutt="abook \
--datafile $HOME/.abook/addressbook-mutt"

This keeps abook from loading more contact info into memory then I need, hence,
preventing memory waste while keeping load times reasonable.

Most times, I'm just looking for one, maybe two contacts at once. And then,
usually only one of the following; address, full name, phone or email address
is needed using command line in a quick easily typed and memorized syntax.


I then use $HOME/journals/commercial, $HOME/journals/personal, ... for more
in depth journaling on each contact. For those, I use VI/VIM.

(Now, if there were only a method for auto mounting a cryptfs on demand through
mutt... Well, there is using autofs but it's complicated last I checked.)
--
Roger
http://rogerx.freeshell.org/
Raphaël Droz
2011-08-23 13:00:13 UTC
Permalink
Post by Roger
Although I getting you side-tracked here, I currently use something like
alias abook-commercial="abook \
--datafile $HOME/.abook/addressbook-commercial"
alias abook-gov="abook \
--datafile $HOME/.abook/addressbook-gov"
That's an interesting way to do, especially when .gov people aren't in
both address books...
I will try such a solution for handling groups even if hierarchical
filesystems are not the best way to handle non-hierarchical taxonomies.



About the field selection in non-interactive mode I'm still waiting for
approval/comment/review of Jaakko or Cedric, shouldn't I ?
But AFAICT the last commit dates from 2006-09-10 21:38 and there still
are quite some patches floating around.
So should I wait for review ? If not, is there people interested in
having the code imported into a Git repository ?

Git would help me working on my patch but I need to know if I should do
a proper CVS import into a public Git repository (usable by other
people as well) or just a quick-and-dirty import for my personal use.


Raph
Don Harper
2011-08-24 14:00:59 UTC
Permalink
I would be interested in development moving forward again...
Post by Raphaël Droz
Post by Roger
Although I getting you side-tracked here, I currently use something like
alias abook-commercial="abook \
    --datafile $HOME/.abook/addressbook-commercial"
alias abook-gov="abook \
    --datafile $HOME/.abook/addressbook-gov"
That's an interesting way to do, especially when .gov people aren't in
both address books...
I will try such a solution for handling groups even if hierarchical
filesystems are not the best way to handle non-hierarchical taxonomies.
About the field selection in non-interactive mode I'm still waiting for
approval/comment/review of Jaakko or Cedric, shouldn't I ?
But AFAICT the last commit dates from 2006-09-10 21:38 and there still
are quite some patches floating around.
So should I wait for review ? If not, is there people interested in
having the code imported into a Git repository ?
Git would help me working on my patch but I need to know if I should do
a proper CVS import into a public Git repository (usable by other
people as well) or just a quick-and-dirty import for my personal use.
Raph
------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system,
user administration capabilities and model configuration. Take
the hassle out of deploying and managing Subversion and the
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Abook-devel mailing list
https://lists.sourceforge.net/lists/listinfo/abook-devel
--
Don Harper, RHCE
Raphaël Droz
2011-08-30 17:28:14 UTC
Permalink
Post by Don Harper
I would be interested in development moving forward again...
So, after some discussion with Jaakko I have migrated the CVS tree to
git (enjoy the DVCS !)
http://abook.git.sourceforge.net/git/gitweb-index.cgi
It can be cloned, forked, ... (please note that master has not yet been
tagged 0.6.0pre2, it wasn't the case in CVS either).
The whole history is there, and a gitignore file setup.

For example, I have imported this in my gitorious personal space to work
on the custom output format patch (waiting comment before pushing)
(https://gitorious.org/drzraf/abook) (notice how the full history and
authorship are preserved)

What I would _advise_ is that the owners of ...
http://repo.or.cz/w/abook.git and https://gitorious.org/abookells
(the two existing repositories I've found so far whose authors CC:ed)
... can rebase* their work on the "main" repository so that the history
is preserved and the merges... smooth.

The former updated autotools and applied abook_vcard_import.patch
(apparently without proper credits though)
The later seems to be an attempt to implement a mutt-groups integration

* Please note that save/remove/recreate repository (at least on gitorious)
may be somewhat easier and less error-prone (I had to test this
personally)**

So I attempted to index the bugs (and patches) floating around and
here's what I was able to come with:


# vcard_import.patch
http://abook.sourceforge.net/patches/abook_vcard_import.patch
# (which is offered to every ~arch gentoo user without apparent problem
# in bugzilla)
http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-misc/abook/files/

# abook-loose-query.patch
https://sourceforge.net/tracker/?func=detail&aid=1830434&group_id=10880&atid=310880

# search-next with 'n'
https://sourceforge.net/mailarchive/forum.php?thread_name=20110113063107.GK4513%40localhost2.local&forum_name=abook-devel

# phone/call keybinding
https://sourceforge.net/mailarchive/forum.php?thread_name=20061227023925.GA6372%40andariel.informatik.uni-erlangen.de&forum_name=abook-devel

# adrconv bibtex format
https://sourceforge.net/mailarchive/forum.php?thread_name=20061221212709.GG8399%40gruenau.informatik.hu-berlin.de&forum_name=abook-devel

# debian patches
http://bugs.debian.org/cgi-bin/pkgreport.cgi?src=abook&include=tags:patch&exclude=tags:pending&pend-exc=done&repeatmerged=no

# an enhancement proposal:
https://sourceforge.net/mailarchive/forum.php?thread_name=20101011194908.GF11843%40josteinb&forum_name=abook-devel

# Bugs:
http://bugs.debian.org/cgi-bin/pkgreport.cgi?pkg=abook;dist=unstable
https://sourceforge.net/mailarchive/forum.php?thread_name=20100214142634.GA10632%40goudrenet.student.utwente.nl&forum_name=abook-devel
https://sourceforge.net/mailarchive/forum.php?thread_name=1265992644.22031.3.camel%40localhost2.local&forum_name=abook-devel
+ obviously the sourceforge tracker

I think that, at the very least, the vcard_import.patch (and the small
fix it has to come with) is a good candidate isn't ? is there anything
we may want to pull in a possible dev' branch for further testing ?


Raph
Roger
2011-08-30 21:42:30 UTC
Permalink
Post by Raphaël Droz
Post by Don Harper
I would be interested in development moving forward again...
So, after some discussion with Jaakko I have migrated the CVS tree to
git (enjoy the DVCS !)
http://abook.git.sourceforge.net/git/gitweb-index.cgi
It can be cloned, forked, ... (please note that master has not yet been
tagged 0.6.0pre2, it wasn't the case in CVS either).
The whole history is there, and a gitignore file setup.
Well, at least ABook is moving in "a" direction. ;-)
Post by Raphaël Droz
# vcard_import.patch
http://abook.sourceforge.net/patches/abook_vcard_import.patch
# (which is offered to every ~arch gentoo user without apparent problem
# in bugzilla)
http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/app-misc/abook/files/
I don't even remember the specifics of this patch, but I think I recall
spending some time getting an updated ebuild into Gentoo Portage with the vcard
patch.

Could be, I was using it to import some old vcard files when migrating to
ABook.

Since then (as previously mentioned), I've used an incantation of cat/grep
and vim alongside abook as previously mentioned. (Which ever is quicker
via command line to get a phone/email address.)... so the patch is probably
good enough for people importing data?
--
Roger
http://rogerx.freeshell.org/
Mark Lawrence
2011-09-08 03:50:44 UTC
Permalink
Post by Raphaël Droz
So, after some discussion with Jaakko I have migrated the CVS tree to
git (enjoy the DVCS !)
Thanks for all the efforts.
Post by Raphaël Droz
http://abook.git.sourceforge.net/git/gitweb-index.cgi
It can be cloned, forked, ... (please note that master has not yet
been tagged 0.6.0pre2, it wasn't the case in CVS either).
Call me blind or silly, but I can't find anywhere on that gitweb
interface a valid url to actually clone with. On some pages there is
this address:

git://abook.git.sourceforge.net

But while that looks like what I want it in fact doesn't work.

What's the real link?

Mark.
--
Mark Lawrence
Jostein Berntsen
2011-09-08 06:48:39 UTC
Permalink
Post by Mark Lawrence
=20
So, after some discussion with Jaakko I have migrated the CVS tre=
e to
Post by Mark Lawrence
git (enjoy the DVCS !)
=20
Thanks for all the efforts.
=20
http://abook.git.sourceforge.net/git/gitweb-index.cgi
It can be cloned, forked, ... (please note that master has not ye=
t
Post by Mark Lawrence
been tagged 0.6.0pre2, it wasn't the case in CVS either).
=20
Call me blind or silly, but I can't find anywhere on that gitweb
interface a valid url to actually clone with. On some pages there i=
s
Post by Mark Lawrence
=20
git://abook.git.sourceforge.net
=20
But while that looks like what I want it in fact doesn't work.
=20
What's the real link?
I am not sure, but I think it might be this one:

~/dw/abook/.git> grep url config
url =3D git://gitorious.org/drzraf/abook.git


Jostein
Raphaël Droz
2011-09-08 09:30:53 UTC
Permalink
Post by Jostein Berntsen
Post by Mark Lawrence
What's the real link?
~/dw/abook/.git> grep url config
url = git://gitorious.org/drzraf/abook.git
This one above is my clone, the official repository, as stated on the
abook SF.net page (http://sourceforge.net/scm/?type=git&group_id=10880) is:
$ git glone git://abook.git.sourceforge.net/gitroot/abook/abook

Sadly this information does not appear in gitweb.


Raph
Raphaël Droz
2011-08-30 17:24:07 UTC
Permalink
Hi,

attached is a new version of the patch, split in 7 parts.
It should be more readable.

Still no documentation, still inconsistencies in option names (why use
--mutt-query if we can specify a custom format, ...)
It needs review but most of all, it need advises and a look forward.
Jostein Berntsen
2011-08-30 17:38:04 UTC
Permalink
Post by Raphaël Droz
Hi,
=20
attached is a new version of the patch, split in 7 parts.
It should be more readable.
=20
Still no documentation, still inconsistencies in option names (why =
use
Post by Raphaël Droz
--mutt-query if we can specify a custom format, ...)
It needs review but most of all, it need advises and a look forward=
.
Post by Raphaël Droz
=20
=20
Raphaël
2012-10-24 16:58:00 UTC
Permalink
Post by Raphaël
1) make the abook output format more configurable (command line)
2) allow to setup the output format not only with --convert but also
with --mutt-query.
It also moves mutt-format-specific function to filters.c for
consistency.
pushed.
please post about any regression which may be encountered (hopefully none)


examples:

# custom format: all from addressbook
abook --convert --outformat=custom --outformatstr="{nick} / {name} : {phone}" < addressbook
# custom format from vcf: only those whose neither name nor mobile is NULL
abook --convert --informat=vcard --infile=phone.vcf --outformat=custom --outformatstr="!{name} : {mobile}"
# all matching *chris* and having their anniversary specified in the addressbook
abook --mutt-query="chris" --outformat=custom --outformatstr="!{nick} {anniversary}"

Think about --mutt-query as if it were named --query (kept for backward compatibility)
--mutt-query=X is short for:
--mutt-query=X --outformat=muttq
--outformat=muttq is (kind of) short for:
--outformat=custom --outformatstr="{email}\t{name}"



best regards

Loading...