On Thu, 2014-02-13 at 21:34 +0005, Sunny Sigara wrote:

> I am trying to import a google holiday calendar with "syncevolution
> --import function.
> While it can import all events from a evolution-ical file just fine,
> it fails to do so for google calendar. I am using syncevolution-1.3.2
> on saucy.
> 
> 
> '''
> cd ~/Desktop/calendar
> 
> 
> wget https://www.google.com/calendar/ical/en.indian%23holiday%
> 40group.v.calendar.google.com/public/basic.ics

The problem is that SyncEvolution cannot split up .ics files which have
multiple VEVENT/VTODO/VJOURNAL components in a single big VCALENDAR.
This is what the Google calendar file contains.

The --import code which splits the file and then passes individual
chunks of it to the backend into which they are to be imported only
knows how to split at empty lines (the default). From the man page:


       syncevolution --print-items <config> <source>
       syncevolution [--delimiter <string>] --export <dir>|<file>|- [<config> 
[<source> [<luid> ...]]]
       syncevolution [--delimiter <string>|none] --import <dir>|<file>|- 
[<config> <source>]
       syncevolution --update <dir> <config> <source>
       syncevolution [--delimiter <string>|none] --update <file>|- <config> 
<source> <luid> ...
       syncevolution --delete-items <config> <source> (<luid> ... | *)

       [...]

       --export
              Writes  all  items in the source or all items whose <luid> is 
given into a directory if the --export
              parameter exists and is a directory. The <luid> of each item is 
used as file name. Otherwise it cre‐
              ates  a  new  file  under  that name and writes the selected 
items separated by the chosen delimiter
              string. stdout can be selected with a dash.

              The default delimiter (two line breaks) matches a blank line. As 
a special case, it also  matches  a
              blank  line with DOS line ending (line break, carriage return, 
line break). This works for vCard 3.0
              and iCalendar 2.0, which never contain blank lines.

              When exporting, the default delimiter will always insert two  
line  breaks  regardless  whether  the
              items contain DOS line ends. As a special case, the initial 
newline of a delimiter is skipped if the
              item already ends in a newline.

       --import
              Adds all items found in the directory or input file to the 
source.  When reading from  a  directory,
              each  file  is  treated as one item. Otherwise the input is split 
at the chosen delimiter. "none" as
              delimiter disables splitting of the input.


If someone was interested in fixing this, he or she would have to add
methods in SyncSource for splitting up text according to the expected
content and then have the generic --import code call that.

Until then one has to pre-process input files to get the format that
SyncEvolution knows how to import. I'm attaching such a script. It
handles .ics files with one or more VCALENDAR inside.

-- 
Best Regards, Patrick Ohly

The content of this message is my personal opinion only and although
I am an employee of Intel, the statements I make here in no way
represent Intel's position on the issue, nor am I authorized to speak
on behalf of Intel on this matter.

#! /usr/bin/python
#
# Converts any kind of .ics file (read from stdin) into a file (on
# stdout) which "syncevolution --import" can handle.
#

# Copyright (C) 2014 Intel Corporation
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.

import re
import sys

all = sys.stdin.read()

# Discard all carriage returns. Makes pattern matching easier.
# Output then doesn't contain them either.
all = all.replace('\r', '')

# Final result.
calendars = []

# Process each VCALENDAR.
for calendar_match in re.finditer(r'''^BEGIN:VCALENDAR$.*?^END:VCALENDAR$''',
                                  all,
                                  re.MULTILINE + re.DOTALL):
    calendar = calendar_match.group(0)
    # Find all individual items inside the calendar.
    items = [m.group(0) for m in re.finditer(r'''^BEGIN:(?P<kind>VEVENT|VJOURNAL|VTODO)\n.*?^END:(?P=kind)\n''',
                                             calendar,
                                             re.MULTILINE + re.DOTALL)]
    # Strip these items from the calendar. We need the remaining
    # VERSION, PRODID, and in particular VTIMEZONE.
    for item in items:
        calendar = calendar.replace(item, '', 1)
    # Now inject one item after the other at the end to produce new VCALENDARs.
    calendars.extend([calendar.replace('\nEND:VCALENDAR',
                                       '\n' + item + 'END:VCALENDAR').replace('\n', '\r\n')
                      for item in items])

# Now print result, with empty line as separator.
sys.stdout.write('\r\n\r\n'.join(calendars))
# Avoid missing newline if we printed something.
if calendars:
    sys.stdout.write('\r\n')
_______________________________________________
SyncEvolution mailing list
[email protected]
https://lists.syncevolution.org/mailman/listinfo/syncevolution

Reply via email to