Enhancements - export

- Implemented Task::composeCSV.
- Implemented export command, but removed filename support.  This
  needs to be documented.
This commit is contained in:
Paul Beckingham 2009-06-14 14:26:39 -04:00
parent efe0b86708
commit f470acadaa
4 changed files with 69 additions and 51 deletions

View file

@ -164,7 +164,6 @@ std::string Context::dispatch ()
// TODO Look at this thing. It just cries out for a dispatch table. // TODO Look at this thing. It just cries out for a dispatch table.
/* /*
if (cmd.command == "export") { out = handleExport (); }
*/ */
if (cmd.command == "projects") { out = handleProjects (); } if (cmd.command == "projects") { out = handleProjects (); }
else if (cmd.command == "tags") { out = handleTags (); } else if (cmd.command == "tags") { out = handleTags (); }
@ -191,6 +190,9 @@ std::string Context::dispatch ()
else if (cmd.command == "start") { out = handleStart (); } else if (cmd.command == "start") { out = handleStart (); }
else if (cmd.command == "stop") { out = handleStop (); } else if (cmd.command == "stop") { out = handleStop (); }
else if (cmd.command == "undo") { out = handleUndo (); } else if (cmd.command == "undo") { out = handleUndo (); }
*/
else if (cmd.command == "export") { out = handleExport (); }
/*
else if (cmd.command == "import") { out = handleImport (); } else if (cmd.command == "import") { out = handleImport (); }
else if (cmd.command == "duplicate") { out = handleDuplicate (); } else if (cmd.command == "duplicate") { out = handleDuplicate (); }
else if (cmd.command == "edit") { out = handleEdit (); } else if (cmd.command == "edit") { out = handleEdit (); }

View file

@ -298,8 +298,36 @@ void Task::legacyParse (const std::string& line)
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string Task::composeCSV () std::string Task::composeCSV ()
{ {
throw std::string ("unimplemented Task::composeCSV"); std::stringstream out;
return "";
out << "'" << id << "',";
out << "'" << get ("uuid") << "',";
out << "'" << get ("status") << "',";
// Tags
std::vector <std::string> tags;
getTags (tags);
std::string allTags;
join (allTags, " ", tags);
out << "'" << allTags << "',";
out << "'" << get ("entry") << "',";
out << "'" << get ("start") << "',";
out << "'" << get ("due") << "',";
out << "'" << get ("recur") << "',";
out << "'" << get ("end") << "',";
out << "'" << get ("project") << "',";
out << "'" << get ("priority") << "',";
out << "'" << get ("fg") << "',";
out << "'" << get ("bg") << "',";
// Convert single quotes to double quotes, because single quotes are used to
// delimit the values that need it.
std::string clean = get ("description");
std::replace (clean.begin (), clean.end (), '\'', '"');
out << "'" << clean << "'\n";
return out.str ();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -639,18 +639,8 @@ std::string handleDone ()
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
std::string handleExport () std::string handleExport ()
{ {
std::stringstream output; std::stringstream out;
/*
// Use the description as a file name, then clobber the description so the
// file name isn't used for filtering.
std::string file = trim (task.getDescription ());
task.setDescription ("");
if (file.length () > 0)
{
std::ofstream out (file.c_str ());
if (out.good ())
{
out << "'id'," out << "'id',"
<< "'uuid'," << "'uuid',"
<< "'status'," << "'status',"
@ -668,29 +658,25 @@ std::string handleExport ()
<< "\n"; << "\n";
int count = 0; int count = 0;
std::vector <T> all;
tdb.allPendingT (all); // Get all the tasks.
filter (all, task); std::vector <Task> tasks;
foreach (t, all) context.tdb.lock (context.config.get ("locking", true));
context.tdb.loadPending (tasks, context.filter);
context.tdb.unlock ();
// TODO handleRecurrence (tdb, tasks);
foreach (task, tasks)
{ {
if (t->getStatus () != T::recurring && if (task->getStatus () != Task::recurring &&
t->getStatus () != T::deleted) task->getStatus () != Task::deleted)
{ {
out << t->composeCSV ().c_str (); out << task->composeCSV ().c_str ();
++count; ++count;
} }
} }
out.close ();
output << count << " tasks exported to '" << file << "'" << std::endl; return out.str ();
}
else
throw std::string ("Could not write to export file.");
}
else
throw std::string ("You must specify a file to write to.");
*/
return output.str ();
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////

View file

@ -174,7 +174,7 @@ std::string shortUsage ()
row = table.addRow (); row = table.addRow ();
table.addCell (row, 1, "task export"); table.addCell (row, 1, "task export");
table.addCell (row, 2, "Exports all tasks as a CSV file"); table.addCell (row, 2, "Lists all tasks as a CSV file");
row = table.addRow (); row = table.addRow ();
table.addCell (row, 1, "task color"); table.addCell (row, 1, "task color");
@ -274,6 +274,7 @@ std::string handleInfo ()
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.get ("locking", true));
context.tdb.loadPending (tasks, context.filter); context.tdb.loadPending (tasks, context.filter);
context.tdb.unlock (); context.tdb.unlock ();
// TODO handleRecurrence (tdb, tasks);
// Filter sequence. // Filter sequence.
context.filter.applySequence (tasks, context.sequence); context.filter.applySequence (tasks, context.sequence);
@ -1615,6 +1616,7 @@ std::string handleReportStats ()
context.tdb.lock (context.config.get ("locking", true)); context.tdb.lock (context.config.get ("locking", true));
context.tdb.load (tasks, context.filter); context.tdb.load (tasks, context.filter);
context.tdb.unlock (); context.tdb.unlock ();
// TODO handleRecurrence (tdb, tasks);
Date now; Date now;
time_t earliest = time (NULL); time_t earliest = time (NULL);