From: Gustavo Sverzut Barbieri Date: Fri, 10 Aug 2012 20:58:48 +0000 (-0300) Subject: contacts: add example CSV and eet generator. X-Git-Tag: accepted/2.0alpha/20121205.174825~100 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c78d5cf083ab01642ea3e69d7145018b3b09ef67;p=profile%2Fivi%2Flemolo.git contacts: add example CSV and eet generator. Simple script to get a CSV and generate the EET. It should be easy to have most addressbooks to generate this, or use OpenOffice to do so. --- diff --git a/Makefile.am b/Makefile.am index c4cdc1d..d5bd2d5 100644 --- a/Makefile.am +++ b/Makefile.am @@ -130,3 +130,13 @@ data/themes/default-sd.edj: $(top_builddir)/Makefile $(top_srcdir)/data/themes/d clean-local: rm -f $(top_builddir)/data/themes/default.edj rm -f $(top_builddir)/data/themes/default-sd.edj + +examplesdir = $(pkgdatadir)/examples +examples_DATA = \ +data/examples/contacts.csv + +scriptsdir = $(pkgdatadir)/scripts +scripts_SCRIPTS = \ +data/scripts/ofono-efl-contacts-db-create.py + +EXTRA_DIST += $(examples_DATA) $(scripts_SCRIPTS) diff --git a/data/examples/contacts.csv b/data/examples/contacts.csv new file mode 100644 index 0000000..b220993 --- /dev/null +++ b/data/examples/contacts.csv @@ -0,0 +1,2 @@ +John, Smith, 11 2222-3333, 11 2222-4444, 11 9999-8888 +Paul, Cooper, 22 2222-2222, 22 2222-3333, 22 9999-9999 diff --git a/data/scripts/ofono-efl-contacts-db-create.py b/data/scripts/ofono-efl-contacts-db-create.py new file mode 100755 index 0000000..22dc610 --- /dev/null +++ b/data/scripts/ofono-efl-contacts-db-create.py @@ -0,0 +1,66 @@ +#!/usr/bin/python + +import sys, csv, os, os.path, re + +if len(sys.argv) < 2: + print "Converts a CSV file to ofono-efl contacts database." + print + print "CSV file should have the following columns:" + print "\t - first name" + print "\t - last name" + print "\t - work phone" + print "\t - home phone" + print "\t - mobile phone" + raise SystemExit("missing input CSV file") + +reader = csv.reader(open(sys.argv[1], 'rb')) + +tmp = os.tmpnam() +tmpfile = open(tmp, 'wb') + +tmpfile.write("""\ +group "Contacts_List" struct { + group "list" list { +""") + +cleannumber = re.compile("[^0-9]") + +for row in reader: + first, last, work, home, mobile = row + + first = first.strip() + last = last.strip() + + work = cleannumber.sub('', work) + home = cleannumber.sub('', home) + mobile = cleannumber.sub('', mobile) + + print "Add: %s, %s, %s, %s, %s" % (first, last, work, home, mobile) + + tmpfile.write(""" + group "Contact_Info" struct { + value "picture" string: ""; + value "work" string: "%(work)s"; + value "home" string: "%(home)s"; + value "mobile" string: "%(mobile)s"; + value "name" string: "%(first)s"; + value "last_name" string: "%(last)s"; + } +""" % {"first": first, "last": last, + "work": work, "home": home, "mobile": mobile}) + +tmpfile.close() + +dbfile = os.path.expanduser("~/.config/ofono-efl/contacts.eet") + +os.system("eet -e '%s' contacts '%s' 1" % (dbfile, tmp)) +os.unlink(tmp) + +print "Created %s" % (dbfile,) +print +print "You can decompile this database with the following command:" +print "\teet -d %s contacts /tmp/contacts.txt" % (dbfile,) +print +print "Edit and then recompile it with the following command:" +print "\teet -e %s contacts /tmp/contacts.txt" % (dbfile,) +print