Export commands deprecated

- Provided examplars of export commands re-implemented using the new
  _query command.
- Implemented export-xml.pl, export-xml.py, export-xml.rb.
- Implemented export-csv.pl.
- Implemented export-yaml.pl.
- Implemented export-ical.pl.
This commit is contained in:
Paul Beckingham 2011-01-29 17:07:45 -05:00
parent 06e15b6e25
commit 8b28b013c4
8 changed files with 440 additions and 2 deletions

4
NEWS
View file

@ -55,7 +55,9 @@ New configuration options in taskwarrior 1.9.4
Newly deprecated features in taskwarrior 1.9.4 Newly deprecated features in taskwarrior 1.9.4
- - The export commands (export, export.csv, export.yaml, export.ical and
export.vcalendar) are deprecated, and will be replaced in future releases
by add-on scripts.
--- ---

View file

@ -1 +1 @@
install (DIRECTORY bash fish vim zsh DESTINATION share/doc/task/scripts) install (DIRECTORY bash fish vim zsh add-ons DESTINATION share/doc/task/scripts)

70
scripts/add-ons/export-csv.pl Executable file
View file

@ -0,0 +1,70 @@
#! /usr/bin/perl
################################################################################
## taskwarrior - a command line task list manager.
##
## Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## 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 General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use JSON;
# Use the taskwarrior 1.9.4+ _query command to issue a query and return JSON
my $command = '/usr/local/bin/task _query ' . join (' ', @ARGV);
# Generate output.
print "'uuid','status','tags','entry','start','due','recur','end','project',",
"'priority','fg','bg','description'\n";
for my $task (split /,$/ms, qx{$command})
{
my $data = from_json ($task);
print "'$data->{'uuid'}',",
"'$data->{'status'}',",
"'", (exists $data->{'tags'} ? join (' ', @{$data->{'tags'}}) : ''), "',",
"'$data->{'entry'}',",
"'", ($data->{'start'} || ''), "',",
"'", ($data->{'due'} || ''), "',",
"'", ($data->{'recur'} || ''), "',",
"'", ($data->{'end'} || ''), "',",
"'", ($data->{'project'} || ''), "',",
"'", ($data->{'priority'} || ''), "',",
"'", ($data->{'fg'} || ''), "',",
"'", ($data->{'bg'} || ''), "',",
"'$data->{'description'}'",
"\n";
# Note that this format ignores:
# wait
# until
# annotations
# mask
# imask
}
exit 0;
################################################################################

91
scripts/add-ons/export-ical.pl Executable file
View file

@ -0,0 +1,91 @@
#! /usr/bin/perl
################################################################################
## taskwarrior - a command line task list manager.
##
## Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## 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 General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use JSON;
# Use the taskwarrior 1.9.4+ _query command to issue a query and return JSON
my $command = '/usr/local/bin/task _query ' . join (' ', @ARGV);
# Generate output.
print "BEGIN:VCALENDAR\n",
"VERSION:2.0\n",
"PRODID:=//GBF/taskwarrior 1.9.4//EN\n";
for my $task (split /,$/ms, qx{$command})
{
my $data = from_json ($task);
print "BEGIN:VTODO\n";
print "UID:$data->{'uuid'}\n";
print "DTSTAMP:$data->{'entry'}\n";
print "DTSTART:$data->{'start'}\n" if exists $data->{'start'};
print "DUE:$data->{'due'}\n" if exists $data->{'due'};
print "COMPLETED:$data->{'end'}\n" if exists $data->{'end'};
print "SUMMARY:$data->{'description'}\n";
print "CLASS:PRIVATE\n";
print "CATEGORIES:", join (',', @{$data->{'tags'}}), "\n" if exists $data->{'tags'};
# Priorities map to a 1-9 scale.
if (exists $data->{'priority'})
{
print "PRIORITY:", ($data->{'priority'} eq 'H' ? '1' :
$data->{'priority'} eq 'M' ? '5' :
'9'), "\n";
}
# Status maps differently.
my $status = $data->{'status'};
if ($status eq 'pending' || $status eq 'waiting')
{
print "STATUS:", (exists $data->{'start'} ? 'IN-PROCESS' : 'NEEDS-ACTION'), "\n";
}
elsif ($status eq 'completed')
{
print "STATUS:COMPLETED\n";
}
elsif ($status eq 'deleted')
{
print "STATUS:CANCELLED\n";
}
# Annotations become comments.
if (exists $data->{'annotations'})
{
print "COMMENT:$_->{'description'}\n" for @{$data->{'annotations'}};
}
print "END:VTODO\n";
}
print "END:VCALENDAR\n";
exit 0;
################################################################################

74
scripts/add-ons/export-xml.pl Executable file
View file

@ -0,0 +1,74 @@
#! /usr/bin/perl
################################################################################
## taskwarrior - a command line task list manager.
##
## Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## 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 General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use JSON;
# Use the taskwarrior 1.9.4+ _query command to issue a query and return JSON
my $command = '/usr/local/bin/task _query ' . join (' ', @ARGV);
# Generate output.
print "<tasks>\n";
for my $task (split /,$/ms, qx{$command})
{
my $data = from_json ($task);
print " <task>\n";
for my $key (keys %$data)
{
if ($key eq 'annotations')
{
print " <annotations>\n";
for my $anno (@{$data->{$key}})
{
print " <annotation>\n";
print " <$_>$anno->{$_}</$_>\n" for keys %$anno;
print " </annotation>\n";
}
print " </annotations>\n";
}
elsif ($key eq 'tags')
{
print " <tags>\n";
print " <tag>$_</tag>\n" for @{$data->{'tags'}};
print " </tags>\n";
}
else
{
print " <$key>$data->{$key}</$key>\n";
}
}
print " </task>\n";
}
print "</tasks>\n";
exit 0;
################################################################################

62
scripts/add-ons/export-xml.py Executable file
View file

@ -0,0 +1,62 @@
#! /usr/bin/python
################################################################################
## taskwarrior - a command line task list manager.
##
## Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## 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 General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
import sys
import commands
import json
# Use the taskwarrior 1.9.4+ _query command to issue a query and return JSON
command = "/usr/local/bin/task _query " + " ".join (sys.argv[1:])
# Generate output.
print "<tasks>"
for task in commands.getoutput (command).split (",\n"):
data = json.loads (task)
print " <task>"
for attribute in data.items ():
if attribute[0] == "annotations":
print " <annotations>"
for anno in attribute[1]:
print " <annotation>"
for item in anno.items ():
print " <{0}>{1}</{0}>".format (item[0], item[1])
print " </annotation>"
print " </annotations>"
elif attribute[0] == "tags":
print " <tags>"
for tag in attribute[1]:
print " <tag>{0}</tag>".format (tag)
print " </tags>"
else:
print " <{0}>{1}</{0}>".format (attribute[0], attribute[1])
print " </task>"
print "</tasks>"
sys.exit (0)
################################################################################

67
scripts/add-ons/export-xml.rb Executable file
View file

@ -0,0 +1,67 @@
#! /usr/bin/ruby
################################################################################
## taskwarrior - a command line task list manager.
##
## Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## 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 General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
require 'rubygems'
require 'json'
# Use the taskwarrior 1.9.4+ _query command to issue a query and return JSON
lines = IO.popen("/usr/local/bin/task _query " + ARGV.join(" ")).readlines
# Generate output.
print "<tasks>\n"
lines.each do |line|
data = JSON.parse(line)
print " <task>\n"
data.each do |key,value|
if key == "annotations"
print " <annotations>\n"
value.each do |anno|
print " <annotation>\n"
anno.each do |key,value|
print " <#{key}>#{value}</#{key}>\n"
end
print " </annotation>\n"
end
print " </annotations>\n"
elsif key == "tags"
print " <tags>\n"
value.each do |tag|
print " <tag>#{tag}</tag>\n"
end
print " </tags>\n"
else
print " <#{key}>#{value}</#{key}>\n"
end
end
print " </task>\n"
end
print "</tasks>\n"
exit 0
################################################################################

72
scripts/add-ons/export-yaml.pl Executable file
View file

@ -0,0 +1,72 @@
#! /usr/bin/perl
################################################################################
## taskwarrior - a command line task list manager.
##
## Copyright 2006 - 2011, Paul Beckingham, Federico Hernandez.
## All rights reserved.
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 2 of the License, or (at your option) any later
## version.
##
## 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 General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, write to the
##
## Free Software Foundation, Inc.,
## 51 Franklin Street, Fifth Floor,
## Boston, MA
## 02110-1301
## USA
##
################################################################################
use strict;
use warnings;
use JSON;
# Use the taskwarrior 1.9.4+ _query command to issue a query and return JSON
my $command = '/usr/local/bin/task _query ' . join (' ', @ARGV);
# Generate output.
print "%YAML 1.1\n",
"---\n";
for my $task (split /,$/ms, qx{$command})
{
my $data = from_json ($task);
print " task:\n";
for my $key (keys %$data)
{
if ($key eq 'annotations')
{
print " annotations:\n";
for my $anno (@{$data->{$key}})
{
print " annotation:\n";
print " $_:$anno->{$_}\n" for keys %$anno;
}
}
elsif ($key eq 'tags')
{
print " tags:\n";
print " tag:$_\n" for @{$data->{'tags'}};
}
else
{
print " $key:$data->{$key}\n";
}
}
}
print "...\n";
exit 0;
################################################################################