Skip to content

Commit

Permalink
Get the classic home dir packaging working from the GUI. Still need t…
Browse files Browse the repository at this point in the history
…o test the extraction and hook that in as well.
  • Loading branch information
Ken Moore committed Oct 16, 2013
1 parent e696950 commit d91dc49
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 37 deletions.
13 changes: 10 additions & 3 deletions lp-gui/LPGUtils.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -186,25 +186,32 @@ QStringList LPGUtils::revertDir(QString oldPath, QString newPath){


QString LPGUtils::packageHomeDir(QString username, QString packageName){ QString LPGUtils::packageHomeDir(QString username, QString packageName){
//Check that the user directory exists //Check that the user directory exists
//qDebug() << "Start package dir:" << username << packageName;
if(!QFile::exists("/usr/home/"+username)){ return ""; } if(!QFile::exists("/usr/home/"+username)){ return ""; }
//Check that the package has the right extension //Check that the package has the right extension
if(!packageName.endsWith(".tar.gz")){ packageName.append(".tar.gz"); } if(!packageName.endsWith(".tar.gz")){ packageName.append(".tar.gz"); }
//Generate any additional files to be contained in the package


//Generate the command //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 //Run the command
//qDebug() << "Run command:" << cmd;
LPBackend::runCmd(cmd); LPBackend::runCmd(cmd);
//qDebug() << "Command return:" << QString::number(ret);
//Check that the package was created //Check that the package was created
QString packagePath; QString packagePath;
if(QFile::exists("/usr/home/"+packageName)){ packagePath = "/usr/home/"+packageName; } if(QFile::exists("/usr/home/"+packageName)){ packagePath = "/usr/home/"+packageName; }
//Now return the path to the package file //Now return the path to the package file
return packagePath; return packagePath;
} }


QString LPGUtils::getPackageUsername(QString packagePath){ QString LPGUtils::checkPackageUserPath(QString packagePath){
//Determine if the file exists //Determine if the file exists
if( !QFile::exists(packagePath) ){ return ""; } if( !QFile::exists(packagePath) ){ return ""; }
//Check the username of the home dir in the package //Check the username of the home dir in the package
QStringList ret = LPBackend::getCmdOutput("tar -tvf "+packagePath); QStringList ret = LPBackend::getCmdOutput("tar -tvf "+packagePath);
if(ret.isEmpty()){ return ""; }
QString username = ret[0].section(" ",2,2,QString::SectionSkipEmpty); QString username = ret[0].section(" ",2,2,QString::SectionSkipEmpty);
return username; return username;
} }
Expand All @@ -213,7 +220,7 @@ bool LPGUtils::extractHomeDirPackage(QString packagePath){
//Determine if the file exists //Determine if the file exists
if( !QFile::exists(packagePath) ){ return false; } if( !QFile::exists(packagePath) ){ return false; }
//Now extract the archive in the home directory (no overwriting of existing files) //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); int ret = LPBackend::runCmd(cmd);
return (ret == 0); return (ret == 0);
} }
2 changes: 1 addition & 1 deletion lp-gui/LPGUtils.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class LPGUtils{
static QStringList revertDir(QString oldPath, QString newPath); //copy a dir out of a snapshot 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 //Functions for packaging up a user's home directory and extracting it later
static QString packageHomeDir(QString username, QString packageName); static QString packageHomeDir(QString username, QString packageName);
static QString getPackageUsername(QString packagePath); static QString checkPackageUserPath(QString packagePath);
static bool extractHomeDirPackage(QString packagePath); static bool extractHomeDirPackage(QString packagePath);
}; };


Expand Down
55 changes: 38 additions & 17 deletions lp-gui/LPMain.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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->menuUnmanage_Pool, SIGNAL(triggered(QAction*)), this, SLOT(menuRemovePool(QAction*)) );
connect(ui->action_SaveKeyToUSB, SIGNAL(triggered()), this, SLOT(menuSaveSSHKey()) ); connect(ui->action_SaveKeyToUSB, SIGNAL(triggered()), this, SLOT(menuSaveSSHKey()) );
connect(ui->actionClose_Window, SIGNAL(triggered()), this, SLOT(menuCloseWindow()) ); 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->actionExtract_Home_Dir, SIGNAL(triggered()), this, SLOT(menuExtractHomeDir()) );
connect(ui->actionAdd_Disk, SIGNAL(triggered()), this, SLOT(menuAddDisk()) ); connect(ui->actionAdd_Disk, SIGNAL(triggered()), this, SLOT(menuAddDisk()) );
connect(ui->actionRemove_Disk, SIGNAL(triggered()), this, SLOT(menuRemoveDisk()) ); connect(ui->actionRemove_Disk, SIGNAL(triggered()), this, SLOT(menuRemoveDisk()) );
Expand Down Expand Up @@ -110,7 +110,13 @@ void LPMain::updatePoolList(){
ui->menuUnmanage_Pool->addAction(pools[i]); ui->menuUnmanage_Pool->addAction(pools[i]);
} }
ui->menuUnmanage_Pool->setEnabled( !ui->menuUnmanage_Pool->isEmpty() ); 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 //Now update the interface appropriately
ui->combo_pools->setEnabled(poolSelected); ui->combo_pools->setEnabled(poolSelected);
updateTabs(); updateTabs();
Expand Down Expand Up @@ -148,20 +154,20 @@ void LPMain::updateTabs(){
ui->label_status->setText(POOLDATA.poolStatus); ui->label_status->setText(POOLDATA.poolStatus);
ui->label_numdisks->setText( QString::number(POOLDATA.harddisks.length()) ); ui->label_numdisks->setText( QString::number(POOLDATA.harddisks.length()) );
ui->label_latestsnapshot->setText(POOLDATA.latestSnapshot); 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{ else{
ui->label_replication->setText(POOLDATA.finishedStatus); ui->label_finishedstat->setText(POOLDATA.finishedStatus);
ui->label_replication->setVisible(true); ui->label_finishedstat->setVisible(true);
} }
if(POOLDATA.runningStatus.isEmpty()){ ui->label_mirror->setVisible(false); } if(POOLDATA.runningStatus.isEmpty()){ ui->label_runningstat->setVisible(false); }
else{ else{
ui->label_mirror->setText(POOLDATA.runningStatus); ui->label_runningstat->setText(POOLDATA.runningStatus);
ui->label_mirror->setVisible(true); ui->label_runningstat->setVisible(true);
} }
if(POOLDATA.errorStatus.isEmpty()){ ui->label_errors->setVisible(false); } if(POOLDATA.errorStatus.isEmpty()){ ui->label_errorstat->setVisible(false); }
else{ else{
ui->label_errors->setText(POOLDATA.errorStatus); ui->label_errorstat->setText(POOLDATA.errorStatus);
ui->label_errors->setVisible(true); ui->label_errorstat->setVisible(true);
} }
//Now list the data restore options //Now list the data restore options
QString cds = ui->combo_datasets->currentText(); QString cds = ui->combo_datasets->currentText();
Expand All @@ -188,9 +194,9 @@ void LPMain::updateTabs(){
ui->label_numdisks->clear(); ui->label_numdisks->clear();
ui->label_latestsnapshot->clear(); ui->label_latestsnapshot->clear();
ui->label_status->clear(); ui->label_status->clear();
ui->label_errors->setVisible(false); ui->label_errorstat->setVisible(false);
ui->label_mirror->setVisible(false); ui->label_runningstat->setVisible(false);
ui->label_replication->setVisible(false); ui->label_finishedstat->setVisible(false);
} }


} }
Expand Down Expand Up @@ -397,9 +403,24 @@ void LPMain::menuCloseWindow(){
} }


// ==== Classic Backups Menu ==== // ==== Classic Backups Menu ====
void LPMain::menuCompressHomeDir(){ void LPMain::menuCompressHomeDir(QAction* act){
qDebug() << "Compress Home Dir"; 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(){ void LPMain::menuExtractHomeDir(){
Expand Down
3 changes: 2 additions & 1 deletion lp-gui/LPMain.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <QWidgetAction> #include <QWidgetAction>
#include <QFileSystemModel> #include <QFileSystemModel>
#include <QInputDialog> #include <QInputDialog>
#include <QDateTime>


#include "LPBackend.h" #include "LPBackend.h"
#include "LPContainers.h" #include "LPContainers.h"
Expand Down Expand Up @@ -58,7 +59,7 @@ private slots:
void menuSaveSSHKey(); void menuSaveSSHKey();
void menuCloseWindow(); void menuCloseWindow();
//Classic Backups //Classic Backups
void menuCompressHomeDir(); void menuCompressHomeDir(QAction*);
void menuExtractHomeDir(); void menuExtractHomeDir();
//Disk Menu //Disk Menu
void menuAddDisk(); void menuAddDisk();
Expand Down
36 changes: 21 additions & 15 deletions lp-gui/LPMain.ui
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_replication"> <widget class="QLabel" name="label_finishedstat">
<property name="statusTip"> <property name="statusTip">
<string/> <string/>
</property> </property>
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color: rgba(10,200,10,100); border-radius: 5px</string> <string notr="true">background-color: rgba(10,200,10,100); border-radius: 5px</string>
</property> </property>
<property name="text"> <property name="text">
<string notr="true">Replication Status</string> <string notr="true">Finished Status</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
Expand All @@ -196,12 +196,12 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_mirror"> <widget class="QLabel" name="label_runningstat">
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color: rgba(10,100,200,100); border-radius: 5px</string> <string notr="true">background-color: rgba(10,100,200,100); border-radius: 5px</string>
</property> </property>
<property name="text"> <property name="text">
<string notr="true">Mirror Status</string> <string notr="true">Running Status</string>
</property> </property>
<property name="alignment"> <property name="alignment">
<set>Qt::AlignCenter</set> <set>Qt::AlignCenter</set>
Expand All @@ -212,7 +212,7 @@
</widget> </widget>
</item> </item>
<item> <item>
<widget class="QLabel" name="label_errors"> <widget class="QLabel" name="label_errorstat">
<property name="styleSheet"> <property name="styleSheet">
<string notr="true">background-color: rgba(230,10,10,100); border-radius: 5px</string> <string notr="true">background-color: rgba(230,10,10,100); border-radius: 5px</string>
</property> </property>
Expand Down Expand Up @@ -449,7 +449,17 @@
<property name="title"> <property name="title">
<string>Classic Backups</string> <string>Classic Backups</string>
</property> </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"/> <addaction name="actionExtract_Home_Dir"/>
</widget> </widget>
<addaction name="menuFile"/> <addaction name="menuFile"/>
Expand Down Expand Up @@ -564,15 +574,6 @@
<string>Classic Backup</string> <string>Classic Backup</string>
</property> </property>
</action> </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"> <action name="actionExtract_Home_Dir">
<property name="icon"> <property name="icon">
<iconset resource="lPreserve.qrc"> <iconset resource="lPreserve.qrc">
Expand All @@ -597,6 +598,11 @@
<string notr="true">snapshots</string> <string notr="true">snapshots</string>
</property> </property>
</action> </action>
<action name="actionUser">
<property name="text">
<string notr="true">user</string>
</property>
</action>
</widget> </widget>
<resources> <resources>
<include location="lPreserve.qrc"/> <include location="lPreserve.qrc"/>
Expand Down

0 comments on commit d91dc49

Please sign in to comment.