Peter Pletcher
2004-07-12 23:42:35 UTC
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).
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).