Import/Export: Relocated add-ons online, removed tests

- The scripts/add-ons/{im,ex}port* examples are relocated online under
  https://taskwarrior.org/tools/index.html#exts .
- The corresponding tests are no longer needed.
- The Perl JSON module is no longer required.
This commit is contained in:
Paul Beckingham 2015-07-20 07:57:54 -04:00
parent 7007ab46d6
commit 129aeb1845
17 changed files with 6 additions and 1605 deletions

3
scripts/add-ons/README Normal file
View file

@ -0,0 +1,3 @@
The import/export add-on scripts have been relocated online. Please see:
https://taskwarrior.org/tools/#exts

View file

@ -1,85 +0,0 @@
#! /usr/bin/perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
# Give a nice error if the (non-standard) JSON module is not installed.
eval "use JSON";
if ($@)
{
print "Error: You need to install the JSON Perl module.\n";
exit 1;
}
# Use the taskwarrior 2.0+ export command to filter and return JSON
my $command = join (' ', ("env PATH=$ENV{PATH} task rc.verbose=nothing rc.json.array=no export", @ARGV));
if ($command =~ /No matches/)
{
printf STDERR $command;
exit 1;
}
# Generate output.
print "'uuid','status','tags','entry','start','due','recur','end','project',",
"'priority','fg','bg','description'\n";
for my $task (split "\n", qx{$command})
{
my $data = from_json ($task);
my $desc = $data->{'description'};
$desc =~ s/'/\\'/g;
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'} || ''), "',",
"'$desc'",
"\n";
# Note that this format ignores:
# wait
# until
# annotations
# mask
# imask
# UDAs
}
exit 0;
################################################################################

View file

@ -1,90 +0,0 @@
#! /usr/bin/perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
# Give a nice error if the (non-standard) JSON module is not installed.
eval "use JSON";
if ($@)
{
print "Error: You need to install the JSON Perl module.\n";
exit 1;
}
# Use the taskwarrior 2.0+ export command to filter and return JSON
my $command = join (' ', ("env PATH='$ENV{PATH}' task rc.verbose=nothing rc.json.array=no export", @ARGV));
if ($command =~ /No matches/)
{
printf STDERR $command;
exit 1;
}
# Generate output.
print "<html>\n",
" <body>\n",
" <table>\n",
" <thead>\n",
" <tr>\n",
" <td>ID</td>\n",
" <td>Pri</td>\n",
" <td>Description</td>\n",
" <td>Project</td>\n",
" <td>Due</td>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n";
my $count = 0;
for my $task (split "\n", qx{$command})
{
++$count;
my $data = from_json ($task);
print " <tr>\n",
" <td>", ($data->{'id'} || ''), "</td>\n",
" <td>", ($data->{'priority'} || ''), "</td>\n",
" <td>", ($data->{'description'} || ''), "</td>\n",
" <td>", ($data->{'project'} || ''), "</td>\n",
" <td>", ($data->{'due'} || ''), "</td>\n",
" </tr>\n";
}
print " </tbody>\n",
" <tfooter>\n",
" <tr>\n",
" <td>", $count, " matching tasks</td>\n",
" </tr>\n",
" </tfooter>\n",
" </table>\n",
" </body>\n",
"</html>\n";
exit 0;
################################################################################

View file

@ -1,102 +0,0 @@
#! /usr/bin/perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
# Give a nice error if the (non-standard) JSON module is not installed.
eval "use JSON";
if ($@)
{
print "Error: You need to install the JSON Perl module.\n";
exit 1;
}
# Use the taskwarrior 2.0+ export command to filter and return JSON
my $command = join (' ', ("env PATH=$ENV{PATH} task rc.verbose=nothing rc.json.array=no export", @ARGV));
if ($command =~ /No matches/)
{
printf STDERR $command;
exit 1;
}
# Generate output.
print "BEGIN:VCALENDAR\n",
"VERSION:2.0\n",
"PRODID:=//GBF/taskwarrior 1.9.4//EN\n";
for my $task (split "\n", 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;
################################################################################

View file

@ -1,170 +0,0 @@
#! /usr/bin/python
###############################################################################
#
# Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included
# in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
# http://www.opensource.org/licenses/mit-license.php
#
###############################################################################
"""
export-sql.py -- Export the taskwarrior database as a series of SQL commands.
Example usage::
$ PYTHONIOENCODING=UTF-8 ./export-sql.py | sqlite3 mytasks.db
$ /usr/bin/sqlite3 mytasks.db "select * from annotations;"
This script has only been tested with sqlite3, but in theory, it could be
easily modified to supported mysql, postgres or whatever you choose.
Author: Ralph Bean
"""
import sys
import commands
import json
from datetime import datetime
# Note that you may want to modify the field sizes to suit your usage.
table_definitions = """
CREATE TABLE tasks (
uuid VARCHAR(255) NOT NULL,
description VARCHAR(255) NOT NULL,
entry DATETIME NOT NULL,
end DATETIME,
priority VARCHAR(32),
project VARCHAR(32),
status VARCHAR(32),
PRIMARY KEY (uuid)
);
CREATE TABLE annotations (
uuid VARCHAR(255) NOT NULL,
description VARCHAR(255) NOT NULL,
entry DATETIME NOT NULL,
FOREIGN KEY(uuid) REFERENCES tasks(uuid)
);
"""
replacements = {
'"': '&dquot;',
"'": '&quot;',
'[': '&open;',
']': '&close;',
'/': '\\/',
}
def escape(s):
""" Escape a string in the taskwarrior style """
for unsafe, safe in replacements.iteritems():
s = s.replace(unsafe, safe)
return s
# A lookup table for how to convert various values by type to SQL
conversion_lookup = {
# Tack on an extra set of quotes
unicode: lambda v: "'%s'" % escape(v),
# Do the same as for unicode
str: lambda v: convert(unicode(v)),
# Convert to ISO format and do the same as for unicode
datetime: lambda v: convert(v.isoformat(' ')),
# Replace python None with SQL NULL
type(None): lambda v: 'NULL',
}
# Compose a value with its corresponding function in conversion_lookup
convert = lambda v: conversion_lookup.get(type(v), lambda v: v)(v)
def parse_datetime(task):
""" Parse the datetime strings given to us by `task export` """
for key in ['entry', 'end']:
if key in task:
task[key] = datetime.strptime(task[key], "%Y%m%dT%H%M%SZ")
return task
def to_sql(task):
""" Create a list of SQL INSERT statements out of a task python dict """
def make_annotation(annot):
""" Create a list of SQL INSERT statements for an annotation """
annot['uuid'] = task['uuid']
template = "{uuid}, {description}, {entry}"
annot = dict(zip(annot.keys(), map(convert, annot.values())))
values = template.format(**annot)
return "INSERT INTO \"annotations\" VALUES(%s)" % values
template = u"{uuid}, {description}, {entry}, {end}, " + \
u"{priority}, {project}, {status}"
nullables = ['end', 'priority', 'project', 'status']
defaults = dict([(key, None) for key in nullables])
defaults['annotations'] = []
defaults.update(task)
defaults = dict(zip(defaults.keys(), map(convert, defaults.values())))
values = template.format(**defaults)
annotations = map(make_annotation, defaults['annotations'])
return ["INSERT INTO \"tasks\" VALUES(%s)" % values] + annotations
def main():
""" Return a list of SQL statements. """
# Use the taskwarrior 2.0+ export command to filter and return JSON
command = "task rc.verbose=nothing rc.json.array=yes " + " ".join(sys.argv[1:]) + " export"
# Load each task from json to a python dict
tasks = json.loads(commands.getoutput(command))
# Mangle datetime strings into python datetime objects
tasks = map(parse_datetime, tasks)
# Produce formatted SQL statements for each task
inserts = sum(map(to_sql, tasks), [])
return inserts
if __name__ == '__main__':
# Get the INSERT statements
lines = main()
# Combine them with semicolons
sql = table_definitions + ";\n".join(lines) + ';'
# Print them out, decorated with sqlite3 trappings
print u"""
BEGIN TRANSACTION;
{sql}
COMMIT;""".format(sql=sql)
###############################################################################

View file

@ -1,82 +0,0 @@
#! /usr/bin/perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
# Give a nice error if the (non-standard) JSON module is not installed.
eval "use JSON";
if ($@)
{
print "Error: You need to install the JSON Perl module.\n";
exit 1;
}
# Use the taskwarrior 2.0+ export command to filter and return JSON
my $command = join (' ', ("env PATH=$ENV{PATH} task rc.verbose=nothing rc.json.array=no export", @ARGV));
if ($command =~ /No matches/)
{
printf STDERR $command;
exit 1;
}
# Generate output.
print "uuid\tstatus\ttags\tentry\tstart\tdue\trecur\tend\tproject\t",
"priority\tfg\tbg\tdescription\n";
for my $task (split "\n", qx{$command})
{
my $data = from_json ($task);
print "$data->{'uuid'}\t",
"$data->{'status'}\t",
(exists $data->{'tags'} ? join (' ', @{$data->{'tags'}}) : ''), "\t",
"$data->{'entry'}\t",
($data->{'start'} || ''), "\t",
($data->{'due'} || ''), "\t",
($data->{'recur'} || ''), "\t",
($data->{'end'} || ''), "\t",
($data->{'project'} || ''), "\t",
($data->{'priority'} || ''), "\t",
($data->{'fg'} || ''), "\t",
($data->{'bg'} || ''), "\t",
"$data->{'description'}",
"\n";
# Note that this format ignores:
# wait
# until
# annotations
# mask
# imask
# UDAs
}
exit 0;
################################################################################

View file

@ -1,85 +0,0 @@
#! /usr/bin/perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
# Give a nice error if the (non-standard) JSON module is not installed.
eval "use JSON";
if ($@)
{
print "Error: You need to install the JSON Perl module.\n";
exit 1;
}
# Use the taskwarrior 2.0+ export command to filter and return JSON
my $command = join (' ', ("env PATH=$ENV{PATH} task rc.verbose=nothing rc.json.array=no export", @ARGV));
if ($command =~ /No matches/)
{
printf STDERR $command;
exit 1;
}
# Generate output.
print "<tasks>\n";
for my $task (split "\n", 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;
################################################################################

View file

@ -1,61 +0,0 @@
#! /usr/bin/python
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
import sys
import commands
import json
# Use the taskwarrior 2.0+ export command to filter and return JSON
command = "/usr/local/bin/task rc.verbose=nothing rc.json.array=no export " + " ".join (sys.argv[1:])
# Generate output.
print "<tasks>"
for task in commands.getoutput (command).split (",\n"):
data = json.loads (task)
print " <task>"
for name,value in data.items ():
if name == "annotations":
print " <annotations>"
for anno in value:
print " <annotation>"
for name,value in anno.items ():
print " <{0}>{1}</{0}>".format (name, value)
print " </annotation>"
print " </annotations>"
elif name == "tags":
print " <tags>"
for tag in value:
print " <tag>{0}</tag>".format (tag)
print " </tags>"
else:
print " <{0}>{1}</{0}>".format (name, value)
print " </task>"
print "</tasks>"
sys.exit (0)
################################################################################

View file

@ -1,66 +0,0 @@
#! /usr/bin/ruby
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
require 'rubygems'
require 'json'
# Use the taskwarrior 2.0+ export command to filter and return JSON
lines = IO.popen("/usr/local/bin/task rc.verbose=nothing rc.json.array=no export " + 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
################################################################################

View file

@ -1,81 +0,0 @@
#! /usr/bin/perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
# Give a nice error if the (non-standard) JSON module is not installed.
eval "use JSON";
if ($@)
{
print "Error: You need to install the JSON Perl module.\n";
exit 1;
}
# Use the taskwarrior 2.0+ export command to filter and return JSON
my $command = join (' ', ("env PATH=$ENV{PATH} task rc.verbose=nothing rc.json.array=no export", @ARGV));
if ($command =~ /No matches/)
{
printf STDERR $command;
exit 1;
}
# Generate output.
print "'uuid','status','tags','entry','start','due','recur','end','project',",
"'priority','fg','bg','description'\n";
for my $task (split "\n", 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;
################################################################################

View file

@ -1,79 +0,0 @@
#! /usr/bin/perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
# Give a nice error if the (non-standard) JSON module is not installed.
eval "use JSON";
if ($@)
{
print "Error: You need to install the JSON Perl module.\n";
exit 1;
}
# Generate output.
print "%YAML 1.1\n",
"---\n";
while (my $json = <>)
{
$json =~ s/^\[//;
$json =~ s/\]$//;
$json =~ s/,$//;
next if $json eq '';
my $data = from_json ($json);
print " task:\n";
for my $key (sort 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: ", join (',', @{$data->{'tags'}}), "\n";
}
else
{
print " $key: $data->{$key}\n";
}
}
}
print "...\n";
exit 0;
################################################################################

View file

@ -1,162 +0,0 @@
#! /usr/bin/perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
use Time::Local;
# Priority mappings.
my %priority_map = (
'a' => 'H', 'b' => 'M', 'c' => 'L', 'd' => 'L', 'e' => 'L', 'f' => 'L',
'g' => 'L', 'h' => 'L', 'i' => 'L', 'j' => 'L', 'k' => 'L', 'l' => 'L',
'm' => 'L', 'n' => 'L', 'o' => 'L', 'p' => 'L', 'q' => 'L', 'r' => 'L',
's' => 'L', 't' => 'L', 'u' => 'L', 'v' => 'L', 'w' => 'L', 'x' => 'L',
'y' => 'L', 'z' => 'L');
my @tasks;
while (my $todo = <>)
{
my $status = 'pending';
my $priority = '';
my $entry = '';
my $end = '';
my @projects;
my @contexts;
my $description = '';
my $due = '';
# pending + pri + entry
if ($todo =~ /^\(([A-Z])\)\s(\d{4}-\d{2}-\d{2})\s(.+)$/i)
{
($status, $priority, $entry, $description) = ('pending', $1, epoch ($2), $3);
}
# pending + pri
elsif ($todo =~ /^\(([A-Z])\)\s(.+)$/i)
{
($status, $priority, $description) = ('pending', $1, $2);
}
# pending + entry
elsif ($todo =~ /^(\d{4}-\d{2}-\d{2})\s(.+)$/i)
{
($status, $entry, $description) = ('pending', epoch ($1), $2);
}
# done + end + entry
elsif ($todo =~ /^x\s(\d{4}-\d{2}-\d{2})\s(\d{4}-\d{2}-\d{2})\s(.+)$/i)
{
($status, $end, $entry, $description) = ('completed', epoch ($1), epoch ($2), $3);
}
# done + end
elsif ($todo =~ /^x\s(\d{4}-\d{2}-\d{2})\s(.+)$/i)
{
($status, $end, $description) = ('completed', epoch ($1), $2);
}
# done
elsif ($todo =~ /^x\s(.+)$/i)
{
($status, $description) = ('completed', $1);
}
# pending
elsif ($todo =~ /^(.+)$/i)
{
($status, $description) = ('pending', $1);
}
# Project
@projects = $description =~ /\+(\S+)/ig;
# Contexts
@contexts = $description =~ /\@(\S+)/ig;
# Due
$due = epoch ($1) if $todo =~ /\sdue:(\d{4}-\d{2}-\d{2})/i;
# Map priorities
$priority = $priority_map{lc $priority} if $priority ne '';
# Pick first project
my $first_project = shift @projects;
# Compose the JSON
my $json = '';
$json .= "{\"status\":\"${status}\"";
$json .= ",\"priority\":\"${priority}\"" if defined $priority && $priority ne '';
$json .= ",\"project\":\"${first_project}\"" if defined $first_project && $first_project ne '';
$json .= ",\"entry\":\"${entry}\"" if $entry ne '';
$json .= ",\"end\":\"${end}\"" if $end ne '';
$json .= ",\"due\":\"${due}\"" if $due ne '';
if (@contexts)
{
$json .= ",\"tags\":[" . join (',', map {"\"$_\""} @contexts) . "]";
}
$json .= ",\"description\":\"${description}\"}";
push @tasks, $json;
}
print "[\n", join ("\n", @tasks), "\n]\n";
exit 0;
################################################################################
sub epoch
{
my ($input) = @_;
my ($y, $m, $d) = $input =~ /(\d{4})-(\d{2})-(\d{2})/;
return timelocal (0, 0, 0, $d, $m-1, $y-1900);
}
################################################################################
__DATA__
(A) Thank Mom for the meatballs @phone
(B) Schedule Goodwill pickup +GarageSale @phone
Post signs around the neighborhood +GarageSale
@GroceryStore Eskimo pies
(A) Thank Mom for the meatballs @phone
(B) Schedule Goodwill pickup +GarageSale @phone
(B) Schedule Goodwill pickup +GarageSale @phone
Post signs around the neighborhood +GarageSale
Really gotta call Mom (A) @phone @someday
(b) Get back to the boss
(B)->Submit TPS report
2011-03-02 Document +TodoTxt task format
(A) 2011-03-02 Call Mom
(A) Call Mom 2011-03-02
(A) Call Mom +Family +PeaceLoveAndHappiness @iphone @phone
x 2011-03-03 Call Mom
xylophone lesson
X 2012-01-01 Make resolutions
(A) x Find ticket prices
x 2011-03-02 2011-03-01 Review Tim's pull request +TodoTxtTouch @github

View file

@ -1,141 +0,0 @@
#! /usr/bin/perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
use Time::Local;
my @tasks;
my $status = '';
my $uuid = '';
my $priority = '';
my $entry = '';
my $end = '';
my $project = '';
my $tags = '';
my $description = '';
my $due = '';
my %annotations;
my $mid_anno = 0;
my $anno_entry = '';
my $anno_desc = '';
while (my $yaml = <>)
{
chomp $yaml;
next if $yaml =~ /\sid:/;
next if $yaml =~ /\sannotations:/;
if ($yaml =~ /task:|\.\.\./ && $description ne '')
{
# Compose the JSON
my $json = "{\"status\":\"${status}\"";
$json .= ",\"uuid\":\"${uuid}\"" if $uuid ne '';
$json .= ",\"priority\":\"${priority}\"" if $priority ne '';
$json .= ",\"project\":\"${project}\"" if $project ne '';
$json .= ",\"entry\":\"${entry}\"" if $entry ne '';
$json .= ",\"end\":\"${end}\"" if $end ne '';
$json .= ",\"due\":\"${due}\"" if $due ne '';
if ($tags ne '')
{
$tags =~ s/,/","/g;
$json .= ",\"tags\":[\"${tags}\"]";
}
if (%annotations)
{
$json .= ",\"annotations\":[";
my $pre = "";
for my $key (sort keys %annotations) {
$json .= "${pre}{\"entry\":\"${key}\",\"description\":\"${annotations{$key}}\"}";
$pre = ",";
}
$json .= "]";
}
$json .= ",\"description\":\"${description}\"}";
push @tasks, $json;
$status = $uuid = $priority = $entry = $end = $project = $tags =
$description = $due = $anno_entry = $anno_desc = '';
$mid_anno = 0;
%annotations = ();
$yaml = '';
}
else
{
$mid_anno = 1 if $yaml =~ /annotation:/;
$anno_entry = $1 if $mid_anno && $yaml =~ /entry:\s*(\S+)/;
if ($mid_anno)
{
if ($yaml =~ /description:\s*(.+)/)
{
$anno_desc = $1;
$mid_anno = 0;
$annotations{$anno_entry} = $anno_desc;
}
}
else
{
$entry = $1 if $yaml =~ /entry:\s*(\S+)/;
$description = $1 if $yaml =~ /description:\s*(.+)/;
}
$status = $1 if $yaml =~ /status:\s*(\S+)/;
$uuid = $1 if $yaml =~ /uuid:\s*(\S+)/;
$priority = $1 if $yaml =~ /priority:\s*(\S+)/;
$project = $1 if $yaml =~ /project:\s*(\S+)/;
$end = $1 if $yaml =~ /end:\s*(\S+)/;
$due = $1 if $yaml =~ /due:\s*(\S+)/;
$tags = $1 if $yaml =~ /tags:\s*(\S+)/;
}
}
print "[\n", join ("\n", @tasks), "\n]\n";
exit 0;
################################################################################
__DATA__
%YAML 1.1
---
task:
annotations:
annotation:
entry: 20100706T025311Z
description: Also needs to ignore control codes
description: text.cpp/extractLines needs to calculate string length in a way that supports UTF8
entry: 20090319T151633Z
id: 9
project: task-2.0
status: pending
tags: bug,utf8,next
uuid: 0c4cf066-9413-4862-9dc8-0793f158a649
...

View file

@ -33,9 +33,9 @@ Architecture
There are three varieties of tests: There are three varieties of tests:
* Perl unit tests that use Test::More and the JSON module. We are phasing * Perl unit tests that use Test::More module. We are phasing these out, and
these out, and will accept no new Perl tests. These tests are high level will accept no new Perl tests. These tests are high level and exercise
and exercise Taskwarrior at the command line level. Taskwarrior at the command line level.
* C++ unit tests that test low-level object interfaces. These are typically * C++ unit tests that test low-level object interfaces. These are typically
very fast tests, and are exhaustive in nature. very fast tests, and are exhaustive in nature.

View file

@ -1,91 +0,0 @@
#! /usr/bin/env perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
use Test::More tests => 22;
# Ensure environment has no influence.
delete $ENV{'TASKDATA'};
delete $ENV{'TASKRC'};
use File::Basename;
my $ut = basename ($0);
my $rc = $ut . '.rc';
my $source_dir = $0;
$source_dir =~ s{[^/]+$}{..};
# Create the rc file.
if (open my $fh, '>', $rc)
{
print $fh "data.location=.\n",
"verbose=no\n",
"json.array=off";
close $fh;
}
# Add two tasks, export, examine result.
# TODO Add annotations.
qx{../src/task rc:$rc add priority:H project:A one 2>&1};
qx{../src/task rc:$rc add +tag1 +tag2 two 2>&1};
my $output = qx{../src/task rc:$rc export | $source_dir/scripts/add-ons/export-yaml.pl > ./export.txt 2>&1};
my @lines;
if (open my $fh, '<', './export.txt')
{
@lines = <$fh>;
close $fh;
}
like ($lines[0], qr/^\%YAML 1\.1$/, "$ut: export YAML line 1");
like ($lines[1], qr/^---$/, "$ut: export YAML line 2");
like ($lines[2], qr/^ task:$/, "$ut: export YAML line 3");
like ($lines[3], qr/^ description: one$/, "$ut: export YAML line 4");
like ($lines[4], qr/^ entry: \d{8}T\d{6}Z$/, "$ut: export YAML line 5");
like ($lines[5], qr/^ id: \d+$/, "$ut: export YAML line 6");
like ($lines[6], qr/^ modified: \d{8}T\d{6}Z$/, "$ut: export YAML line 7");
like ($lines[7], qr/^ priority: H$/, "$ut: export YAML line 8");
like ($lines[8], qr/^ project: A$/, "$ut: export YAML line 9");
like ($lines[9], qr/^ status: pending$/, "$ut: export YAML line 10");
like ($lines[10], qr/^ urgency: .+$/, "$ut: export YAML line 11");
like ($lines[11], qr/^ uuid: .+$/, "$ut: export YAML line 12");
like ($lines[12], qr/^ task:$/, "$ut: export YAML line 13");
like ($lines[13], qr/^ description: two$/, "$ut: export YAML line 14");
like ($lines[14], qr/^ entry: \d{8}T\d{6}Z$/, "$ut: export YAML line 15");
like ($lines[15], qr/^ id: \d+$/, "$ut: export YAML line 16");
like ($lines[16], qr/^ modified: \d{8}T\d{6}Z$/, "$ut: export YAML line 17");
like ($lines[17], qr/^ status: pending$/, "$ut: export YAML line 18");
like ($lines[18], qr/^ tags: tag1,tag2$/, "$ut: export YAML line 19");
like ($lines[19], qr/^ urgency: .+$/, "$ut: export YAML line 20");
like ($lines[20], qr/^ uuid: .+$/, "$ut: export YAML line 21");
like ($lines[21], qr/^\.\.\.$/, "$ut: export YAML line 22");
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data export.txt), $rc;
exit 0;

View file

@ -1,129 +0,0 @@
#! /usr/bin/env perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
use Test::More tests => 23;
# Ensure environment has no influence.
delete $ENV{'TASKDATA'};
delete $ENV{'TASKRC'};
my $source_dir = $0;
$source_dir =~ s{[^/]+$}{..};
# Create the rc file.
if (open my $fh, '>', 'import.rc')
{
print $fh "data.location=.\n",
"json.array=on\n",
"dateformat=YYYY-M-D\n",
"verbose=off\n";
close $fh;
}
# Create import file.
if (open my $fh, '>', 'import.txt')
{
print $fh "(A) \@phone thank Mom for the meatballs\n", # 1
"(B) +GarageSale \@phone schedule Goodwill pickup\n", # 2
"+GarageSale \@home post signs around the neighborhood\n", # 3
"\@shopping Eskimo pies\n", # 4
"(A) Call Mom\n", # 5
"Really gotta call Mom (A) \@phone \@someday\n", # 6
"(b)->get back to the boss\n", # 7
"2011-03-02 Document +TodoTxt task format\n", # 8
"(A) 2011-03-02 Call Mom\n", # 9
"(A) Call Mom 2011-03-02\n", # 10
"(A) Call Mom +Family +PeaceLoveAndHappiness \@iphone \@phone\n", # 11
"xylophone lesson\n", # 12
"X 2011-03-03 Call Mom\n", # -
"x 2011-03-02 2011-03-01 Review Tim's pull request +TodoTxtTouch \@github\n"; # -
close $fh;
}
# Convert todo.sh --> task JSON.
qx{$source_dir/scripts/add-ons/import-todo.sh.pl <import.txt >import.json 2>&1};
# Import the JSON.
my $output = qx{../src/task rc:import.rc import import.json 2>&1};
diag ($output);
$output = qx{../src/task rc:import.rc info 1 2>&1};
like ($output, qr/^Priority.+H/ms, '1 pri:H');
like ($output, qr/^Tags.+phone/ms, '1 +phone');
like ($output, qr/^Description.+\@phone thank Mom for the meatballs/ms, '1 <desc>');
$output = qx{../src/task rc:import.rc info 2 2>&1};
like ($output, qr/^Priority.+M/ms, '2 pri:M');
like ($output, qr/^Project.+GarageSale/ms, '2 <project>');
like ($output, qr/^Description.+/ms, '2 <desc>');
$output = qx{../src/task rc:import.rc info 3 2>&1};
like ($output, qr/^Project.+GarageSale/ms, '3 <project>');
like ($output, qr/^Description.+\+GarageSale \@home post signs around the neighborhood/ms, '3 <desc>');
$output = qx{../src/task rc:import.rc info 4 2>&1};
like ($output, qr/^Description.+\@shopping Eskimo pies/ms, '4 <desc>');
$output = qx{../src/task rc:import.rc info 5 2>&1};
like ($output, qr/^Priority.+H/ms, '5 pri:H');
like ($output, qr/^Description.+Call Mom/ms, '5 <desc>');
$output = qx{../src/task rc:import.rc info 6 2>&1};
like ($output, qr/^Description.+Really gotta call Mom \(A\) \@phone \@someday/ms, '6 <desc>');
$output = qx{../src/task rc:import.rc info 7 2>&1};
like ($output, qr/^Description.+\(b\)->get back to the boss/ms, '7 <desc>');
$output = qx{../src/task rc:import.rc info 8 2>&1};
like ($output, qr/^Project.+TodoTxt/ms, '8 <project>');
like ($output, qr/^Description.+Document \+TodoTxt task format/ms, '8 <desc>');
$output = qx{../src/task rc:import.rc info 9 2>&1};
like ($output, qr/^Priority.+H/ms, '9 pri:H');
like ($output, qr/^Description.+Call Mom/ms, '9 <desc>');
$output = qx{../src/task rc:import.rc info 10 2>&1};
like ($output, qr/^Priority.+H/ms, '10 pri:H');
like ($output, qr/^Description.+Call Mom 2011-03-02/ms, '10 <desc>');
$output = qx{../src/task rc:import.rc info 11 2>&1};
like ($output, qr/^Priority.+H/ms, '11 pri:H');
like ($output, qr/^Project.+Family/ms, '8 <project>');
like ($output, qr/^Description.+Call Mom \+Family \+PeaceLoveAndHappiness \@iphone \@phone/ms, '11 <desc>');
$output = qx{../src/task rc:import.rc info 12 2>&1};
like ($output, qr/^Description.+xylophone lesson/ms, '12 <desc>');
# TODO and now the completed ones.
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data import.rc import.txt import.json);
exit 0;

View file

@ -1,178 +0,0 @@
#! /usr/bin/env perl
################################################################################
##
## Copyright 2006 - 2015, Paul Beckingham, Federico Hernandez.
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to deal
## in the Software without restriction, including without limitation the rights
## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
## copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## The above copyright notice and this permission notice shall be included
## in all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
## OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
## THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
## SOFTWARE.
##
## http://www.opensource.org/licenses/mit-license.php
##
################################################################################
use strict;
use warnings;
use Test::More tests => 15;
# Ensure environment has no influence.
delete $ENV{'TASKDATA'};
delete $ENV{'TASKRC'};
use File::Basename;
my $ut = basename ($0);
my $rc = $ut . '.rc';
my $source_dir = $0;
$source_dir =~ s{[^/]+$}{..};
# Create the rc file.
if (open my $fh, '>', $rc)
{
print $fh "data.location=.\n",
"dateformat=m/d/Y\n";
close $fh;
}
# Create import file.
if (open my $fh, '>', 'import.txt')
{
print $fh <<EOF;
%YAML 1.1
---
task:
uuid: 00000000-0000-0000-0000-000000000000
annotations:
annotation:
entry: 20100706T025311Z
description: anno ONE
description: zero
project: A
tags: a,b,y
status: pending
entry: 20110901T120000Z
task:
uuid: 11111111-1111-1111-1111-111111111111
annotations:
annotation:
entry: 20110706T025311Z
description: anno TWO
annotation:
entry: 20120706T025311Z
description: anno THREE
description: one
project: B
tags: x,y,z
status: pending
entry: 20110902T120000Z
task:
uuid: 22222222-2222-2222-2222-222222222222
description: two
status: completed
entry: 20110903T010000Z
end: 20110904T120000Z
...
EOF
close $fh;
}
# Convert YAML --> task JSON.
qx{$source_dir/scripts/add-ons/import-yaml.pl <import.txt >import.json 2>&1};
# Import the JSON.
my $output = qx{../src/task rc:$rc import import.json 2>&1 >/dev/null};
like ($output, qr/Imported 3 tasks\./, "$ut: 3 tasks imported");
$output = qx{../src/task rc:$rc list 2>&1};
# ID Project Age Description
# -- ------- ------- -----------
# 1 A 1.5 yrs zero
# 2 B 1.5 yrs one
#
# 2 tasks
like ($output, qr/1.+A.+zero/, "$ut: t1 present");
like ($output, qr/2.+B.+one/, "$ut: t2 present");
unlike ($output, qr/3.+two/, "$ut: t3 missing");
$output = qx{../src/task rc:$rc completed 2>&1};
# Complete Age Description UUID
# ---------- ---- ----------- ------------------------------------
# 9/4/2011 2.9y two 22222222-2222-2222-2222-222222222222
#
# 1 task
unlike ($output, qr/A.+zero/, "$ut: t1 missing");
unlike ($output, qr/B.+one/, "$ut: t2 missing");
like ($output, qr/9\/4\/2011.+two/, "$ut: t3 present");
# check tags and annotations
$output = qx{../src/task rc:$rc +y 2>&1};
# ID Proj Age Urg Description
# -- ---- ---- ---- -----------------------
# 2 B 2.9y 4.9 one
# 7/6/2011 anno TWO
# 7/6/2012 anno THREE
# 1 A 2.9y 4.8 zero
# 7/6/2010 anno ONE
#
# 2 tasks
like ($output, qr/1.+A.+zero.*\n.+ONE/, "$ut: t1 selected by tag, has annotation");
like ($output, qr/2.+B.+one.*\n.+TWO.*\n.+THREE/, "$ut: t2 selected by tag, has two annotations");
like ($output, qr/\n2 tasks\n/, "$ut: tag selected two tasks");
# Create import file.
if (open my $fh, '>', 'import.txt')
{
print $fh <<EOF;
%YAML 1.1
---
task:
uuid: 44444444-4444-4444-4444-444444444444
description: three
status: pending
entry: 1234567889
...
EOF
close $fh;
ok (-r 'import.txt', "$ut: Created second sample import data");
}
# Convert YAML --> task JSON.
qx{$source_dir/scripts/add-ons/import-yaml.pl <import.txt >import.json 2>&1};
# Import the JSON.
$output = qx{../src/task rc:$rc import import.json 2>&1 >/dev/null};
like ($output, qr/Imported 1 tasks\./, "$ut: 1 task imported");
# Verify.
$output = qx{../src/task rc:$rc list 2>&1};
# ID Project Pri Due Active Age Description
# -- ------- --- --- ------ ---- -----------
# 3 2.6y three
# 1 A 3d zero
# 2 B 2d one
like ($output, qr/1.+A.+zero/, "$ut: t1 present");
like ($output, qr/2.+B.+one/, "$ut: t2 present");
like ($output, qr/3.+three/, "$ut: t3 present");
# Cleanup.
unlink qw(pending.data completed.data undo.data backlog.data import.txt import.json), $rc;
exit 0;