*
* wxbPanel for restoring files
*
- * Nicolas Boichat, April-May 2004
+ * Nicolas Boichat, April-July 2004
*
+ * Version $Id$
*/
/*
Copyright (C) 2004 Kern Sibbald and John Walker
unsigned int i;
if (status == activable) {
wxbMainFrame::GetInstance()->SetStatusText("Getting parameters list.");
- wxbDataTokenizer* dt = WaitForEnd(".clients\n", true, false);
+ wxbDataTokenizer* dt = wxbUtils::WaitForEnd(".clients\n", true, false);
wxString str;
configPanel->ClearRowChoices("Client");
return;
}
- dt = WaitForEnd(".filesets\n", true, false);
+ dt = wxbUtils::WaitForEnd(".filesets\n", true, false);
configPanel->ClearRowChoices("Fileset");
restorePanel->ClearRowChoices("Fileset");
return;
}
- dt = WaitForEnd(".storage\n", true, false);
+ dt = wxbUtils::WaitForEnd(".storage\n", true, false);
configPanel->ClearRowChoices("Storage");
restorePanel->ClearRowChoices("Storage");
return;
}
- dt = WaitForEnd(".jobs\n", true, false);
+ dt = wxbUtils::WaitForEnd(".jobs\n", true, false);
configPanel->ClearRowChoices("Job Name");
return;
}
- dt = WaitForEnd(".pools\n", true, false);
+ dt = wxbUtils::WaitForEnd(".pools\n", true, false);
configPanel->ClearRowChoices("Pool");
SetStatus(choosing);
- WaitForPrompt(wxString("restore") <<
+ wxbTableParser* tableparser = new wxbTableParser();
+ wxbDataTokenizer* dt = new wxbDataTokenizer(true);
+
+ wxbMainFrame::GetInstance()->Send(wxString("restore") <<
" client=\"" << configPanel->GetRowString("Client") <<
"\" fileset=\"" << configPanel->GetRowString("Fileset") <<
"\" pool=\"" << configPanel->GetRowString("Pool") <<
- "\" storage=\"" << configPanel->GetRowString("Storage") << "\"\n");
- WaitForPrompt("6\n");
+ "\" storage=\"" << configPanel->GetRowString("Storage") <<
+ "\" before=\"" << configPanel->GetRowString("Before") <<
+ "\" select\n");
+ //wxbUtils::WaitForPrompt("6\n");
//WaitForEnd();
- /*wxbPromptParser *pp = WaitForPrompt(wxString() << configPanel->GetRowString("Before") << "\n", true);
+ /*wxbPromptParser *pp = wxbUtils::WaitForPrompt(wxString() << configPanel->GetRowString("Before") << "\n", true);
int client = pp->getChoices()->Index(configPanel->GetRowString("Client"));
if (client == wxNOT_FOUND) {
wxbMainFrame::GetInstance()->SetStatusText("Failed to find the selected client.");
}
delete pp;*/
- wxbTableParser* tableparser = new wxbTableParser();
- wxbDataTokenizer* dt = new wxbDataTokenizer(true);
-
- wxbMainFrame::GetInstance()->Send(wxString() << configPanel->GetRowString("Before") << "\n");
+ //wxbMainFrame::GetInstance()->Send(wxString() << configPanel->GetRowString("Before") << "\n");
while (!tableparser->hasFinished() && !dt->hasFinished()) {
wxTheApp->Yield(true);
int var = 0;
- while (!dt->hasFinished()) {
+ int i1, i2;
+
+ while (true) {
newdate = wxDateTime::Now();
if (newdate.Subtract(base).GetMilliseconds() > 10 ) {
base = newdate;
for (; lastindex < dt->GetCount(); lastindex++) {
- if (((*dt)[lastindex].Find("Building directory tree for JobId ") == 0) &&
- ((i = (*dt)[lastindex].Find(" ...")) > 0)) {
- str = (*dt)[lastindex].Mid(34, i-34);
+ if (((i1 = (*dt)[lastindex].Find("Building directory tree for JobId ")) >= 0) &&
+ ((i2 = (*dt)[lastindex].Find(" ...")) > 0)) {
+ str = (*dt)[lastindex].Mid(i1+34, i2-(i1+34));
for (i = 0; i < tableparser->GetCount(); i++) {
if (str == (*tableparser)[i][0]) {
str = (*tableparser)[i][2];
gauge->SetValue(gauge->GetValue()+var);
+ if (dt->hasFinished()) {
+ break;
+ }
+
/*wxbMainFrame::GetInstance()->Print(
wxString("[") << gauge->GetValue() << "/" << done
<< "-" << willdo << "]", CS_DEBUG);*/
return;
}
- WaitForEnd("unmark *\n");
+ wxbUtils::WaitForEnd("unmark *\n");
wxTreeItemId root = tree->AddRoot(configPanel->GetRowString("Client"), -1, -1, new wxbTreeItemData("/", configPanel->GetRowString("Client"), 0));
currentTreeItem = root;
tree->Refresh();
int j;
dt = new wxbDataTokenizer(true);
- WaitForPrompt("done\n");
+ wxbUtils::WaitForPrompt("done\n");
SetStatus(configuring);
wxbDataTokenizer* dt;
SetStatus(restoring);
- WaitForEnd("yes\n");
+ wxbUtils::WaitForEnd("yes\n");
gauge->SetValue(0);
gauge->SetRange(totfilemessages);
wxDateTime currenttime;
- dt = WaitForEnd("time\n", true);
+ dt = wxbUtils::WaitForEnd("time\n", true);
wxStringTokenizer ttkz((*dt)[0], " ", wxTOKEN_STRTOK);
if ((currenttime.ParseDate(ttkz.GetNextToken()) == NULL) || // Date
(currenttime.ParseTime(ttkz.GetNextToken()) == NULL)) { // Time
wxbTableParser* tableparser;
while (true) {
- tableparser = CreateAndWaitForParser("list jobs\n");
+ tableparser = wxbUtils::CreateAndWaitForParser("list jobs\n");
wxDateTime jobtime;
- if (jobname == (*tableparser)[tableparser->GetCount()-1][1]) {
- wxStringTokenizer jtkz((*tableparser)[tableparser->GetCount()-1][2], " ", wxTOKEN_STRTOK);
- if ((jobtime.ParseDate(jtkz.GetNextToken()) != NULL) && // Date
- (jobtime.ParseTime(jtkz.GetNextToken()) != NULL)) { // Time
- if (jobtime.IsLaterThan(currenttime)) {
- jobid = (*tableparser)[tableparser->GetCount()-1][0];
- cmd << jobid << "\n";
- delete tableparser;
- cancel->Enable(true);
- break;
+ for (i = 0; i < tableparser->GetCount(); i++) {
+ if (jobname == (*tableparser)[i][1]) {
+ wxStringTokenizer jtkz((*tableparser)[i][2], " ", wxTOKEN_STRTOK);
+ if ((jobtime.ParseDate(jtkz.GetNextToken()) != NULL) && // Date
+ (jobtime.ParseTime(jtkz.GetNextToken()) != NULL)) { // Time
+ if (jobtime.IsLaterThan(currenttime)) {
+ jobid = (*tableparser)[i][0];
+ cmd << jobid << "\n";
+ delete tableparser;
+ tableparser = NULL;
+ cancel->Enable(true);
+ break;
+ }
}
}
}
+ if (tableparser == NULL) { //The job was found
+ break;
+ }
+
delete tableparser;
wxStopWatch sw2;
long filemessages = 0;
while (true) {
- tableparser = CreateAndWaitForParser(cmd);
+ tableparser = wxbUtils::CreateAndWaitForParser(cmd);
if ((*tableparser)[0][7] != "C") {
break;
}
delete tableparser;
- dt = WaitForEnd("messages\n", true);
+ dt = wxbUtils::WaitForEnd("messages\n", true);
for (unsigned int i = 0; i < dt->GetCount(); i++) {
wxStringTokenizer tkz((*dt)[i], " ", wxTOKEN_STRTOK);
}
}
- WaitForEnd("messages\n");
+ wxbUtils::WaitForEnd("messages\n");
gauge->SetValue(totfilemessages);
}
wxString def; //String to send if can't use our data
if ((cfgUpdated >> ConfigWhere) & 1) {
- WaitForPrompt("mod\n"); /* TODO: check results */
- WaitForPrompt("9\n");
+ wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
+ wxbUtils::WaitForPrompt("9\n");
dt = new wxbDataTokenizer(true);
- WaitForPrompt(restorePanel->GetRowString("Where") + "\n");
+ wxbUtils::WaitForPrompt(restorePanel->GetRowString("Where") + "\n");
def = "/tmp";
cfgUpdated = cfgUpdated & (~(1 << ConfigWhere));
}
else if ((cfgUpdated >> ConfigReplace) & 1) {
- WaitForPrompt("mod\n"); /* TODO: check results */
- WaitForPrompt("10\n");
+ wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
+ wxbUtils::WaitForPrompt("10\n");
dt = new wxbDataTokenizer(true);
- WaitForPrompt(wxString() << (restorePanel->GetRowSelection("Replace")+1) << "\n");
+ wxbUtils::WaitForPrompt(wxString() << (restorePanel->GetRowSelection("Replace")+1) << "\n");
def = "1";
cfgUpdated = cfgUpdated & (~(1 << ConfigReplace));
}
else if ((cfgUpdated >> ConfigWhen) & 1) {
- WaitForPrompt("mod\n"); /* TODO: check results */
- WaitForPrompt("6\n");
+ wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
+ wxbUtils::WaitForPrompt("6\n");
dt = new wxbDataTokenizer(true);
- WaitForPrompt(restorePanel->GetRowString("When") + "\n");
+ wxbUtils::WaitForPrompt(restorePanel->GetRowString("When") + "\n");
def = "";
cfgUpdated = cfgUpdated & (~(1 << ConfigWhen));
}
else if ((cfgUpdated >> ConfigPriority) & 1) {
- WaitForPrompt("mod\n"); /* TODO: check results */
- WaitForPrompt("7\n");
+ wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
+ wxbUtils::WaitForPrompt("7\n");
dt = new wxbDataTokenizer(true);
- WaitForPrompt(restorePanel->GetRowString("Priority") + "\n");
+ wxbUtils::WaitForPrompt(restorePanel->GetRowString("Priority") + "\n");
def = "10";
cfgUpdated = cfgUpdated & (~(1 << ConfigPriority));
}
else if ((cfgUpdated >> ConfigClient) & 1) {
- WaitForPrompt("mod\n"); /* TODO: check results */
- wxbPromptParser *pp = WaitForPrompt("5\n", true);
+ wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
+ wxbPromptParser *pp = wxbUtils::WaitForPrompt("5\n", true);
int client = pp->getChoices()->Index(restorePanel->GetRowString("Client"));
if (client == wxNOT_FOUND) {
wxbMainFrame::GetInstance()->SetStatusText("Failed to find the selected client.");
}
delete pp;
dt = new wxbDataTokenizer(true);
- WaitForPrompt(wxString() << client << "\n");
+ wxbUtils::WaitForPrompt(wxString() << client << "\n");
def = "1";
cfgUpdated = cfgUpdated & (~(1 << ConfigClient));
}
else if ((cfgUpdated >> ConfigFileset) & 1) {
- WaitForPrompt("mod\n"); /* TODO: check results */
- wxbPromptParser *pp = WaitForPrompt("4\n", true);
+ wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
+ wxbPromptParser *pp = wxbUtils::WaitForPrompt("4\n", true);
int fileset = pp->getChoices()->Index(restorePanel->GetRowString("Fileset"));
if (fileset == wxNOT_FOUND) {
wxbMainFrame::GetInstance()->SetStatusText("Failed to find the selected fileset.");
}
delete pp;
dt = new wxbDataTokenizer(true);
- WaitForPrompt(wxString() << fileset << "\n");
+ wxbUtils::WaitForPrompt(wxString() << fileset << "\n");
def = "1";
cfgUpdated = cfgUpdated & (~(1 << ConfigFileset));
}
else if ((cfgUpdated >> ConfigStorage) & 1) {
- WaitForPrompt("mod\n"); /* TODO: check results */
- wxbPromptParser *pp = WaitForPrompt("2\n", true);
+ wxbUtils::WaitForPrompt("mod\n"); /* TODO: check results */
+ wxbPromptParser *pp = wxbUtils::WaitForPrompt("2\n", true);
int fileset = pp->getChoices()->Index(restorePanel->GetRowString("Storage"));
if (fileset == wxNOT_FOUND) {
wxbMainFrame::GetInstance()->SetStatusText("Failed to find the selected storage.");
}
delete pp;
dt = new wxbDataTokenizer(true);
- WaitForPrompt(wxString() << fileset << "\n");
+ wxbUtils::WaitForPrompt(wxString() << fileset << "\n");
def = "1";
cfgUpdated = cfgUpdated & (~(1 << ConfigFileset));
}
if (i == dt->GetCount()) {
delete dt;
- dt = WaitForEnd(def + "\n", true);
+ dt = wxbUtils::WaitForEnd(def + "\n", true);
failed = true;
}
}
/* Cancel restore */
void wxbRestorePanel::CmdConfigCancel() {
- WaitForEnd("no\n");
+ wxbUtils::WaitForEnd("no\n");
wxbMainFrame::GetInstance()->Print("Restore cancelled.\n", CS_DEBUG);
wxbMainFrame::GetInstance()->SetStatusText("Restore cancelled.");
SetStatus(finished);
void wxbRestorePanel::CmdListJobs() {
if (status == entered) {
configPanel->ClearRowChoices("Before");
- WaitForPrompt("query\n");
- WaitForPrompt("6\n");
- wxbTableParser* tableparser = CreateAndWaitForParser(configPanel->GetRowString("Client") + "\n");
+ wxbUtils::WaitForPrompt("query\n");
+ wxbUtils::WaitForPrompt("6\n");
+ wxbTableParser* tableparser = new wxbTableParser();
+ wxbDataTokenizer* dt = wxbUtils::WaitForEnd(configPanel->GetRowString("Client") + "\n", true);
+
+ if (!tableparser->hasFinished()) {
+ for (unsigned int i = 0; i < dt->Count(); i++) {
+ if ((*dt)[i].Find("No results to list.") == 0) {
+ configPanel->AddRowChoice("Before", "No backup found for this client.");
+ configPanel->SetRowSelection("Before", 0);
+ configPanel->EnableApply(true); // Enabling the not existing apply button disables the ok button.
+ delete tableparser;
+ delete dt;
+ return;
+ }
+ else if (((*dt)[i].Find("ERROR") > -1) || ((*dt)[i].Find("Query failed") > -1)) {
+ configPanel->AddRowChoice("Before", "Cannot get previous backups list, see console.");
+ configPanel->SetRowSelection("Before", 0);
+ configPanel->EnableApply(true); // Enabling the not existing apply button disables the ok button.
+ delete tableparser;
+ delete dt;
+ return;
+ }
+ }
+ }
+
+ while (!tableparser->hasFinished()) {
+ wxTheApp->Yield(true);
+ ::wxUsleep(100);
+ }
+
+ delete dt;
for (int i = tableparser->GetCount()-1; i > -1; i--) {
wxString str = (*tableparser)[i][3];
jobChoice->Append("Invalid");
}*/
}
-
+
delete tableparser;
configPanel->SetRowSelection("Before", 0);
+ configPanel->EnableApply(false); // Disabling the not existing apply button enables the ok button.
}
}
}
}
- WaitForEnd(wxString("cd \"") << dir << "\"\n");
- WaitForEnd(wxString((state==1) ? "mark" : "unmark") << " \"" << file << "\"\n");
+ wxbUtils::WaitForEnd(wxString("cd \"") << dir << "\"\n");
+ wxbUtils::WaitForEnd(wxString((state==1) ? "mark" : "unmark") << " \"" << file << "\"\n");
/* TODO: Check commands results */
General functions
----------------------------------------------------------------------------*/
-/* Parse a table in tableParser */
-wxbTableParser* wxbRestorePanel::CreateAndWaitForParser(wxString cmd) {
- wxbTableParser* tableParser = new wxbTableParser();
-
- wxbMainFrame::GetInstance()->Send(cmd);
-
- //time_t base = wxDateTime::Now().GetTicks();
- while (!tableParser->hasFinished()) {
- //innerThread->Yield();
- wxTheApp->Yield(true);
- ::wxUsleep(100);
- //if (base+15 < wxDateTime::Now().GetTicks()) break;
- }
- return tableParser;
-}
-
-/* Run a command, and waits until prompt result is fully received,
- * if keepresults is true, returns a valid pointer to a wxbPromptParser
- * containing the data. */
-wxbPromptParser* wxbRestorePanel::WaitForPrompt(wxString cmd, bool keepresults) {
- wxbPromptParser* promptParser = new wxbPromptParser();
-
- wxbMainFrame::GetInstance()->Send(cmd);
-
- //time_t base = wxDateTime::Now().GetTicks();
- while (!promptParser->hasFinished()) {
- //innerThread->Yield();
- wxTheApp->Yield(true);
- ::wxUsleep(100);
- //if (base+15 < wxDateTime::Now().GetTicks()) break;
- }
-
- if (keepresults) {
- return promptParser;
- }
- else {
- delete promptParser;
- return NULL;
- }
-}
-
-/* Run a command, and waits until result is fully received. */
-wxbDataTokenizer* wxbRestorePanel::WaitForEnd(wxString cmd, bool keepresults, bool linebyline) {
- wxbDataTokenizer* datatokenizer = new wxbDataTokenizer(linebyline);
-
- wxbMainFrame::GetInstance()->Send(cmd);
-
- //wxbMainFrame::GetInstance()->Print("(<WFE)", CS_DEBUG);
-
- //time_t base = wxDateTime::Now().GetTicks();
- while (!datatokenizer->hasFinished()) {
- //innerThread->Yield();
- wxTheApp->Yield(true);
- ::wxUsleep(100);
- //if (base+15 < wxDateTime::Now().GetTicks()) break;
- }
-
- //wxbMainFrame::GetInstance()->Print("(>WFE)", CS_DEBUG);
-
- if (keepresults) {
- return datatokenizer;
- }
- else {
- delete datatokenizer;
- return NULL;
- }
-}
-
/* Run a dir command, and waits until result is fully received. */
void wxbRestorePanel::UpdateTreeItem(wxTreeItemId item, bool updatelist, bool recurse) {
// this->updatelist = updatelist;
wxbDataTokenizer* dt;
- dt = WaitForEnd(wxString("cd \"") <<
+ dt = wxbUtils::WaitForEnd(wxString("cd \"") <<
static_cast<wxbTreeItemData*>(tree->GetItemData(item))
->GetPath() << "\"\n", false);
if (updatelist)
list->DeleteAllItems();
- dt = WaitForEnd("dir\n", true);
+ dt = wxbUtils::WaitForEnd("dir\n", true);
wxString str;
/* Parse dir command results. */
wxString* wxbRestorePanel::ParseList(wxString line) {
- //drwx------ 11 1003 42949672 0 2001-07-30 16:45:14 *filename
- //+ 10 ++ 4++ 10 ++ 8 ++ 8 + + 19 + *+ ->
- //0 10 14 24 32 42 62
+ /* See ls_output in dird/ua_tree.c */
+
+ //drwxrwxrwx 1 root root 0 2004-04-03 14:35:21 f:/tocd/NVSU 1.00.00/
+ //+ 10 + ++ + 8 + + 8 ++ 8 + + 19 + *+ ->
+ //0 12 15 24 32 42 62
if (line.Length() < 63)
return NULL;
wxString* ret = new wxString[9];
ret[0] = line.Mid(0, 10).Trim();
- ret[1] = line.Mid(10, 4).Trim();
- ret[2] = line.Mid(14, 10).Trim();
+ ret[1] = line.Mid(12, 2).Trim();
+ ret[2] = line.Mid(15, 8).Trim();
ret[3] = line.Mid(24, 8).Trim();
ret[4] = line.Mid(32, 8).Trim();
ret[5] = line.Mid(42, 19).Trim();
/* Update first config, adapting settings to the job name selected */
void wxbRestorePanel::UpdateFirstConfig() {
configPanel->Enable(false);
- wxbDataTokenizer* dt = WaitForEnd(wxString(".defaults job=") + configPanel->GetRowString("Job Name") + "\n", true, false);
+ wxbDataTokenizer* dt = wxbUtils::WaitForEnd(wxString(".defaults job=") + configPanel->GetRowString("Job Name") + "\n", true, false);
/* job=RestoreFiles
* pool=Default
* messages=Standard
CmdConfigCancel();
SetWorking(false);
}
-