mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
TDB2
- Implemented CmdAdd.cpp and CmdLog.cpp using TDB2. - Implemented simple append writes in TDB2. - Modified CmdImport to accept and parse JSON. - Added more const-ness in DOM, Expression and Task, to allow TDB2::get_tasks to return a const vector ref, which is a Very Good Thing. - Corrected usage for the export command. - Implemented Task::urgency as a call to Task::urgency_c, which is a const overload to allow urgency calculations (without caching) for const Task objects. - Removed obolete code from TDB. - Added lots of diagnostic output for TDB2 - it's annoying, but will be gone soon. - Added mention in CmdHelp of the new <filter> and <modifications> syntax elements. Needs more. - Added Command::filter overload which uses TDB2. Not in use yet.
This commit is contained in:
parent
523c4dfcca
commit
8827f9c978
18 changed files with 400 additions and 173 deletions
|
@ -51,12 +51,6 @@ int CmdAdd::execute (std::string& output)
|
|||
{
|
||||
int rc = 0;
|
||||
|
||||
// Must load pending to resolve dependencies, and to provide a new ID.
|
||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||
|
||||
std::vector <Task> all;
|
||||
context.tdb.loadPending (all);
|
||||
|
||||
// Every task needs a UUID.
|
||||
Task task;
|
||||
task.set ("uuid", uuid ());
|
||||
|
@ -68,17 +62,16 @@ int CmdAdd::execute (std::string& output)
|
|||
|
||||
// Only valid tasks can be added.
|
||||
task.validate ();
|
||||
|
||||
context.tdb.add (task);
|
||||
context.tdb2.add (task);
|
||||
|
||||
// TODO This should be a call in to feedback.cpp.
|
||||
/*
|
||||
if (context.verbose ("new-id"))
|
||||
output = format (STRING_CMD_ADD_FEEDBACK, context.tdb.nextId ()) + "\n";
|
||||
*/
|
||||
|
||||
context.footnote (onProjectChange (task));
|
||||
|
||||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
context.tdb2.commit ();
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
|
|
@ -125,6 +125,15 @@ int CmdHelp::execute (std::string& output)
|
|||
"or at http://taskwarrior.org"
|
||||
+ "\n"
|
||||
+ "\n"
|
||||
|
||||
+ "<filter>\n"
|
||||
" Used to restrict the visible data.\n"
|
||||
"\n"
|
||||
|
||||
+ "<modfications>\n"
|
||||
" Changes to apply to the filtered data.\n"
|
||||
"\n"
|
||||
|
||||
+ "ID is the numeric identifier displayed by the 'task list' command. "
|
||||
"You can specify multiple IDs for task commands, and multiple tasks "
|
||||
"will be affected. To specify multiple IDs make sure you use one "
|
||||
|
|
|
@ -25,9 +25,11 @@
|
|||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <Context.h>
|
||||
#include <Transport.h>
|
||||
#include <JSON.h>
|
||||
#include <text.h>
|
||||
#include <util.h>
|
||||
#include <main.h>
|
||||
|
@ -35,6 +37,85 @@
|
|||
|
||||
extern Context context;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CmdImport::CmdImport ()
|
||||
{
|
||||
_keyword = "import";
|
||||
_usage = "task import <file> [<file> ...]";
|
||||
_description = "Imports JSON files.";
|
||||
_read_only = false;
|
||||
_displays_id = false;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int CmdImport::execute (std::string& output)
|
||||
{
|
||||
int rc = 0;
|
||||
|
||||
// Use the description as a file name.
|
||||
Arguments words = context.args.extract_simple_words ();
|
||||
if (! words.size ())
|
||||
throw std::string ("You must specify a file to import.");
|
||||
|
||||
std::vector <Triple>::iterator word;
|
||||
for (word = words.begin (); word != words.end (); ++word)
|
||||
{
|
||||
std::string file = word->_first;
|
||||
std::cout << "Importing '" << file << "'\n";
|
||||
|
||||
std::string tmpfile = "";
|
||||
Uri uri (file);
|
||||
uri.parse ();
|
||||
|
||||
Transport* transport;
|
||||
if ((transport = Transport::getTransport (uri)) != NULL)
|
||||
{
|
||||
std::string location (context.config.get ("data.location"));
|
||||
tmpfile = location + "/import.data";
|
||||
transport->recv (tmpfile);
|
||||
delete transport;
|
||||
|
||||
file = tmpfile;
|
||||
}
|
||||
|
||||
// Load the file.
|
||||
std::vector <std::string> lines;
|
||||
File::read (file, lines);
|
||||
|
||||
std::vector <std::string>::iterator line;
|
||||
for (line = lines.begin (); line != lines.end (); ++line)
|
||||
{
|
||||
std::string object = trimLeft (
|
||||
trimRight (
|
||||
trimRight (
|
||||
trim (*line), ","),
|
||||
"]"),
|
||||
"[");
|
||||
|
||||
// Parse the whole thing.
|
||||
json::value* root = json::parse (object);
|
||||
std::cout << root->dump ()
|
||||
<< "\n";
|
||||
|
||||
/*
|
||||
// For each object element...
|
||||
std::map <std::string, json::value*>::iterator i;
|
||||
for (i = ((std::map <std::string, json::value*>*)root)->begin ();
|
||||
i != ((std::map <std::string, json::value*>*)root)->end ();
|
||||
++i)
|
||||
{
|
||||
Task task;
|
||||
|
||||
// TODO Navigate each object.
|
||||
}
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#ifdef OLD_STYLE
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
CmdImport::CmdImport ()
|
||||
{
|
||||
|
@ -1368,5 +1449,5 @@ int CmdImport::execute (std::string& output)
|
|||
*/
|
||||
return rc;
|
||||
}
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -31,6 +31,14 @@
|
|||
#include <string>
|
||||
#include <Command.h>
|
||||
|
||||
class CmdImport : public Command
|
||||
{
|
||||
public:
|
||||
CmdImport ();
|
||||
int execute (std::string&);
|
||||
};
|
||||
|
||||
/*
|
||||
class CmdImport : public Command
|
||||
{
|
||||
public:
|
||||
|
@ -62,6 +70,7 @@ private:
|
|||
std::string CSV (const std::vector <std::string>&);
|
||||
std::string YAML (const std::vector <std::string>&);
|
||||
};
|
||||
*/
|
||||
|
||||
#endif
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -51,12 +51,6 @@ int CmdLog::execute (std::string& output)
|
|||
{
|
||||
int rc = 0;
|
||||
|
||||
// Must load pending to resolve dependencies, and to provide a new ID.
|
||||
context.tdb.lock (context.config.getBoolean ("locking"));
|
||||
|
||||
std::vector <Task> all;
|
||||
context.tdb.loadPending (all);
|
||||
|
||||
// Every task needs a UUID.
|
||||
Task task;
|
||||
task.set ("uuid", uuid ());
|
||||
|
@ -82,13 +76,10 @@ int CmdLog::execute (std::string& output)
|
|||
|
||||
// Only valid tasks can be added.
|
||||
task.validate ();
|
||||
|
||||
context.tdb.add (task);
|
||||
context.tdb2.add (task);
|
||||
|
||||
context.footnote (onProjectChange (task));
|
||||
|
||||
context.tdb.commit ();
|
||||
context.tdb.unlock ();
|
||||
context.tdb2.commit ();
|
||||
|
||||
if (context.config.getBoolean ("echo.command"))
|
||||
output = std::string (STRING_CMD_LOG_LOGGED) + "\n";
|
||||
|
|
|
@ -283,6 +283,48 @@ void Command::filter (std::vector <Task>& input, std::vector <Task>& output)
|
|||
output = input;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
void Command::filter (std::vector <Task>& output)
|
||||
{
|
||||
Timer timer ("Command::filter");
|
||||
|
||||
Arguments f;
|
||||
if (read_only ())
|
||||
f = context.args.extract_read_only_filter ();
|
||||
else
|
||||
f = context.args.extract_write_filter ();
|
||||
|
||||
if (f.size ())
|
||||
{
|
||||
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
||||
const std::vector <Task>& completed = context.tdb2.completed.get_tasks (); // TODO Optional
|
||||
|
||||
Expression e (f);
|
||||
|
||||
output.clear ();
|
||||
std::vector <Task>::const_iterator task;
|
||||
for (task = pending.begin (); task != pending.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
output.push_back (*task);
|
||||
|
||||
for (task = completed.begin (); task != completed.end (); ++task)
|
||||
if (e.eval (*task))
|
||||
output.push_back (*task);
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::vector <Task>& pending = context.tdb2.pending.get_tasks ();
|
||||
const std::vector <Task>& completed = context.tdb2.completed.get_tasks ();
|
||||
|
||||
std::vector <Task>::const_iterator task;
|
||||
for (task = pending.begin (); task != pending.end (); ++task)
|
||||
output.push_back (*task);
|
||||
|
||||
for (task = completed.begin (); task != completed.end (); ++task)
|
||||
output.push_back (*task);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Apply the modifications in arguments to the task.
|
||||
void Command::modify_task_description_replace (Task& task, Arguments& arguments)
|
||||
|
|
|
@ -54,6 +54,8 @@ public:
|
|||
|
||||
protected:
|
||||
void filter (std::vector <Task>&, std::vector <Task>&);
|
||||
void filter (std::vector <Task>&);
|
||||
|
||||
void modify_task_description_replace (Task&, Arguments&);
|
||||
void modify_task_description_prepend (Task&, Arguments&);
|
||||
void modify_task_description_append (Task&, Arguments&);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue