[Calypso] [Patch] Import all contacts from file

Guido G√ľnther agx at sigxcpu.org
Sat Jan 2 07:04:59 PST 2016


Hi,
On Fri, Jan 01, 2016 at 12:04:54PM -0200, Raniere Silva wrote:
> I'm not sure why
> 
>     $ calypso.py --import foo/bar my-vcard.vcf
> 
> import only the first contact from my-vcard.vcf.
> The behaviour that I expected from the previous command
> was to import all the contacts so I fixed this,
> see the attachment.

According to https://tools.ietf.org/html/rfc6350#section-6.1.1 there can
be several entities within a single file so having this makes sense to
me.

Cheers,
 -- Guido

> 
> Cheers and Happy New Year.
> 
> Raniere

> From b5b95e0937b7c82b65279fdbcd1d8aeab4bae878 Mon Sep 17 00:00:00 2001
> From: Raniere Silva <raniere at ime.unicamp.br>
> Date: Fri, 1 Jan 2016 11:59:30 -0200
> Subject: [PATCH] Import all the vcard items one the file
> 
> ---
>  calypso/webdav.py | 27 ++++++++++++++-------------
>  1 file changed, 14 insertions(+), 13 deletions(-)
> 
> diff --git a/calypso/webdav.py b/calypso/webdav.py
> index c23d4e4..b533a57 100644
> --- a/calypso/webdav.py
> +++ b/calypso/webdav.py
> @@ -501,21 +501,22 @@ class Collection(object):
>          """
>  
>          try:
> -            new_ics = vobject.readOne(codecs.open(path,encoding='utf-8').read())
> -            if new_ics.name == 'VCALENDAR':
> -
> -                events = new_ics.vevent_list
> -                for ve in events:
> -                    # Check for events with both dtstart and duration entries and
> -                    # delete the duration one
> -                    if ve.contents.has_key('dtstart') and ve.contents.has_key('duration'):
> -                        del ve.contents['duration']
> -                    new_ics.vevent_list = [ve]
> +            new_object = vobject.readComponents(codecs.open(path,encoding='utf-8').read())
> +            for new_ics in new_object:
> +                if new_ics.name == 'VCALENDAR':
> +
> +                    events = new_ics.vevent_list
> +                    for ve in events:
> +                        # Check for events with both dtstart and duration entries and
> +                        # delete the duration one
> +                        if ve.contents.has_key('dtstart') and ve.contents.has_key('duration'):
> +                            del ve.contents['duration']
> +                        new_ics.vevent_list = [ve]
> +                        new_item = Item(new_ics.serialize(), None, path)
> +                        self.import_item(new_item, path)
> +                else:
>                      new_item = Item(new_ics.serialize(), None, path)
>                      self.import_item(new_item, path)
> -            else:
> -                new_item = Item(new_ics.serialize(), None, path)
> -                self.import_item(new_item, path)
>              return True
>          except Exception, ex:
>              self.log.exception("Failed to import: %s", path)
> -- 
> 2.6.0
> 




> _______________________________________________
> Calypso mailing list
> Calypso at keithp.com
> http://keithp.com/mailman/listinfo/calypso



More information about the Calypso mailing list