Merge branch '1.9.3' of tasktools.org:task into 1.9.3

This commit is contained in:
Paul Beckingham 2010-10-04 17:46:46 -04:00
commit 59fa056c4b
11 changed files with 356 additions and 98 deletions

View file

@ -137,6 +137,10 @@ _task()
_known_hosts_real -a "$cur"
return 0
;;
import)
COMPREPLY=( $(compgen -o "default" -- ${cur}) )
return 0
;;
esac
;;
esac

View file

@ -12,8 +12,8 @@ task_SOURCES = API.cpp API.h Att.cpp Att.h Cmd.cpp Cmd.h Color.cpp Color.h \
Task.cpp Task.h Taskmod.cpp Taskmod.h Thread.cpp Thread.h \
Timer.cpp Timer.h Transport.cpp Transport.h TransportSSH.cpp \
TransportSSH.h TransportRSYNC.cpp TransportRSYNC.h \
Tree.cpp Tree.h command.cpp custom.cpp \
dependency.cpp edit.cpp export.cpp i18n.h import.cpp \
TransportCurl.cpp TransportCurl.h Tree.cpp Tree.h command.cpp \
custom.cpp dependency.cpp edit.cpp export.cpp i18n.h import.cpp \
interactive.cpp main.cpp main.h recur.cpp report.cpp rules.cpp \
rx.cpp rx.h text.cpp text.h util.cpp util.h
task_CPPFLAGS=$(LUA_CFLAGS)

View file

@ -32,6 +32,7 @@
#include "Transport.h"
#include "TransportSSH.h"
#include "TransportRSYNC.h"
#include "TransportCurl.h"
////////////////////////////////////////////////////////////////////////////////
Transport::Transport (const std::string& host, const std::string& path, const std::string& user="", const std::string& port="")
@ -111,67 +112,75 @@ void Transport::parseUri(std::string uri)
////////////////////////////////////////////////////////////////////////////////
Transport* Transport::getTransport(const std::string& uri)
{
if (uri.find("ssh://") == 0) {
return new TransportSSH(uri);
}
else if (uri.find("rsync://") == 0) {
return new TransportRSYNC(uri);
}
else if ( (uri.find(":") != std::string::npos)
&& (uri.find("://") == std::string::npos) )
{
return new TransportSSH(uri);
}
if (uri.find("ssh://") == 0)
{
return new TransportSSH(uri);
}
else if (uri.find("rsync://") == 0)
{
return new TransportRSYNC(uri);
}
else if ( (uri.find("http://") == 0)
|| (uri.find("https://") == 0)
|| (uri.find("ftp://") == 0) )
{
return new TransportCurl(uri);
}
else if ( (uri.find(":") != std::string::npos)
&& (uri.find("://") == std::string::npos) )
{
return new TransportSSH(uri);
}
return NULL;
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
int Transport::execute()
{
if (executable == "")
return -1;
if (executable == "")
return -1;
pid_t child_pid = fork();
pid_t child_pid = fork();
if (child_pid == 0)
{
// this is done by the child process
char shell[] = "sh";
char opt[] = "-c";
if (child_pid == 0)
{
// this is done by the child process
char shell[] = "sh";
char opt[] = "-c";
std::string cmdline = executable;
std::string cmdline = executable;
std::vector <std::string>::iterator it;
for (it = arguments.begin(); it != arguments.end(); ++it)
{
std::string tmp = *it;
cmdline += " " + tmp;
}
std::vector <std::string>::iterator it;
for (it = arguments.begin(); it != arguments.end(); ++it)
{
std::string tmp = *it;
cmdline += " " + tmp;
}
char** argv = new char*[4];
argv[0] = shell; // sh
argv[1] = opt; // -c
argv[2] = (char*)cmdline.c_str(); // e.g. scp undo.data user@host:.task/
argv[3] = NULL; // required by execv
char** argv = new char*[4];
argv[0] = shell; // sh
argv[1] = opt; // -c
argv[2] = (char*)cmdline.c_str(); // e.g. scp undo.data user@host:.task/
argv[3] = NULL; // required by execv
int ret = execvp("sh", argv);
delete[] argv;
int ret = execvp("sh", argv);
delete[] argv;
exit(ret);
}
else
{
// this is done by the parent process
int child_status;
exit(ret);
}
else
{
// this is done by the parent process
int child_status;
pid_t pid = waitpid(child_pid, &child_status, 0);
pid_t pid = waitpid(child_pid, &child_status, 0);
if (pid == -1)
return -1;
else
return child_status;
}
if (pid == -1)
return -1;
else
return child_status;
}
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -44,9 +44,9 @@ public:
protected:
std::string executable;
std::string protocol;
std::string protocol;
std::vector<std::string> arguments;
std::string host;
std::string path;
std::string port;

114
src/TransportCurl.cpp Normal file
View file

@ -0,0 +1,114 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2010, Johannes Schlatow.
// 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
//
////////////////////////////////////////////////////////////////////////////////
#include "TransportCurl.h"
////////////////////////////////////////////////////////////////////////////////
TransportCurl::TransportCurl(const std::string& uri) : Transport(uri)
{
executable = "curl";
if (protocol == "")
protocol = "http";
}
////////////////////////////////////////////////////////////////////////////////
TransportCurl::TransportCurl(
const std::string& host,
const std::string& path,
const std::string& user,
const std::string& port) : Transport (host,path,user,port)
{
executable = "curl";
if (protocol == "")
protocol = "http";
}
////////////////////////////////////////////////////////////////////////////////
void TransportCurl::send(const std::string& source)
{
if (host == "") {
throw std::string ("Hostname is empty");
}
// Wildcards arent supported
if ( (source.find ("*") != std::string::npos)
|| (source.find ("?") != std::string::npos) )
{
throw std::string ("Failed to use curl with wildcards!");
}
// cmd line is: curl -T source protocol://host:port/path
arguments.push_back ("-T");
arguments.push_back (source);
if (port != "")
{
arguments.push_back (protocol + "://" + host + ":" + port + "/" + path);
}
else
{
arguments.push_back (protocol + "://" + host + "/" + path);
}
if (execute())
throw std::string ("Failed to run curl!");
}
////////////////////////////////////////////////////////////////////////////////
void TransportCurl::recv(std::string target)
{
if (host == "") {
throw std::string ("Hostname is empty");
}
// Wildcards arent supported
if ( (path.find ("*") != std::string::npos)
|| (path.find ("?") != std::string::npos) )
{
throw std::string ("Failed to use curl with wildcards!");
}
// cmd line is: curl protocol://host:port/path/to/source/file -o path/to/target/file
if (port != "")
{
arguments.push_back (protocol + "://" + host + ":" + port + "/" + path);
}
else
{
arguments.push_back (protocol + "://" + host + "/" + path);
}
arguments.push_back ("-o");
arguments.push_back (target);
if (execute())
throw std::string ("Failed to run curl!");
}
////////////////////////////////////////////////////////////////////////////////

44
src/TransportCurl.h Normal file
View file

@ -0,0 +1,44 @@
////////////////////////////////////////////////////////////////////////////////
// taskwarrior - a command line task list manager.
//
// Copyright 2010, Johannes Schlatow.
// 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
//
////////////////////////////////////////////////////////////////////////////////
#ifndef INCLUDED_TRANSPORTCURL
#define INCLUDED_TRANSPORTCURL
#include <string>
#include <Transport.h>
class TransportCurl : public Transport {
public:
TransportCurl (const std::string&);
TransportCurl (const std::string&, const std::string&, const std::string&, const std::string&);
virtual void send (const std::string&);
virtual void recv (std::string);
};
#endif

View file

@ -43,7 +43,7 @@
#include "util.h"
#include "main.h"
#include "../auto.h"
#include "TransportSSH.h"
#include "Transport.h"
#ifdef HAVE_LIBNCURSES
#include <ncurses.h>
@ -597,65 +597,65 @@ void handleMerge (std::string& outs)
if (context.hooks.trigger ("pre-merge-command"))
{
std::string file = trim (context.task.get ("description"));
std::string tmpfile = "";
if (file.length () == 0)
{
// get default target from config
file = context.config.get ("merge.default.uri");
}
else
{
// replace argument with uri from config
std::string tmp = context.config.get ("merge." + file + ".uri");
if (tmp != "")
file = tmp;
}
std::string tmpfile = "";
if (file.length () == 0)
{
// get default target from config
file = context.config.get ("merge.default.uri");
}
else
{
// replace argument with uri from config
std::string tmp = context.config.get ("merge." + file + ".uri");
if (tmp != "")
file = tmp;
}
if (file.length () > 0)
{
Directory location (context.config.get ("data.location"));
Directory location (context.config.get ("data.location"));
// add undo.data to path if necessary
if (file.find ("undo.data") == std::string::npos)
{
if (file[file.length()-1] != '/')
file += "/";
// add undo.data to path if necessary
if (file.find ("undo.data") == std::string::npos)
{
if (file[file.length()-1] != '/')
file += "/";
file += "undo.data";
}
file += "undo.data";
}
Transport* transport;
if ((transport = Transport::getTransport (file)) != NULL )
{
tmpfile = location.data + "/undo_remote.data";
transport->recv (tmpfile);
delete transport;
Transport* transport;
if ((transport = Transport::getTransport (file)) != NULL )
{
tmpfile = location.data + "/undo_remote.data";
transport->recv (tmpfile);
delete transport;
file = tmpfile;
}
file = tmpfile;
}
context.tdb.lock (context.config.getBoolean ("locking"));
context.tdb.merge (file);
context.tdb.unlock ();
context.hooks.trigger ("post-merge-command");
context.hooks.trigger ("post-merge-command");
if (tmpfile != "")
{
remove (tmpfile.c_str());
if (tmpfile != "")
{
remove (tmpfile.c_str());
std::string autopush = context.config.get ("merge.autopush");
std::string autopush = context.config.get ("merge.autopush");
if ( ((autopush == "ask") && (confirm ("Do you want to push the changes to the database you merged from?")) )
|| (autopush == "yes") )
{
std::string out;
handlePush(out);
}
if ( ((autopush == "ask") && (confirm ("Do you want to push the changes to the database you merged from?")) )
|| (autopush == "yes") )
{
std::string out;
handlePush(out);
}
}
}
}
else // TODO : get default source from config file
throw std::string ("You must specify a file to merge.");

View file

@ -34,6 +34,7 @@
#include <text.h>
#include <util.h>
#include <main.h>
#include "Transport.h"
extern Context context;
@ -1259,10 +1260,25 @@ int handleImport (std::string &outs)
if (context.hooks.trigger ("pre-import-command"))
{
std::stringstream out;
// Use the description as a file name.
std::stringstream out;
// Use the description as a file name.
std::string file = trim (context.task.get ("description"));
#if FEATURE_URL > 0
std::string tmpfile = "";
Transport* transport;
if ((transport = Transport::getTransport (file)) != NULL )
{
std::string location (context.config.get ("data.location"));
tmpfile = location + "/import.data";
transport->recv (tmpfile);
delete transport;
file = tmpfile;
}
#endif
if (file.length () > 0)
{
// Load the file.
@ -1317,6 +1333,13 @@ int handleImport (std::string &outs)
case text: out << importText (lines); break;
case not_a_clue: /* to stop the compiler from complaining. */ break;
}
#if FEATURE_URL > 0
if (tmpfile != "")
{
remove (tmpfile.c_str ());
}
#endif
}
else
throw std::string ("You must specify a file to import.");

View file

@ -31,6 +31,8 @@
#define FEATURE_NEW_ID 1 // Echoes back new id.
#define FEATURE_SHELL 1 // Interactive shell.
#define FEATURE_NCURSES_COLS 1 // Shortcut that avoids WINDOW.
#define FEATURE_URL 1 // URL support for import.
// (always enabled for merge/push/pull)
#include <string>
#include <vector>

View file

@ -14,7 +14,8 @@ OBJECTS = ../t-TDB.o ../t-Task.o ../t-text.o ../t-Date.o ../t-Table.o \
../t-Permission.o ../t-Path.o ../t-File.o ../t-Directory.o \
../t-Hooks.o ../t-API.o ../t-rx.o ../t-Taskmod.o ../t-dependency.o \
../t-Transport.o ../t-TransportSSH.o ../t-Sensor.o ../t-Thread.o \
../t-Lisp.o ../t-Rectangle.o ../t-Tree.o ../t-TransportRSYNC.o
../t-Lisp.o ../t-Rectangle.o ../t-Tree.o ../t-TransportRSYNC.o \
../t-TransportCurl.o
all: $(PROJECT)

61
src/tests/import.url.t Executable file
View file

@ -0,0 +1,61 @@
#! /usr/bin/perl
################################################################################
## taskwarrior - a command line task list manager.
##
## Copyright 2006 - 2010, Paul Beckingham.
## 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 Test::More tests => 8;
# Create the rc file.
if (open my $fh, '>', 'import.rc')
{
print $fh "data.location=.\n";
close $fh;
ok (-r 'import.rc', 'Created import.rc');
}
my $output = qx{../task rc:import.rc import http://taskwarrior.org/attachments/download/216/import.txt};
like ($output, qr/Imported 2 tasks successfully, with 0 errors./, 'no errors');
$output = qx{../task rc:import.rc list};
like ($output, qr/1.+A.+H.+This is a test/, 't1');
like ($output, qr/2.+Another task/, 't2');
unlink 'pending.data';
ok (!-r 'pending.data', 'Removed pending.data');
unlink 'completed.data';
ok (!-r 'completed.data', 'Removed completed.data');
unlink 'undo.data';
ok (!-r 'undo.data', 'Removed undo.data');
unlink 'import.rc';
ok (!-r 'import.rc', 'Removed import.rc');
exit 0;