diff --git a/src/Cmd.cpp b/src/Cmd.cpp index abfd48ca2..3e9675df8 100644 --- a/src/Cmd.cpp +++ b/src/Cmd.cpp @@ -131,7 +131,6 @@ void Cmd::load () { commands.push_back ("merge"); commands.push_back ("push"); - commands.push_back ("pull"); // Now load the custom reports. std::vector all; @@ -199,8 +198,7 @@ bool Cmd::isReadOnlyCommand () // Commands that directly modify the data files. bool Cmd::isWriteCommand () { - if (command == "merge" || - command == "pull") + if (command == "merge") return true; return false; diff --git a/src/Context.cpp b/src/Context.cpp index da584f334..81f76c3b9 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -252,7 +252,6 @@ int Context::dispatch (std::string &out) if (cmd.command == "merge") { tdb.gc (); handleMerge (out); } else if (cmd.command == "push") { handlePush (out); } - else if (cmd.command == "pull") { handlePull (out); } else if (cmd.command == "" && sequence.size ()) { rc = handleModify (out); } diff --git a/src/command.cpp b/src/command.cpp index 66cc80f49..a15018d9b 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -158,74 +158,6 @@ void handlePush (std::string&) "'push.default.uri' entry in your .taskrc file."); } -//////////////////////////////////////////////////////////////////////////////// -void handlePull (std::string&) -{ - std::string file = trim (context.task.get ("description")); - - Uri uri (file, "pull"); - uri.parse (); - - if (uri.data.length ()) - { - Directory location (context.config.get ("data.location")); - - if (! uri.append ("{pending,undo,completed}.data")) - throw std::string ("The uri '") + uri.path + "' is not a directory. Did you forget a trailing '/'?"; - - Transport* transport; - if ((transport = Transport::getTransport (uri)) != NULL) - { - transport->recv (location.data + "/"); - delete transport; - } - else - { - // Verify that files are not being copied from rc.data.location to the - // same place. - if (Directory (uri.path) == Directory (context.config.get ("data.location"))) - throw std::string ("Cannot pull files when the source and destination are the same."); - - // copy files locally - - // remove {pending,undo,completed}.data - uri.path = uri.parent(); - - Path path1 (uri.path + "undo.data"); - Path path2 (uri.path + "pending.data"); - Path path3 (uri.path + "completed.data"); - - if (path1.exists() && path2.exists() && path3.exists()) - { -// if (confirm ("xxxxxxxxxxxxx")) -// { - std::ofstream ofile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary); - std::ifstream ifile1 (path1.data.c_str() , std::ios_base::binary); - ofile1 << ifile1.rdbuf(); - - std::ofstream ofile2 ((location.data + "/pending.data").c_str(), std::ios_base::binary); - std::ifstream ifile2 (path2.data.c_str() , std::ios_base::binary); - ofile2 << ifile2.rdbuf(); - - std::ofstream ofile3 ((location.data + "/completed.data").c_str(), std::ios_base::binary); - std::ifstream ifile3 (path3.data.c_str() , std::ios_base::binary); - ofile3 << ifile3.rdbuf(); -// } - } - else - { - throw std::string ("At least one of the database files in '" + uri.path + "' is not present."); - } - } - - std::cout << "Tasks transferred from " << uri.data << "\n"; - } - else - throw std::string ("No uri was specified for the pull. Either specify " - "the uri of a remote .task directory, or create a " - "'pull.default.uri' entry in your .taskrc file."); -} - //////////////////////////////////////////////////////////////////////////////// int handleModify (std::string& outs) { diff --git a/src/commands/CMakeLists.txt b/src/commands/CMakeLists.txt index d7c6fa6f3..a470f7e2f 100644 --- a/src/commands/CMakeLists.txt +++ b/src/commands/CMakeLists.txt @@ -33,6 +33,7 @@ set (commands_SRCS Command.cpp Command.h CmdLogo.cpp CmdLogo.h CmdPrepend.cpp CmdPrepend.h CmdProjects.cpp CmdProjects.h + CmdPull.cpp CmdPull.h CmdQuery.cpp CmdQuery.h CmdReports.cpp CmdReports.h CmdShell.cpp CmdShell.h diff --git a/src/commands/CmdHelp.cpp b/src/commands/CmdHelp.cpp index 35b2da106..1f4451b06 100644 --- a/src/commands/CmdHelp.cpp +++ b/src/commands/CmdHelp.cpp @@ -110,10 +110,6 @@ int CmdHelp::execute (const std::string&, std::string& output) row = view.addRow (); view.set (row, 1, "task push URL"); view.set (row, 2, "Pushes the local *.data files to the URL."); - - row = view.addRow (); - view.set (row, 1, "task pull URL"); - view.set (row, 2, "Overwrites the local *.data files with those found at the URL."); */ output = "\n" diff --git a/src/commands/CmdPull.cpp b/src/commands/CmdPull.cpp new file mode 100644 index 000000000..f90d01197 --- /dev/null +++ b/src/commands/CmdPull.cpp @@ -0,0 +1,118 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +// +//////////////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include +#include + +extern Context context; + +//////////////////////////////////////////////////////////////////////////////// +CmdPull::CmdPull () +{ + _keyword = "pull"; + _usage = "task pull URL"; + _description = "Overwrites the local *.data files with those found at the URL."; + _read_only = true; + _displays_id = false; +} + +//////////////////////////////////////////////////////////////////////////////// +int CmdPull::execute (const std::string&, std::string& output) +{ + std::string file = trim (context.task.get ("description")); + + Uri uri (file, "pull"); + uri.parse (); + + if (uri.data.length ()) + { + Directory location (context.config.get ("data.location")); + + if (! uri.append ("{pending,undo,completed}.data")) + throw std::string ("The uri '") + uri.path + "' is not a directory. Did you forget a trailing '/'?"; + + Transport* transport; + if ((transport = Transport::getTransport (uri)) != NULL) + { + transport->recv (location.data + "/"); + delete transport; + } + else + { + // Verify that files are not being copied from rc.data.location to the + // same place. + if (Directory (uri.path) == Directory (context.config.get ("data.location"))) + throw std::string ("Cannot pull files when the source and destination are the same."); + + // copy files locally + + // remove {pending,undo,completed}.data + uri.path = uri.parent(); + + Path path1 (uri.path + "undo.data"); + Path path2 (uri.path + "pending.data"); + Path path3 (uri.path + "completed.data"); + + if (path1.exists() && path2.exists() && path3.exists()) + { +// if (confirm ("xxxxxxxxxxxxx")) +// { + std::ofstream ofile1 ((location.data + "/undo.data").c_str(), std::ios_base::binary); + std::ifstream ifile1 (path1.data.c_str() , std::ios_base::binary); + ofile1 << ifile1.rdbuf(); + + std::ofstream ofile2 ((location.data + "/pending.data").c_str(), std::ios_base::binary); + std::ifstream ifile2 (path2.data.c_str() , std::ios_base::binary); + ofile2 << ifile2.rdbuf(); + + std::ofstream ofile3 ((location.data + "/completed.data").c_str(), std::ios_base::binary); + std::ifstream ifile3 (path3.data.c_str() , std::ios_base::binary); + ofile3 << ifile3.rdbuf(); +// } + } + else + { + throw std::string ("At least one of the database files in '" + uri.path + "' is not present."); + } + } + + output += "Tasks transferred from " + uri.data + "\n"; + } + else + throw std::string ("No uri was specified for the pull. Either specify " + "the uri of a remote .task directory, or create a " + "'pull.default.uri' entry in your .taskrc file."); + + return 0; +} + +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/CmdPull.h b/src/commands/CmdPull.h new file mode 100644 index 000000000..3e77f824e --- /dev/null +++ b/src/commands/CmdPull.h @@ -0,0 +1,42 @@ +//////////////////////////////////////////////////////////////////////////////// +// 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 +// +//////////////////////////////////////////////////////////////////////////////// +#ifndef INCLUDED_CMDPULL +#define INCLUDED_CMDPULL +#define L10N // Localization complete. + +#include +#include + +class CmdPull : public Command +{ +public: + CmdPull (); + int execute (const std::string&, std::string&); +}; + +#endif +//////////////////////////////////////////////////////////////////////////////// diff --git a/src/commands/Command.cpp b/src/commands/Command.cpp index d5a0bc040..321549895 100644 --- a/src/commands/Command.cpp +++ b/src/commands/Command.cpp @@ -55,6 +55,7 @@ #include #include #include +#include #include #include #include @@ -114,6 +115,7 @@ void Command::factory (std::map & all) c = new CmdLogo (); all[c->keyword ()] = c; c = new CmdPrepend (); all[c->keyword ()] = c; c = new CmdProjects (); all[c->keyword ()] = c; + c = new CmdPull (); all[c->keyword ()] = c; c = new CmdQuery (); all[c->keyword ()] = c; c = new CmdReports (); all[c->keyword ()] = c; c = new CmdShell (); all[c->keyword ()] = c; diff --git a/src/main.h b/src/main.h index ae5622bd4..4fd8dd0a7 100644 --- a/src/main.h +++ b/src/main.h @@ -53,7 +53,6 @@ bool nag (Task&); int handleModify (std::string&); void handleMerge (std::string&); void handlePush (std::string&); -void handlePull (std::string&); int deltaAppend (Task&); int deltaPrepend (Task&); int deltaDescription (Task&);