aboutsummaryrefslogtreecommitdiffstats
path: root/tools/evolution-move-tasks
diff options
context:
space:
mode:
authorDamon Chaplin <damon@helixcode.com>2001-01-14 09:29:29 +0800
committerDamon Chaplin <damon@src.gnome.org>2001-01-14 09:29:29 +0800
commit8c0f66640f7f09dc778cb8ae16431328698e776f (patch)
tree0c3b7b92eb21ccc09b6fd10ed65e37892e4cf9d6 /tools/evolution-move-tasks
parentb24cb94e37a34fafec5ab5dbf80e1c8b7391b70b (diff)
downloadgsoc2013-evolution-8c0f66640f7f09dc778cb8ae16431328698e776f.tar
gsoc2013-evolution-8c0f66640f7f09dc778cb8ae16431328698e776f.tar.gz
gsoc2013-evolution-8c0f66640f7f09dc778cb8ae16431328698e776f.tar.bz2
gsoc2013-evolution-8c0f66640f7f09dc778cb8ae16431328698e776f.tar.lz
gsoc2013-evolution-8c0f66640f7f09dc778cb8ae16431328698e776f.tar.xz
gsoc2013-evolution-8c0f66640f7f09dc778cb8ae16431328698e776f.tar.zst
gsoc2013-evolution-8c0f66640f7f09dc778cb8ae16431328698e776f.zip
new script to move tasks from the Calendar folder to the new Tasks folder,
2001-01-14 Damon Chaplin <damon@helixcode.com> * tools/evolution-move-tasks: new script to move tasks from the Calendar folder to the new Tasks folder, so people won't lose tasks. This can be deleted after a few releases. * tools/Makefile.am (bin_SCRIPTS): added above. svn path=/trunk/; revision=7480
Diffstat (limited to 'tools/evolution-move-tasks')
-rwxr-xr-xtools/evolution-move-tasks135
1 files changed, 135 insertions, 0 deletions
diff --git a/tools/evolution-move-tasks b/tools/evolution-move-tasks
new file mode 100755
index 0000000000..05c27cbce2
--- /dev/null
+++ b/tools/evolution-move-tasks
@@ -0,0 +1,135 @@
+#!/usr/bin/env perl
+# The above is a portable way to invoke Perl, according to the GNU Autotools
+# book. It is useful since we don't know where perl is installed.
+#
+# evolution-move-tasks: a Perl script to move tasks from the Calendar folder
+# to the new Tasks folder.
+#
+
+use diagnostics;
+
+# You may have to change this if your Evolution files are somewhere else.
+$EVOLUTION_DIR = "$ENV{'HOME'}/evolution";
+
+$CALENDAR_DIR = "$EVOLUTION_DIR/local/Calendar";
+$TASKS_DIR = "$EVOLUTION_DIR/local/Tasks";
+
+# Create the Tasks folder if needed.
+&EnsureTasksFolderExists ($TASKS_DIR);
+
+# Get any tasks from the calendar .ics file.
+$tasks = &LoadTasks ("$CALENDAR_DIR/calendar.ics");
+
+# Get any tasks already in the tasks .ics file.
+$tasks .= &LoadTasks ("$TASKS_DIR/tasks.ics");
+
+# Create a new Tasks .ics file containing all the tasks.
+&OutputTasks ("$TASKS_DIR/tasks.new", $tasks);
+
+# Move the existing tasks file to a backup.
+if (-e "$TASKS_DIR/tasks.ics") {
+ rename "$TASKS_DIR/tasks.ics", "$TASKS_DIR/tasks.bak"
+ || die "Can't rename $TASKS_DIR/tasks.ics to $TASKS_DIR/tasks.bak";
+}
+
+# Move the new file into position.
+rename "$TASKS_DIR/tasks.new", "$TASKS_DIR/tasks.ics"
+ || die "Can't rename $TASKS_DIR/tasks.new to $TASKS_DIR/tasks.ics";
+
+# Move the new Calendar file (without the Tasks) into position.
+rename "$CALENDAR_DIR/calendar.ics.new", "$CALENDAR_DIR/calendar.ics"
+ || die "Can't rename $TASKS_DIR/tasks.new to $TASKS_DIR/tasks.ics";
+
+0;
+
+
+# If the evolution/local/Tasks folder does not exist, this creates it and
+# creates the metadata XML file.
+sub EnsureTasksFolderExists {
+ my ($tasks_dir) = @_;
+
+ return if (-e $tasks_dir);
+
+ print "Creating Tasks folder in: $tasks_dir\n";
+
+ mkdir ($tasks_dir, 0777)
+ || die "Can't create Tasks folder directory: $tasks_dir";
+
+ $metadata = "$tasks_dir/folder-metadata.xml";
+ open (METADATA, ">$metadata")
+ || die "Can't create metadata file: $metadata";
+
+ print METADATA <<EOF;
+<?xml version="1.0"?>
+<efolder>
+ <type>tasks</type>
+ <description>Tasks</description>
+</efolder>
+EOF
+
+ close (METADATA);
+}
+
+
+sub LoadTasks {
+ my ($icalendar_file) = @_;
+
+ return "" if (! -e $icalendar_file);
+
+ open (ICSFILE, $icalendar_file)
+ || die "Can't open iCalendar file: $icalendar_file";
+
+ open (NEWICSFILE, ">$icalendar_file.new")
+ || die "Can't open iCalendar file: $icalendar_file.new";
+
+ $tasks = "";
+ $in_task = 0;
+ while (<ICSFILE>) {
+ if ($in_task) {
+ $tasks .= $_;
+
+ if (m/^END:VTODO/) {
+ $in_task = 0;
+ }
+
+ } else {
+ if (m/^BEGIN:VTODO/) {
+ print "Found task\n";
+
+ $tasks .= $_;
+ $in_task = 1;
+ } else {
+ print NEWICSFILE $_;
+ }
+ }
+ }
+
+ close (NEWICSFILE);
+ close (ICSFILE);
+
+ return $tasks;
+}
+
+
+sub OutputTasks {
+ my ($icalendar_file, $tasks) = @_;
+
+ open (ICSFILE, ">$icalendar_file")
+ || die "Can't create iCalendar file: $icalendar_file";
+
+ print ICSFILE <<EOF;
+BEGIN:VCALENDAR
+CALSCALE
+ :GREGORIAN
+PRODID
+ :-//Helix Code//NONSGML Evolution Calendar//EN
+VERSION
+ :2.0
+$tasks
+END:VCALENDAR
+EOF
+
+ close (ICSFILE);
+}
+
+