mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-06-26 10:54:26 +02:00
Url support #462
- Added TransportCurl for http, https and ftp - Added url support for import command
This commit is contained in:
parent
adc7992608
commit
bf316974d9
10 changed files with 352 additions and 98 deletions
|
@ -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 \
|
Task.cpp Task.h Taskmod.cpp Taskmod.h Thread.cpp Thread.h \
|
||||||
Timer.cpp Timer.h Transport.cpp Transport.h TransportSSH.cpp \
|
Timer.cpp Timer.h Transport.cpp Transport.h TransportSSH.cpp \
|
||||||
TransportSSH.h TransportRSYNC.cpp TransportRSYNC.h \
|
TransportSSH.h TransportRSYNC.cpp TransportRSYNC.h \
|
||||||
Tree.cpp Tree.h command.cpp custom.cpp \
|
TransportCurl.cpp TransportCurl.h Tree.cpp Tree.h command.cpp \
|
||||||
dependency.cpp edit.cpp export.cpp i18n.h import.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 \
|
interactive.cpp main.cpp main.h recur.cpp report.cpp rules.cpp \
|
||||||
rx.cpp rx.h text.cpp text.h util.cpp util.h
|
rx.cpp rx.h text.cpp text.h util.cpp util.h
|
||||||
task_CPPFLAGS=$(LUA_CFLAGS)
|
task_CPPFLAGS=$(LUA_CFLAGS)
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include "Transport.h"
|
#include "Transport.h"
|
||||||
#include "TransportSSH.h"
|
#include "TransportSSH.h"
|
||||||
#include "TransportRSYNC.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="")
|
Transport::Transport (const std::string& host, const std::string& path, const std::string& user="", const std::string& port="")
|
||||||
|
@ -111,12 +112,20 @@ void Transport::parseUri(std::string uri)
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
Transport* Transport::getTransport(const std::string& uri)
|
Transport* Transport::getTransport(const std::string& uri)
|
||||||
{
|
{
|
||||||
if (uri.find("ssh://") == 0) {
|
if (uri.find("ssh://") == 0)
|
||||||
|
{
|
||||||
return new TransportSSH(uri);
|
return new TransportSSH(uri);
|
||||||
}
|
}
|
||||||
else if (uri.find("rsync://") == 0) {
|
else if (uri.find("rsync://") == 0)
|
||||||
|
{
|
||||||
return new TransportRSYNC(uri);
|
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)
|
else if ( (uri.find(":") != std::string::npos)
|
||||||
&& (uri.find("://") == std::string::npos) )
|
&& (uri.find("://") == std::string::npos) )
|
||||||
{
|
{
|
||||||
|
|
114
src/TransportCurl.cpp
Normal file
114
src/TransportCurl.cpp
Normal 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
44
src/TransportCurl.h
Normal 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
|
||||||
|
|
|
@ -43,7 +43,7 @@
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
#include "../auto.h"
|
#include "../auto.h"
|
||||||
#include "TransportSSH.h"
|
#include "Transport.h"
|
||||||
|
|
||||||
#ifdef HAVE_LIBNCURSES
|
#ifdef HAVE_LIBNCURSES
|
||||||
#include <ncurses.h>
|
#include <ncurses.h>
|
||||||
|
@ -654,8 +654,8 @@ void handleMerge (std::string& outs)
|
||||||
std::string out;
|
std::string out;
|
||||||
handlePush(out);
|
handlePush(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else // TODO : get default source from config file
|
else // TODO : get default source from config file
|
||||||
throw std::string ("You must specify a file to merge.");
|
throw std::string ("You must specify a file to merge.");
|
||||||
|
|
|
@ -34,6 +34,7 @@
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
#include <main.h>
|
#include <main.h>
|
||||||
|
#include "Transport.h"
|
||||||
|
|
||||||
extern Context context;
|
extern Context context;
|
||||||
|
|
||||||
|
@ -1271,6 +1272,21 @@ int handleImport (std::string &outs)
|
||||||
|
|
||||||
// Use the description as a file name.
|
// Use the description as a file name.
|
||||||
std::string file = trim (context.task.get ("description"));
|
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)
|
if (file.length () > 0)
|
||||||
{
|
{
|
||||||
// Load the file.
|
// Load the file.
|
||||||
|
@ -1325,6 +1341,13 @@ int handleImport (std::string &outs)
|
||||||
case text: out << importText (lines); break;
|
case text: out << importText (lines); break;
|
||||||
case not_a_clue: /* to stop the compiler from complaining. */ break;
|
case not_a_clue: /* to stop the compiler from complaining. */ break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if FEATURE_URL > 0
|
||||||
|
if (tmpfile != "")
|
||||||
|
{
|
||||||
|
remove (tmpfile.c_str ());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw std::string ("You must specify a file to import.");
|
throw std::string ("You must specify a file to import.");
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
#define FEATURE_NEW_ID 1 // Echoes back new id.
|
#define FEATURE_NEW_ID 1 // Echoes back new id.
|
||||||
#define FEATURE_SHELL 1 // Interactive shell.
|
#define FEATURE_SHELL 1 // Interactive shell.
|
||||||
#define FEATURE_NCURSES_COLS 1 // Shortcut that avoids WINDOW.
|
#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 <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
|
@ -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-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-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-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)
|
all: $(PROJECT)
|
||||||
|
|
||||||
|
|
61
src/tests/import.url.t
Executable file
61
src/tests/import.url.t
Executable 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;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue