mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
Sync
- Added server credential handling. - Added server error handling. - Added task download handling. - Added backlog truncation and synch_key handling. - Added display of server-side messages. - Cleaned up NEWS file for 2.3.0. - Removed duplicate info in diagnostics command output.
This commit is contained in:
parent
27df379f1d
commit
9cbd729553
4 changed files with 60 additions and 26 deletions
|
@ -95,9 +95,6 @@ int CmdDiagnostics::execute (std::string& output)
|
|||
#else
|
||||
STRING_CMD_DIAG_UNKNOWN
|
||||
#endif
|
||||
<< "\n"
|
||||
<< STRING_CMD_DIAG_SERVER << ": "
|
||||
<< context.config.get ("taskd.server")
|
||||
<< "\n\n";
|
||||
|
||||
// Compiler.
|
||||
|
|
|
@ -59,7 +59,11 @@ int CmdSync::execute (std::string& output)
|
|||
throw std::string (STRING_CMD_SYNC_NO_SERVER);
|
||||
|
||||
// Obtain credentials.
|
||||
std::string credentials = context.config.get ("taskd.credentials");
|
||||
std::string credentials_string = context.config.get ("taskd.credentials");
|
||||
std::vector <std::string> credentials;
|
||||
split (credentials, credentials_string, "/");
|
||||
if (credentials.size () != 3)
|
||||
throw std::string (STRING_CMD_SYNC_BAD_CRED);
|
||||
|
||||
// Read backlog.data.
|
||||
std::string payload = "";
|
||||
|
@ -70,6 +74,10 @@ int CmdSync::execute (std::string& output)
|
|||
// Send 'sync' + payload.
|
||||
Msg request, response;
|
||||
request.set ("type", "sync");
|
||||
request.set ("org", credentials[0]);
|
||||
request.set ("user", credentials[1]);
|
||||
request.set ("key", credentials[2]);
|
||||
|
||||
// TODO Add the other header fields.
|
||||
|
||||
request.setPayload (payload);
|
||||
|
@ -81,22 +89,29 @@ int CmdSync::execute (std::string& output)
|
|||
{
|
||||
std::cout << "# response:\n"
|
||||
<< response.serialize ();
|
||||
if (response.get ("code") == "200")
|
||||
std::string code = response.get ("code");
|
||||
if (code == "200")
|
||||
{
|
||||
payload = response.getPayload ();
|
||||
std::vector <std::string> lines;
|
||||
split (lines, payload, '\n');
|
||||
std::cout << "# received " << lines.size () << " lines of data\n";
|
||||
|
||||
// TODO Load all tasks.
|
||||
// Load all tasks.
|
||||
std::vector <Task> all = context.tdb2.all_tasks ();
|
||||
|
||||
std::string synch_key;
|
||||
std::string synch_key = "";
|
||||
std::vector <std::string>::iterator line;
|
||||
for (line = lines.begin (); line != lines.end (); ++line)
|
||||
{
|
||||
if ((*line)[0] == '[')
|
||||
{
|
||||
// TODO Apply tasks.
|
||||
std::cout << "# task: " << *line << "\n";
|
||||
Task from_server (*line);
|
||||
std::cout << " " << from_server.get ("uuid")
|
||||
<< " " << from_server.get ("description")
|
||||
<< "\n";
|
||||
context.tdb2.modify (from_server);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -105,19 +120,47 @@ int CmdSync::execute (std::string& output)
|
|||
}
|
||||
}
|
||||
|
||||
// TODO Truncate backlog.data.
|
||||
// TODO Store new synch key.
|
||||
// Only update everything if there is a new synch_key. No synch_key means
|
||||
// something horrible happened on the other end of the wire.
|
||||
if (synch_key != "")
|
||||
{
|
||||
// Truncate backlog.data, save new synch_key.
|
||||
context.tdb2.backlog.clear ();
|
||||
context.tdb2.backlog.add_line (synch_key + "\n");
|
||||
|
||||
// TODO Commit.
|
||||
// Commit all changes.
|
||||
context.tdb2.commit ();
|
||||
}
|
||||
}
|
||||
else if (code == "430")
|
||||
{
|
||||
context.error ("Not authorized. Could be incorrect credentials or "
|
||||
"server account not enabled.");
|
||||
status = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
context.error ("Task Server problem.");
|
||||
context.error ("Task Server error: " + code + " " + response.get ("status"));
|
||||
status = 2;
|
||||
}
|
||||
|
||||
// TODO Display all errors returned.
|
||||
// Display all errors returned. This is required by the server protocol.
|
||||
std::string to_be_displayed = response.get ("messages");
|
||||
if (to_be_displayed != "")
|
||||
{
|
||||
if (context.verbose ("footnote"))
|
||||
context.footnote (to_be_displayed);
|
||||
else
|
||||
context.debug (to_be_displayed);
|
||||
}
|
||||
}
|
||||
|
||||
// Some kind of low-level error:
|
||||
// - Server down
|
||||
// - Wrong address
|
||||
// - Wrong port
|
||||
// - Firewall
|
||||
// - Network error
|
||||
else
|
||||
{
|
||||
context.error ("Could not connect to Task Server.");
|
||||
|
|
|
@ -412,6 +412,7 @@
|
|||
#define STRING_CMD_SHELL_HELP3 "Enter 'quit' (or 'bye', 'exit') to end the session."
|
||||
#define STRING_CMD_SYNC_USAGE "Synchronizes data with the Task Server"
|
||||
#define STRING_CMD_SYNC_NO_SERVER "Task Server is not configured."
|
||||
#define STRING_CMD_SYNC_BAD_CRED "Task Server credentials malformed."
|
||||
#define STRING_CMD_DIAG_USAGE "Platform, build and environment details"
|
||||
#define STRING_CMD_DIAG_PLATFORM "Platform"
|
||||
#define STRING_CMD_DIAG_UNKNOWN "<unknown>"
|
||||
|
@ -434,7 +435,6 @@
|
|||
#define STRING_CMD_DIAG_UUID_SCAN "Scanned {1} tasks for duplicate UUIDs:"
|
||||
#define STRING_CMD_DIAG_UUID_DUP "Found duplicate {1}"
|
||||
#define STRING_CMD_DIAG_UUID_NO_DUP "No duplicates found"
|
||||
#define STRING_CMD_DIAG_SERVER "Task Server"
|
||||
#define STRING_CMD_DIAG_NONE "-none-"
|
||||
#define STRING_CMD_PUSH_USAGE "Pushes the local files to the URL"
|
||||
#define STRING_CMD_PUSH_SAME "Cannot push files when the source and destination are the same."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue