- Adds a new 'initialize' synchronize command argument that uploads all pending
  tasks for first-time initialization.
This commit is contained in:
Paul Beckingham 2013-06-08 18:00:50 -04:00
parent f13208479d
commit 14d3fd00e3
7 changed files with 46 additions and 13 deletions

View file

@ -14,6 +14,8 @@ Features
+ #1256 Supports default values for UDA fields (thanks to Thomas Sullivan). + #1256 Supports default values for UDA fields (thanks to Thomas Sullivan).
+ Stores un-synched transactions in <data.location>/backlog.data. + Stores un-synched transactions in <data.location>/backlog.data.
+ Adds a new 'synchronize' command to sync data with a task server. + Adds a new 'synchronize' command to sync data with a task server.
+ Adds a new 'initialize' synchronize command argument that uploads all pending
tasks for first-time initialization.
+ Adds a new 'sync' verbosity token, which will remind when a backlog builds + Adds a new 'sync' verbosity token, which will remind when a backlog builds
up and needs a sync. up and needs a sync.
+ Supports IPv4 and IPv6 server addresses. + Supports IPv4 and IPv6 server addresses.

View file

@ -340,7 +340,7 @@ need to retype the URI every time. You can also use this configuration scheme
to set alias names, e.g. set pull.desktop.uri and run 'task pull desktop'. to set alias names, e.g. set pull.desktop.uri and run 'task pull desktop'.
.RE .RE
Note that, when using SSH/scp, hostnames will be expanded due to the ssh Note that, when using SSH/scp, hostnames will be expanded due to the ssh
configuration file ~/.ssh/config. configuration file ~/.ssh/config.
.SH EXTERNAL DEPENDENCIES .SH EXTERNAL DEPENDENCIES

View file

@ -33,6 +33,7 @@
#include <TLSClient.h> #include <TLSClient.h>
#include <Color.h> #include <Color.h>
#include <text.h> #include <text.h>
#include <util.h>
#include <i18n.h> #include <i18n.h>
#include <CmdSync.h> #include <CmdSync.h>
@ -42,7 +43,7 @@ extern Context context;
CmdSync::CmdSync () CmdSync::CmdSync ()
{ {
_keyword = "synchronize"; _keyword = "synchronize";
_usage = "task synchronize"; _usage = "task synchronize [initialize]";
_description = STRING_CMD_SYNC_USAGE; _description = STRING_CMD_SYNC_USAGE;
_read_only = false; _read_only = false;
_displays_id = false; _displays_id = false;
@ -58,6 +59,22 @@ int CmdSync::execute (std::string& output)
std::stringstream out; std::stringstream out;
// Loog for the 'init' keyword to indicate one-time pending.data upload.
bool first_time_init = false;
std::vector <std::string> words = context.a3.extract_words ();
std::vector <std::string>::iterator word;
for (word = words.begin (); word != words.end (); ++word)
{
if (closeEnough ("initialize", *word, 4))
{
if (!context.config.getBoolean ("confirmation") ||
confirm (STRING_CMD_SYNC_INIT))
first_time_init = true;
else
throw std::string (STRING_CMD_SYNC_NO_INIT);
}
}
// If no server is set up, quit. // If no server is set up, quit.
std::string connection = context.config.get ("taskd.server"); std::string connection = context.config.get ("taskd.server");
if (connection == "" || if (connection == "" ||
@ -78,21 +95,30 @@ int CmdSync::execute (std::string& output)
if (certificate == "") if (certificate == "")
throw std::string (STRING_CMD_SYNC_BAD_CERT); throw std::string (STRING_CMD_SYNC_BAD_CERT);
// Read backlog.data. // If this is a first-time initialization, send pending.data, not
// backlog.data.
std::string payload = ""; std::string payload = "";
File backlog (context.config.get ("data.location") + "/backlog.data");
if (backlog.exists ())
backlog.read (payload);
// Count the number of tasks being uploaded.
int upload_count = 0; int upload_count = 0;
if (first_time_init)
{ {
std::vector <std::string> lines; std::vector <Task> pending = context.tdb2.pending.get_tasks ();
split (lines, payload, "\n"); std::vector <Task>::iterator i;
for (i = pending.begin (); i != pending.end (); ++i)
{
payload += i->composeJSON () + "\n";
++upload_count;
}
}
else
{
std::vector <std::string> lines = context.tdb2.backlog.get_lines ();
std::vector <std::string>::iterator i; std::vector <std::string>::iterator i;
for (i = lines.begin (); i != lines.end (); ++i) for (i = lines.begin (); i != lines.end (); ++i)
if ((*i)[0] == '{') if ((*i)[0] == '{')
{
payload += *i + "\n";
++upload_count; ++upload_count;
}
} }
// Send 'sync' + payload. // Send 'sync' + payload.
@ -103,8 +129,6 @@ int CmdSync::execute (std::string& output)
request.set ("user", credentials[1]); request.set ("user", credentials[1]);
request.set ("key", credentials[2]); request.set ("key", credentials[2]);
// TODO Add the other necessary header fields.
request.setPayload (payload); request.setPayload (payload);
out << format (STRING_CMD_SYNC_PROGRESS, connection) out << format (STRING_CMD_SYNC_PROGRESS, connection)

View file

@ -418,6 +418,8 @@
#define STRING_CMD_SYNC_FAIL_CONNECT "Sync failed. Could not connect to the Task Server." #define STRING_CMD_SYNC_FAIL_CONNECT "Sync failed. Could not connect to the Task Server."
#define STRING_CMD_SYNC_BAD_SERVER "Sync failed. Malformed configuration setting '{1}'" #define STRING_CMD_SYNC_BAD_SERVER "Sync failed. Malformed configuration setting '{1}'"
#define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." #define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available."
#define STRING_CMD_SYNC_INIT "Please confirm that you wish to upload all your pending tasks to the Task Server?"
#define STRING_CMD_SYNC_NO_INIT "Taskwarrior will not proceed with first-time sync initialization."
#define STRING_CMD_DIAG_USAGE "Platform, build and environment details" #define STRING_CMD_DIAG_USAGE "Platform, build and environment details"
#define STRING_CMD_DIAG_PLATFORM "Platform" #define STRING_CMD_DIAG_PLATFORM "Platform"
#define STRING_CMD_DIAG_UNKNOWN "<unknown>" #define STRING_CMD_DIAG_UNKNOWN "<unknown>"

View file

@ -429,7 +429,8 @@
#define STRING_CMD_SYNC_FAIL_CONNECT "Sincronización fallida. No se pudo conectar con el Servidor Task." #define STRING_CMD_SYNC_FAIL_CONNECT "Sincronización fallida. No se pudo conectar con el Servidor Task."
#define STRING_CMD_SYNC_BAD_SERVER "Sincronización fallida. Ajuste de configuración '{1}' incorrecto" #define STRING_CMD_SYNC_BAD_SERVER "Sincronización fallida. Ajuste de configuración '{1}' incorrecto"
#define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." #define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available."
#define STRING_CMD_SYNC_INIT "Please confirm that you wish to upload all your pending tasks to the Task Server?"
#define STRING_CMD_SYNC_NO_INIT "Taskwarrior will not proceed with first-time sync initialization."
#define STRING_CMD_DIAG_USAGE "Detalles de plataforma, construcción y entorno" #define STRING_CMD_DIAG_USAGE "Detalles de plataforma, construcción y entorno"
#define STRING_CMD_DIAG_PLATFORM "Plataforma" #define STRING_CMD_DIAG_PLATFORM "Plataforma"
#define STRING_CMD_DIAG_UNKNOWN "<desconocido>" #define STRING_CMD_DIAG_UNKNOWN "<desconocido>"

View file

@ -418,6 +418,8 @@
#define STRING_CMD_SYNC_FAIL_CONNECT "Sync failed. Could not connect to the Task Server." #define STRING_CMD_SYNC_FAIL_CONNECT "Sync failed. Could not connect to the Task Server."
#define STRING_CMD_SYNC_BAD_SERVER "Sync failed. Malformed configuration setting '{1}'" #define STRING_CMD_SYNC_BAD_SERVER "Sync failed. Malformed configuration setting '{1}'"
#define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." #define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available."
#define STRING_CMD_SYNC_INIT "Please confirm that you wish to upload all your pending tasks to the Task Server?"
#define STRING_CMD_SYNC_NO_INIT "Taskwarrior will not proceed with first-time sync initialization."
#define STRING_CMD_DIAG_USAGE "Platform, build and environment details" #define STRING_CMD_DIAG_USAGE "Platform, build and environment details"
#define STRING_CMD_DIAG_PLATFORM "Platform" #define STRING_CMD_DIAG_PLATFORM "Platform"
#define STRING_CMD_DIAG_UNKNOWN "<unknown>" #define STRING_CMD_DIAG_UNKNOWN "<unknown>"

View file

@ -419,6 +419,8 @@
#define STRING_CMD_SYNC_FAIL_CONNECT "Sincronizzazione fallita. Impossibile connettersi al Task Server." #define STRING_CMD_SYNC_FAIL_CONNECT "Sincronizzazione fallita. Impossibile connettersi al Task Server."
#define STRING_CMD_SYNC_BAD_SERVER "Sincronizzazione fallita. Impostazione di configurazione '{1}' malformata" #define STRING_CMD_SYNC_BAD_SERVER "Sincronizzazione fallita. Impostazione di configurazione '{1}' malformata"
#define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available." #define STRING_CMD_SYNC_NO_TLS "Taskwarrior was built without GnuTLS support. Sync is not available."
#define STRING_CMD_SYNC_INIT "Please confirm that you wish to upload all your pending tasks to the Task Server?"
#define STRING_CMD_SYNC_NO_INIT "Taskwarrior will not proceed with first-time sync initialization."
#define STRING_CMD_DIAG_USAGE "Dettagli su piattaforma, build e ambiente" #define STRING_CMD_DIAG_USAGE "Dettagli su piattaforma, build e ambiente"
#define STRING_CMD_DIAG_PLATFORM "Piattaforma" #define STRING_CMD_DIAG_PLATFORM "Piattaforma"
#define STRING_CMD_DIAG_UNKNOWN "<sconoscito>" #define STRING_CMD_DIAG_UNKNOWN "<sconoscito>"