Discussion:
[Bitpim-devel] Re: Evolution address book interface
Peter Pletcher
2004-07-12 23:42:35 UTC
Permalink
I modified the evolution-addressbook-export interface code to use a
pseudo-folder as you wanted. It should be invisible to Evolution users
other than version 1.4.x
Some further capabilities would be nice, e.g.:

- Import only contacts in certain categories (my contacts list won't
*fit* in my phone)
- Mapping categories to phone "groups"
- Pull out a shorter name than "Last, First | Fullname", for the
"Name" field or have some intelligence in this area.

which I'll be working on.

Comments?

But for now:

===================================================================
RCS file: /cvsroot/bitpim/bitpim/native/evolution/evolution.py,v
retrieving revision 1.4
diff -u -r1.4 evolution.py
--- native/evolution/evolution.py 29 Jun 2004 00:13:33 -0000
1.4
+++ native/evolution/evolution.py 12 Jul 2004 23:36:26 -0000
@@ -35,6 +35,7 @@

import sys
import os
+import re

if sys.platform!="linux2":
raise ImportError()
@@ -48,12 +49,34 @@
userdir=os.path.expanduser("~")
evolutionpath="evolution/local"
evolutionbasedir=os.path.join(userdir, evolutionpath)
+evolutionexporter = {
+ 'command' : "evolution-addressbook-export",
+ 'folderid' : "<Evolution Addressbook Export>",
+ 'name' : "<Evolution Addressbook Export>",
+ 'type' : ["address book"]
+}


def getcontacts(folder):
"""Returns the contacts as a list of string vcards

Note that the Windows EOL convention is used"""
+
+ if folder == evolutionexporter['folderid']:
+ try:
+ evo_export = os.popen(evolutionexporter['command'])
+ evo_cards = evo_export.read()
+ evo_export_status = evo_export.close()
+ if evo_export_status is not None:
+ raise IOError
+ p = re.compile('(?<!\r)\n')
+ cardlist = p.split(evo_cards)
+ while len(cardlist) and cardlist[-1] == '':
+ cardlist.pop()
+ return cardlist
+ except:
+ pass
+
dir=os.path.expanduser(folder)
p=os.path.join(dir, "addressbook.db")
if not os.path.isfile(p):
@@ -73,7 +96,27 @@
db.close()
return res

-def getfolders(basedir=evolutionbasedir):
+def getfolders():
+ res=[]
+
+ # See if we can use the external addressbook exporter
+ try:
+ evo_version = os.popen(evolutionexporter['command'] + "
--version")
+ evo_version_result = evo_version.read()
+ evo_version_status = evo_version.close()
+ if evo_version_status is not None:
+ raise IOError
+ if evo_version_result.startswith("Gnome evolution 1.4"):
+ res.append(evolutionexporter)
+ else:
+ raise ValueError
+ except:
+ pass
+
+ res.extend(getfsfolders())
+ return res
+
+def getfsfolders(basedir=evolutionbasedir):

res={}
children=[]
@@ -83,7 +126,7 @@

# deal with child folders (depth first)
if os.path.isdir(p):
- f=getfolders(p)
+ f=getfsfolders(p)
if len(f):
children.extend(f)
continue
===================================================================
Note there is a space before the --version switch above. (the line
wraps for me).
Roger Binns
2004-07-14 05:25:35 UTC
Permalink
Post by Peter Pletcher
I modified the evolution-addressbook-export interface code to use a
pseudo-folder as you wanted. It should be invisible to Evolution users
other than version 1.4.x
I have added your code in and it will be available in the next release.
I made a few changes to the structure as well as some tweaks to the
code. In particular no exceptions are raised when running
evolution-addressbook-exporter --version. Also the other exception
handling was tweaked. (You were raising a class instead of an instance
of that class :-)

Finally I didn't bother trying to split the cards apart. There were
two reasons for this. The calling code just joins them all back
into a single string anyway, and I couldn't come up with an appropriate
pattern that would do the splitting correctly. Your pattern plus
variants I was trying (based around looking for "begin:vcard") have
various degenerate cases they would get wrong.
Post by Peter Pletcher
- Import only contacts in certain categories (my contacts list won't
*fit* in my phone)
Yes, that is on the list to implement. It will be a standard part
of the import dialog (ie usable for all import sources). In the same
way that there is a row saying "Only rows with ..." there
will be one saying "Only categories ...."

Later on I also expect to add some filtering of categories you
want to write to the phone.
Post by Peter Pletcher
- Mapping categories to phone "groups"
That has been the case for ages for the LG and CDM8900 code. I don't
know if Stephen has done it for the Sanyo code.

The existing code selects the most populat categories. For example for
the LG phones there are 9 categories (plus "No Group") so the most popular
9 are found and used. (Any contacts not in the most popular 9 are
written as "No Group"). The CDM8900 only has 3 user definable groups
plus another 4 pre-defined.
Post by Peter Pletcher
- Pull out a shorter name than "Last, First | Fullname", for the
"Name" field or have some intelligence in this area.
which I'll be working on.
Which particular place that names are displayed are you referring to?

Roger

Loading...