- Removed support for the "command.logging" configuration variable and

the "task usage" command.
This commit is contained in:
Paul Beckingham 2008-09-20 20:46:20 -04:00
parent 78fae5195b
commit d837a25be7
12 changed files with 6 additions and 171 deletions

View file

@ -112,7 +112,6 @@ void Config::createDefault (const std::string& home)
if ((out = fopen (rcFile.c_str (), "w")))
{
fprintf (out, "data.location=%s\n", dataDir.c_str ());
fprintf (out, "command.logging=off\n");
fprintf (out, "confirmation=yes\n");
fprintf (out, "next=2\n");
fprintf (out, "dateformat=m/d/Y\n");

View file

@ -37,7 +37,6 @@
TDB::TDB ()
: mPendingFile ("")
, mCompletedFile ("")
, mLogFile ("")
, mId (1)
{
}
@ -54,7 +53,6 @@ void TDB::dataDirectory (const std::string& directory)
{
mPendingFile = directory + "/pending.data";
mCompletedFile = directory + "/completed.data";
mLogFile = directory + "/command.log";
}
else
{
@ -286,58 +284,6 @@ bool TDB::modifyT (const T& t)
return overwritePending (pending);
}
////////////////////////////////////////////////////////////////////////////////
bool TDB::logRead (std::vector <std::string>& entries) const
{
entries.clear ();
return readLockedFile (mLogFile, entries);
}
////////////////////////////////////////////////////////////////////////////////
bool TDB::logCommand (int argc, char** argv) const
{
// Get time info.
time_t now;
time (&now);
struct tm* t = localtime (&now);
// Generate timestamp.
char timestamp[20];
sprintf (timestamp, "%04d-%02d-%02d %02d:%02d:%02d",
t->tm_year + 1900,
t->tm_mon + 1,
t->tm_mday,
t->tm_hour,
t->tm_min,
t->tm_sec);
std::string command = timestamp;
command += " \"";
for (int i = 0; i < argc; ++i)
command += std::string (i ? " " : "") + argv[i];
command += "\"\n";
if (! access (mLogFile.c_str (), F_OK | W_OK))
{
FILE* out;
if ((out = fopen (mLogFile.c_str (), "a")))
{
#ifdef HAVE_FLOCK
int retry = 0;
while (flock (fileno (out), LOCK_EX) && ++retry <= 3)
delay (0.25);
#endif
fputs (command.c_str (), out);
fclose (out);
return true;
}
}
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool TDB::lock (FILE* file) const
{

View file

@ -48,7 +48,6 @@ public:
bool addT (const T&) const;
bool modifyT (const T&);
bool logRead (std::vector <std::string>&) const;
bool logCommand (int, char**) const;
int gc ();
int nextId ();
@ -62,7 +61,6 @@ private:
private:
std::string mPendingFile;
std::string mCompletedFile;
std::string mLogFile;
int mId;
};

View file

@ -142,7 +142,6 @@ static const char* commands[] =
"tags",
"undelete",
"undo",
"usage",
"version",
"",
};

View file

@ -1594,81 +1594,6 @@ void handleReportGHistory (TDB& tdb, T& task, Config& conf)
std::cout << "No tasks." << std::endl;
}
////////////////////////////////////////////////////////////////////////////////
// A summary of the command usage. Not useful to users, but used to display
// usage statistics for feedback.
//
// 2006-12-04 19:59:43 "task list"
//
void handleReportUsage (const TDB& tdb, T& task, Config& conf)
{
if (conf.get ("command.logging") == "on")
{
std::map <std::string, int> usage;
std::vector <std::string> all;
tdb.logRead (all);
for (unsigned int i = 0; i < all.size (); ++i)
{
// 0123456789012345678901
// v 21
// 2006-12-04 19:59:43 "task list"
std::string command = all[i].substr (21, all[i].length () - 22);
// Parse as a command line.
std::vector <std::string> args;
split (args, command, " ");
try
{
T task;
std::string commandName;
parse (args, commandName, task, conf);
usage[commandName]++;
}
// Deliberately ignore errors from parsing the command log, as there may
// be commands from a prior version of task in there, which were
// abbreviated, and are now ambiguous.
catch (...) {}
}
// Now render the table.
Table table;
table.addColumn ("Command");
table.addColumn ("Frequency");
if (conf.get ("color", true))
{
table.setColumnUnderline (0);
table.setColumnUnderline (1);
}
else
table.setTableDashedUnderline ();
table.setColumnJustification (1, Table::right);
table.sortOn (1, Table::descendingNumeric);
table.setDateFormat (conf.get ("dateformat", "m/d/Y"));
foreach (i, usage)
{
int row = table.addRow ();
table.addCell (row, 0, (i->first == "" ? "(modify)" : i->first));
table.addCell (row, 1, i->second);
}
if (table.rowCount ())
std::cout << optionalBlankLine (conf)
<< table.render ()
<< std::endl;
else
std::cout << "No usage." << std::endl;
}
else
std::cout << "Command logging is not enabled, so no history has been kept."
<< std::endl;
}
////////////////////////////////////////////////////////////////////////////////
std::string renderMonths (
int firstMonth,

View file

@ -178,10 +178,6 @@ static void shortUsage (Config& conf)
table.addCell (row, 1, "task stats");
table.addCell (row, 2, "Shows task database statistics");
row = table.addRow ();
table.addCell (row, 1, "task usage");
table.addCell (row, 2, "Shows task command usage frequency");
row = table.addRow ();
table.addCell (row, 1, "task export");
table.addCell (row, 2, "Exports all tasks as a CSV file");
@ -296,10 +292,6 @@ int main (int argc, char** argv)
TDB tdb;
tdb.dataDirectory (expandPath (conf.get ("data.location")));
// Log commands, if desired.
if (conf.get ("command.logging") == "on")
tdb.logCommand (argc, argv);
// If argc == 1 and the default.command configuration variable is set,
// then use that, otherwise stick with argc/argv.
std::vector <std::string> args;
@ -347,7 +339,6 @@ int main (int argc, char** argv)
else if (command == "oldest") handleReportOldest (tdb, task, conf);
else if (command == "newest") handleReportNewest (tdb, task, conf);
else if (command == "stats") handleReportStats (tdb, task, conf);
else if (command == "usage") handleReportUsage (tdb, task, conf);
else if (command == "" && task.getId ()) handleModify (tdb, task, conf);
else if (command == "help") longUsage (conf);
else shortUsage (conf);

View file

@ -92,7 +92,6 @@ void handleReportSummary (TDB&, T&, Config&);
void handleReportNext (TDB&, T&, Config&);
void handleReportHistory (TDB&, T&, Config&);
void handleReportGHistory (TDB&, T&, Config&);
void handleReportUsage (const TDB&, T&, Config&);
void handleReportCalendar (TDB&, T&, Config&);
void handleReportActive (TDB&, T&, Config&);
void handleReportOverdue (TDB&, T&, Config&);