[PC-BSD Commits] r20561 - users/ken/EasyPBI2

svn at pcbsd.org svn at pcbsd.org
Thu Dec 13 14:17:54 PST 2012


Author: kenmoore
Date: 2012-12-13 22:17:54 +0000 (Thu, 13 Dec 2012)
New Revision: 20561

Modified:
   users/ken/EasyPBI2/aboutDialog.ui
   users/ken/EasyPBI2/portsDialog.cpp
   users/ken/EasyPBI2/portsDialog.h
Log:
Fix up all the EasyPBI ports tree updating. Almost dome with EasyPBI 2.0



Modified: users/ken/EasyPBI2/aboutDialog.ui
===================================================================
(Binary files differ)

Modified: users/ken/EasyPBI2/portsDialog.cpp
===================================================================
--- users/ken/EasyPBI2/portsDialog.cpp	2012-12-13 21:56:16 UTC (rev 20560)
+++ users/ken/EasyPBI2/portsDialog.cpp	2012-12-13 22:17:54 UTC (rev 20561)
@@ -17,7 +17,7 @@
 	localPorts = FALSE;
 	systemPorts = FALSE;
 	p = new QProcess(this);
-	p->setProcessChannelMode(QProcess::MergedChannels);
+	//p->setProcessChannelMode(QProcess::MergedChannels);
 	p->setProcessEnvironment( QProcessEnvironment::systemEnvironment() );
 	connect(p,SIGNAL(readyReadStandardOutput()),this,SLOT(updateStatusBar()) );
 	connect(p,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(processFinished(int,QProcess::ExitStatus)) );
@@ -53,7 +53,7 @@
   if( !suCMD.isEmpty() ){
     QDir dir(systemPortsTree);
     QFileInfoList list = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files | QDir::Dirs, QDir::Time); //sort by most recently changed
-    if(list.length() > 0){
+    if(list.length() > 2){ //allow for a couple directories to still be there, and not have the full ports tree
 	systemPorts = TRUE; //files and/or directories exist
 	ui->push_updatesystem->setText( tr("Update System Ports") );
 	ui->label_systeminfo->setText( QString(tr("The system ports tree was last updated on %1")).arg( list[0].lastModified().toString() ));
@@ -77,7 +77,24 @@
 }
 
 void portsDialog::slotGetLocalPorts(){
-  qDebug() << "Fetching local ports tree is not supported yet";
+  qDebug() << "Starting local download of FreeBSD Ports tree";
+  //Disable the interface buttons
+  ui->push_updatesystem->setEnabled(FALSE);
+  ui->push_updatelocal->setEnabled(FALSE);
+  ui->push_close->setEnabled(FALSE);
+  //Now make sure the progress box is visible
+  ui->groupUpdate->setVisible(TRUE);
+  ui->progressBar->setValue(0);
+    //Begin creating the network variables
+    QNetworkReply *currentDL;
+    QNetworkAccessManager *manager = new QNetworkAccessManager(this);
+    //Start the download
+    connect(manager, SIGNAL(finished(QNetworkReply*)), this, SLOT(downloadFinished(QNetworkReply*)) );
+    currentDL = manager->get(QNetworkRequest(QUrl("ftp://ftp.freebsd.org/pub/FreeBSD/ports/ports/ports.tar.gz")));
+    //Update the status
+    ui->label_status->setText(tr("Downloading the FreeBSD ports tree..."));
+    connect(currentDL, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(updateProgressBar(qint64,qint64)) );
+
 }
 
 void portsDialog::slotGetSystemPorts(){
@@ -88,13 +105,14 @@
   //Now make sure the progress box is visible
   ui->groupUpdate->setVisible(TRUE);
   ui->progressBar->setMaximum(0); ui->progressBar->setMinimum(0); //default to a "loading" indicator
+  ui->label_status->setText(tr("Requesting Root Access"));
   QString cmd = suCMD + " \""; //use the swutch-user utility
   if(systemPorts){
     //Update the ports tree
-    cmd.append("/usr/sbin/portsnap fetch update");
+    cmd.append("svn update /usr/ports");
   }else{
     //Fresh installation of the ports tree
-    cmd.append("/usr/sbin/portsnap fetch extract");
+    cmd.append("svn co svn://svn.freebsd.org/ports/head /usr/ports");
   }
   cmd.append("\""); //close the quotes
   //Now run the command
@@ -102,14 +120,64 @@
   qDebug() << "System ports update started: CMD:" << cmd;
 }
 
-void portsDialog::updateProgressBar(){
-	
+void portsDialog::updateProgressBar(qint64 bytesReceived, qint64 bytesTotal){
+  //Determine the percentage
+  int percent = 0;
+  if(bytesTotal != 0){
+    percent = (bytesReceived*100)/bytesTotal;
+  }
+  //Update the progress bar
+  ui->progressBar->setValue(percent);
+  ui->progressBar->update();
 }
 
+void portsDialog::downloadFinished(QNetworkReply *reply){
+  //Disable the progress bar
+  ui->progressBar->setMaximum(0); ui->progressBar->setMinimum(0); //default to a "loading" indicator
+  //See if the Download was successful
+  qDebug() << "Ports download completion code:" << reply->error();
+  if( reply->error() != QNetworkReply::NoError){
+    QMessageBox::warning(this, tr("Download Failed"),tr("Downloading the FreeBSD ports tree failed. Please check your internet connection and try again."));
+    return;
+  }
+  //Download Succesful, save it to file
+  QFile file(localPortsTree+".tar.gz");
+  if( !file.open(QIODevice::WriteOnly)){   //if file could not be opened
+    QMessageBox::warning(this, tr("Saving Failed"),tr("Saving the FreeBSD ports tree file failed. Please try again."));
+    reply->deleteLater();
+    return;
+  }
+  file.write(reply->readAll());
+  file.close();
+  //Saving the file successful, delete the downloaded data from memory
+  reply->deleteLater();
+  ui->label_status->setText(tr("Extracting the ports tree into the EasyPBI directory. (This may take a while)"));
+  QTimer::singleShot(1000, this, SLOT(extractLocalPorts()) ); //wait 1 sec to start process
+}
+
+void portsDialog::extractLocalPorts(){
+  //Now start the extraction
+  QString pFile = localPortsTree.section("/",-1) + ".tar.gz";
+  QString pDir = localPortsTree + ".tar.gz";
+  pDir.remove("/"+pFile); //cut the file name off the end
+  if(pDir.endsWith("/")){ pDir.chop(1); } //remove any extra "/" on the end
+  if(localPorts){ //remove the old tree if it exists
+    qDebug() << "Removing current local ports tree";
+    QString rcmd = "cd "+pDir+"; rm -r ports/";
+    system(rcmd.toUtf8()); 
+  } 
+  //extract the new tree and remove the downloaded file
+  QString cmd1 = "tar xvf "+pFile;
+  p->setWorkingDirectory(pDir); //Make sure we start in the proper directory
+  p->start(cmd1);
+  qDebug() << "Starting ports extraction process: CMD:" << cmd1;
+}
+
 void portsDialog::updateStatusBar(){
   QString tmp = p->readAllStandardOutput();
-  tmp.remove("\n");
-  qDebug() << "Status Update:" << tmp;
+  tmp.remove("\n").simplified();
+  //qDebug() << "Status Update:" << tmp;
+  ui->label_status->clear();
   ui->label_status->setText(tmp);
 }
 
@@ -122,13 +190,19 @@
   //Now make sure the progress box is invisible
   ui->groupUpdate->setVisible(FALSE);	
 	
+  //If the ports package exists in the EasyPBI directory, remove it
+  if(QFile::exists(localPortsTree+".tar.gz") ){ 
+    QString cmd = "rm "+localPortsTree+".tar.gz";
+    system(cmd.toUtf8());
+  }
   //Inform the user of the result
   if(exitCode == 0){
     //Finished successfully
-    QMessageBox::information(this, tr("Success"), tr("The System ports tree has been successfully updated") );
+    QMessageBox::information(this, tr("Success"), tr("The FreeBSD ports tree has been successfully updated") );
   }else{
     //Finished with error
-    QMessageBox::information(this, tr("Failure"), tr("The System ports tree has failed to update.") );
+    QString msg = p->readAllStandardError();
+    QMessageBox::information(this, tr("Failure"), QString(tr("The FreeBSD ports tree has failed to update.")+"\n"+tr("Last Message: %1") ).arg(msg) );
   }
   checkForPorts(); //Update the interface times and such
 }

Modified: users/ken/EasyPBI2/portsDialog.h
===================================================================
--- users/ken/EasyPBI2/portsDialog.h	2012-12-13 21:56:16 UTC (rev 20560)
+++ users/ken/EasyPBI2/portsDialog.h	2012-12-13 22:17:54 UTC (rev 20561)
@@ -10,6 +10,10 @@
 #include <QProcessEnvironment>
 #include <QMessageBox>
 #include <QDateTime>
+#include <QNetworkAccessManager>
+#include <QNetworkRequest>
+#include <QNetworkReply>
+#include <QTimer>
 #include "ui_portsDialog.h"
 
 
@@ -29,8 +33,10 @@
     void slotClose();
     void slotGetLocalPorts();
     void slotGetSystemPorts();
-    void updateProgressBar();
+    void updateProgressBar(qint64,qint64);
     void updateStatusBar();
+    void downloadFinished(QNetworkReply*);
+    void extractLocalPorts();
     void processFinished(int,QProcess::ExitStatus);
 
 private:



More information about the Commits mailing list