Permalink
Browse files

Get the classic home dir packaging working from the GUI. Still need t…

…o test the extraction and hook that in as well.
  • Loading branch information...
1 parent e696950 commit d91dc4934c995f0c63f411e8b335e878b440ed82 Ken Moore committed Oct 16, 2013
Showing with 72 additions and 37 deletions.
  1. +10 −3 lp-gui/LPGUtils.cpp
  2. +1 −1 lp-gui/LPGUtils.h
  3. +38 −17 lp-gui/LPMain.cpp
  4. +2 −1 lp-gui/LPMain.h
  5. +21 −15 lp-gui/LPMain.ui
View
@@ -186,25 +186,32 @@ QStringList LPGUtils::revertDir(QString oldPath, QString newPath){
QString LPGUtils::packageHomeDir(QString username, QString packageName){
//Check that the user directory exists
+ //qDebug() << "Start package dir:" << username << packageName;
if(!QFile::exists("/usr/home/"+username)){ return ""; }
//Check that the package has the right extension
if(!packageName.endsWith(".tar.gz")){ packageName.append(".tar.gz"); }
+ //Generate any additional files to be contained in the package
+
+
//Generate the command
- QString cmd = "cd /usr/home; tar -czf "+packageName+" "+username;
+ QString cmd = "tar -czf /usr/home/"+packageName+" -C /usr/home "+username;
//Run the command
+ //qDebug() << "Run command:" << cmd;
LPBackend::runCmd(cmd);
+ //qDebug() << "Command return:" << QString::number(ret);
//Check that the package was created
QString packagePath;
if(QFile::exists("/usr/home/"+packageName)){ packagePath = "/usr/home/"+packageName; }
//Now return the path to the package file
return packagePath;
}
-QString LPGUtils::getPackageUsername(QString packagePath){
+QString LPGUtils::checkPackageUserPath(QString packagePath){
//Determine if the file exists
if( !QFile::exists(packagePath) ){ return ""; }
//Check the username of the home dir in the package
QStringList ret = LPBackend::getCmdOutput("tar -tvf "+packagePath);
+ if(ret.isEmpty()){ return ""; }
QString username = ret[0].section(" ",2,2,QString::SectionSkipEmpty);
return username;
}
@@ -213,7 +220,7 @@ bool LPGUtils::extractHomeDirPackage(QString packagePath){
//Determine if the file exists
if( !QFile::exists(packagePath) ){ return false; }
//Now extract the archive in the home directory (no overwriting of existing files)
- QString cmd = "cd /usr/home; tar -xkf "+packagePath;
+ QString cmd = "tar -xkf "+packagePath+" -C /usr/home";
int ret = LPBackend::runCmd(cmd);
return (ret == 0);
}
View
@@ -19,7 +19,7 @@ class LPGUtils{
static QStringList revertDir(QString oldPath, QString newPath); //copy a dir out of a snapshot
//Functions for packaging up a user's home directory and extracting it later
static QString packageHomeDir(QString username, QString packageName);
- static QString getPackageUsername(QString packagePath);
+ static QString checkPackageUserPath(QString packagePath);
static bool extractHomeDirPackage(QString packagePath);
};
View
@@ -37,7 +37,7 @@ LPMain::LPMain(QWidget *parent) : QMainWindow(parent), ui(new Ui::LPMain){
connect(ui->menuUnmanage_Pool, SIGNAL(triggered(QAction*)), this, SLOT(menuRemovePool(QAction*)) );
connect(ui->action_SaveKeyToUSB, SIGNAL(triggered()), this, SLOT(menuSaveSSHKey()) );
connect(ui->actionClose_Window, SIGNAL(triggered()), this, SLOT(menuCloseWindow()) );
- connect(ui->actionCompress_Home_Dir, SIGNAL(triggered()), this, SLOT(menuCompressHomeDir()) );
+ connect(ui->menuCompress_Home_Dir, SIGNAL(triggered(QAction*)), this, SLOT(menuCompressHomeDir(QAction*)) );
connect(ui->actionExtract_Home_Dir, SIGNAL(triggered()), this, SLOT(menuExtractHomeDir()) );
connect(ui->actionAdd_Disk, SIGNAL(triggered()), this, SLOT(menuAddDisk()) );
connect(ui->actionRemove_Disk, SIGNAL(triggered()), this, SLOT(menuRemoveDisk()) );
@@ -110,7 +110,13 @@ void LPMain::updatePoolList(){
ui->menuUnmanage_Pool->addAction(pools[i]);
}
ui->menuUnmanage_Pool->setEnabled( !ui->menuUnmanage_Pool->isEmpty() );
-
+ //Now update the user's that are available for home-dir packaging
+ QDir hdir("/usr/home");
+ QStringList users = hdir.entryList(QDir::Dirs | QDir::NoDotAndDotDot, QDir::Name);
+ ui->menuCompress_Home_Dir->clear();
+ for(int i=0; i<users.length(); i++){
+ ui->menuCompress_Home_Dir->addAction(users[i]);
+ }
//Now update the interface appropriately
ui->combo_pools->setEnabled(poolSelected);
updateTabs();
@@ -148,20 +154,20 @@ void LPMain::updateTabs(){
ui->label_status->setText(POOLDATA.poolStatus);
ui->label_numdisks->setText( QString::number(POOLDATA.harddisks.length()) );
ui->label_latestsnapshot->setText(POOLDATA.latestSnapshot);
- if(POOLDATA.finishedStatus.isEmpty()){ ui->label_replication->setVisible(false); }
+ if(POOLDATA.finishedStatus.isEmpty()){ ui->label_finishedstat->setVisible(false); }
else{
- ui->label_replication->setText(POOLDATA.finishedStatus);
- ui->label_replication->setVisible(true);
+ ui->label_finishedstat->setText(POOLDATA.finishedStatus);
+ ui->label_finishedstat->setVisible(true);
}
- if(POOLDATA.runningStatus.isEmpty()){ ui->label_mirror->setVisible(false); }
+ if(POOLDATA.runningStatus.isEmpty()){ ui->label_runningstat->setVisible(false); }
else{
- ui->label_mirror->setText(POOLDATA.runningStatus);
- ui->label_mirror->setVisible(true);
+ ui->label_runningstat->setText(POOLDATA.runningStatus);
+ ui->label_runningstat->setVisible(true);
}
- if(POOLDATA.errorStatus.isEmpty()){ ui->label_errors->setVisible(false); }
+ if(POOLDATA.errorStatus.isEmpty()){ ui->label_errorstat->setVisible(false); }
else{
- ui->label_errors->setText(POOLDATA.errorStatus);
- ui->label_errors->setVisible(true);
+ ui->label_errorstat->setText(POOLDATA.errorStatus);
+ ui->label_errorstat->setVisible(true);
}
//Now list the data restore options
QString cds = ui->combo_datasets->currentText();
@@ -188,9 +194,9 @@ void LPMain::updateTabs(){
ui->label_numdisks->clear();
ui->label_latestsnapshot->clear();
ui->label_status->clear();
- ui->label_errors->setVisible(false);
- ui->label_mirror->setVisible(false);
- ui->label_replication->setVisible(false);
+ ui->label_errorstat->setVisible(false);
+ ui->label_runningstat->setVisible(false);
+ ui->label_finishedstat->setVisible(false);
}
}
@@ -397,9 +403,24 @@ void LPMain::menuCloseWindow(){
}
// ==== Classic Backups Menu ====
-void LPMain::menuCompressHomeDir(){
- qDebug() << "Compress Home Dir";
-
+void LPMain::menuCompressHomeDir(QAction* act){
+ QString user = act->text();
+ qDebug() << "Compress Home Dir:" << user;
+ //Prompt for the package name
+ QString pkgName = user+"-homedir-"+QDateTime::currentDateTime().toString("yyyyMMdd-hhmm");
+ bool ok;
+ pkgName = QInputDialog::getText(this, tr("Package Name"), tr("Name of the package to create:"), QLineEdit::Normal, pkgName, &ok);
+ if(!ok || pkgName.isEmpty() ){ return; } //cancelled
+ //Now create the package
+ QString pkgPath = LPGUtils::packageHomeDir(user, pkgName);
+ //Now inform the user of the result
+ if(pkgPath.isEmpty()){
+ qDebug() << "No Package created";
+ QMessageBox::warning(this,tr("Package Failure"), tr("The home directory package could not be created."));
+ }else{
+ qDebug() << "Package created at:" << pkgPath;
+ QMessageBox::information(this,tr("Package Success"), tr("The home directory package was successfully created.")+"\n\n"+pkgPath);
+ }
}
void LPMain::menuExtractHomeDir(){
View
@@ -11,6 +11,7 @@
#include <QWidgetAction>
#include <QFileSystemModel>
#include <QInputDialog>
+#include <QDateTime>
#include "LPBackend.h"
#include "LPContainers.h"
@@ -58,7 +59,7 @@ private slots:
void menuSaveSSHKey();
void menuCloseWindow();
//Classic Backups
- void menuCompressHomeDir();
+ void menuCompressHomeDir(QAction*);
void menuExtractHomeDir();
//Disk Menu
void menuAddDisk();
View
@@ -177,15 +177,15 @@
</widget>
</item>
<item>
- <widget class="QLabel" name="label_replication">
+ <widget class="QLabel" name="label_finishedstat">
<property name="statusTip">
<string/>
</property>
<property name="styleSheet">
<string notr="true">background-color: rgba(10,200,10,100); border-radius: 5px</string>
</property>
<property name="text">
- <string notr="true">Replication Status</string>
+ <string notr="true">Finished Status</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
@@ -196,12 +196,12 @@
</widget>
</item>
<item>
- <widget class="QLabel" name="label_mirror">
+ <widget class="QLabel" name="label_runningstat">
<property name="styleSheet">
<string notr="true">background-color: rgba(10,100,200,100); border-radius: 5px</string>
</property>
<property name="text">
- <string notr="true">Mirror Status</string>
+ <string notr="true">Running Status</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
@@ -212,7 +212,7 @@
</widget>
</item>
<item>
- <widget class="QLabel" name="label_errors">
+ <widget class="QLabel" name="label_errorstat">
<property name="styleSheet">
<string notr="true">background-color: rgba(230,10,10,100); border-radius: 5px</string>
</property>
@@ -449,7 +449,17 @@
<property name="title">
<string>Classic Backups</string>
</property>
- <addaction name="actionCompress_Home_Dir"/>
+ <widget class="QMenu" name="menuCompress_Home_Dir">
+ <property name="title">
+ <string>Compress Home Dir</string>
+ </property>
+ <property name="icon">
+ <iconset resource="lPreserve.qrc">
+ <normaloff>:/images/box_add.png</normaloff>:/images/box_add.png</iconset>
+ </property>
+ <addaction name="actionUser"/>
+ </widget>
+ <addaction name="menuCompress_Home_Dir"/>
<addaction name="actionExtract_Home_Dir"/>
</widget>
<addaction name="menuFile"/>
@@ -564,15 +574,6 @@
<string>Classic Backup</string>
</property>
</action>
- <action name="actionCompress_Home_Dir">
- <property name="icon">
- <iconset resource="lPreserve.qrc">
- <normaloff>:/images/box_add.png</normaloff>:/images/box_add.png</iconset>
- </property>
- <property name="text">
- <string>Compress Home Dir</string>
- </property>
- </action>
<action name="actionExtract_Home_Dir">
<property name="icon">
<iconset resource="lPreserve.qrc">
@@ -597,6 +598,11 @@
<string notr="true">snapshots</string>
</property>
</action>
+ <action name="actionUser">
+ <property name="text">
+ <string notr="true">user</string>
+ </property>
+ </action>
</widget>
<resources>
<include location="lPreserve.qrc"/>

0 comments on commit d91dc49

Please sign in to comment.