Unverified Commit addd1302 authored by Austin Sanders's avatar Austin Sanders Committed by GitHub
Browse files

Edrget removal (#5189)



* deprecated edrget app

* Edited changelog

* Edited changelog

---------

Co-authored-by: default avatarGavin <nelsong916@gmail.com>
parent 84f09660
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -46,6 +46,9 @@ release.

### Deprecated

### Removed
- edrget application [#4665](https://github.com/DOI-USGS/ISIS3/issues/4665)

### Fixed
- Updated README.md to remove remaining references to downloading data from discontinued rsync server [#5152](https://github.com/DOI-USGS/ISIS3/issues/5152)
- Fixed users not being able to modify planetographic projections in qmos
+0 −7
Original line number Diff line number Diff line
ifeq ($(ISISROOT), $(BLANK))
.SILENT:
error:
	echo "Please set ISISROOT";
else
	include $(ISISROOT)/make/isismake.apps
endif
 No newline at end of file
+0 −228
Original line number Diff line number Diff line
#include "ResourceGet.h"

#include <iostream>

#include <QString>
#include <QtCore>
#include <QMessageBox>
#include <QtNetwork>
#include <QSysInfo>


#include "Application.h"
#include "IException.h"
#include "Progress.h"


using namespace std;

namespace Isis {

  ResourceGet::ResourceGet(QObject *parent) : QObject(parent) {
    m_error = false;
    m_lastDone = -1;
    m_timeOut = 60000; // default timeout (ms) 
    m_reply = NULL;
    m_isInteractive = Application::GetUserInterface().IsInteractive();

    //tjw:  A timer for detecting network timeouts and exiting the application gracefully
    connect(&m_timer, SIGNAL(timeout()), 
            this, SLOT(connectionTimeout()));
  }



  /**
   * Destructor
   */
  ResourceGet::~ResourceGet() {
    // m_reply already scheduled for deletion in connectionFinished
  }



  /**
   * Initiates the request for the resource at the given url
   * 
   * @param url (const QUrl &) The resource's URL
   * @param topath (QString) Local destination for the downloaded resource
   * @param timeout (int) Time (in milliseconds) to try before timeout occurs
   * 
   * @return (bool) Indicates if there were any problems creating the local file to write to
   */
  bool ResourceGet::getResource(const QUrl &url, QString topath, int timeout) {

    m_timeOut = timeout;

    // Need to setup output file 
    QString localFileName;
    if (topath.size() != 0) {
      localFileName += topath;
      localFileName += "/";
    }

    // The local file is named according to the external resource name
    // i.e. if there is no filename in the URL, we can't name our local file to write to
    localFileName +=  QFileInfo(url.path()).fileName();
    if (localFileName.isEmpty() ) {
      QString msg = QString("URL has no filename, can't create local output file");
      m_progress.SetText(msg);
      if (!m_isInteractive)
         cout << msg.toStdString() << endl;

      m_error = true;
      return m_error;
    }

    // Handle any problems with opening the local output file
    m_file.setFileName(localFileName);
    if (!m_file.open(QIODevice::WriteOnly) ) {
      QString msg = QString("Cannot open output file: ");
      msg += m_file.error();
      m_progress.SetText(msg);

      if (!m_isInteractive)
         cout << msg.toStdString() << endl;

      m_error =  true;
      return m_error;
    }

    // Establish the connection and start the GET request
    m_networkMgr.connectToHost(url.host(),url.port());


    // We obtain ownership of the QNetworkReply *, so need to delete later

    m_reply = m_networkMgr.get(QNetworkRequest(url));

    QString productType(QSysInfo::productType());
    productType = productType.toLower();

    //If this application is running on OS X, then this if statement gets around the SSL Handshaking
    //errors because Qt is not looking for the DOI root certificate in the correct
    //place. 

    if (productType.contains("osx") ) {
       
       m_reply->ignoreSslErrors();
    }


    connect(m_reply, SIGNAL(finished()),
            this, SLOT(connectionFinished()));
    connect(m_reply, SIGNAL(readyRead()),
            this, SLOT(downloadReadyRead()));
    connect(m_reply, SIGNAL(downloadProgress(qint64, qint64)),
            this, SLOT(updateDownloadProgress(qint64, qint64)));

    m_lastDone = -1;
    m_error = false;
    return m_error;
  }



   //Timeout event handler monitors the ftp connection and gracefully
  //closes and exits the application if a timeout occurs.
  void ResourceGet::connectionTimeout() {
      QString timeoutSecs = QString("Timeout error:  GET request exceeded ") +
              QString::number(m_timeOut)+ QString(" ms.");

      m_progress.SetText(timeoutSecs);

      // Will let user know there was a timeout
      m_errorMessage = timeoutSecs;

      // Note that finished() SIGNAL will be emitted when aborting
      m_reply->abort();
  }



  //! Handles when the connection finishes
  void ResourceGet::connectionFinished() {
    // This will handle an abort() as well
    if (m_reply->error()) {
      // Error message is already set if we encountered a TIMEOUT
      if (m_errorMessage.isEmpty()) {
        m_errorMessage = m_reply->errorString();
        
      }
      
      if (m_errorMessage.contains("Timeout error")) {
        m_error = false;
        if (!m_isInteractive) {
          cout << m_errorMessage << endl;
        }
      }
      else {
        m_error = true;
      }

      removeLocalFile();
    }

    else {
      m_file.close();
      // this was added because final size may not match progress size so
      // you do not get 100% processed
      if (!m_isInteractive) {
        cout << "100% Processed" << endl;
      }
    }

    // QNetworkAccessManager::get gave us ownership of the QNetworkReply *
    m_reply->deleteLater();
    m_reply = NULL;

    emit done();
  }



  //! Slot that is invoked whenever there is data available to read over connection
  void ResourceGet::downloadReadyRead() {
    if (m_file.exists()) {
      m_file.write(m_reply->readAll());
    }
  }



  //! Removes the local file if there is an error with the download
  void ResourceGet::removeLocalFile() {
    bool fileExists = false;
    QString fileRemovedQStr;

    fileExists = m_file.exists();

    if (fileExists) {
      m_file.close();
      m_file.remove();
    }
  }



  // tjw:  ftpProgress uses the ISIS progress class to track progress
  void ResourceGet::updateDownloadProgress(qint64 read, qint64 total) {
    m_timer.start(m_timeOut);

    if (total == 0) return;
    if (total == -1) return;
    if (m_error) return;
    if (m_lastDone < 0) {        
      m_progress.SetText(QString("Downloading File ") + m_file.fileName());
      m_progress.SetMaximumSteps(total);
      m_progress.CheckStatus();
      m_lastDone = 1;
    }

    while (m_lastDone <= read) {
      m_progress.CheckStatus();
      m_lastDone++;
    }
   }

}
+0 −66
Original line number Diff line number Diff line
#ifndef RESOURCEGET_H
#define RESOURCEGET_H

#include <QFile>
#include <QNetworkAccessManager>
#include <QString>
#include <QTimer>

#include "Progress.h"

class QNetworkReply;
class QUrl;

namespace Isis {
  /**
   * @author ????-??-?? Unknown
   *
   * @internal
   *   @history 2016-02-08 Ian Humphrey - Replaced ftpget and httpget classes with ResourceGet
   *                           class to handle generic resource requests (Qt5). This was done
   *                           as the previous classes relied on QFtp and QHttp, which are 
   *                           deprecated in Qt5.
   */
  class ResourceGet : public QObject {
      Q_OBJECT

    public:
      ResourceGet(QObject *parent = 0);
      ~ResourceGet();

      bool getResource(const QUrl &url, QString topath, int timeout);

      inline bool error() const {
        return m_error;
      };
      inline QString errorMessage() const {
        return m_errorMessage;
      }

    signals:
      void done();

    private slots:
      //tjw
      void connectionTimeout();
      void connectionFinished();
      void downloadReadyRead();
      void updateDownloadProgress(qint64 read, qint64 total);
      

    private:
      void removeLocalFile();
      
      bool m_error;                       //!< Indicates if an error has occurred
      bool m_isInteractive;               //!< Indicates if application is interactive
      int m_lastDone;                     //!< Last read byte during download
      int m_timeOut;                      //!< Value (in milliseconds) before timeout occurs
      Progress m_progress;                //!< Keeps track of download progress
      QFile m_file;                       //!< Local file to write download data to
      QNetworkAccessManager m_networkMgr; //!< Manages the connection for the download
      QNetworkReply *m_reply;             //!< The reply that will contain data to read
      QString m_errorMessage;             //!< A string representation of an error that occurs
      QTimer m_timer;                     //!< Timer used to determine timeout
  };
}
#endif
+0 −106
Original line number Diff line number Diff line
<?xml version="1.0" encoding="UTF-8"?>

<application name="edrget" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation=
"http://isis.astrogeology.usgs.gov/Schemas/Application/application.xsd">
  <brief>
    Download network file using FTP or HTTP protocol.
  </brief>

  <description>
    When the Uniform Resouce Locator (URL) of a desired file is entered, edrget will use
     the FTP or HTTP protocol to download the requested file.  The URL must contain the scheme, 
     domain, path, and filename.<br></br>
         <b>URL Example:</b><br></br>
                   ftp://host.gov/directory/sub_directory/image_name.QUB<br></br>
         or<br></br>
                   http://host.gov/directory/sub_directory/image_name.QUB
  </description>

  <category>
    <categoryItem>Import and Export</categoryItem>
  </category>
  
  <history>
    <change name="Robert Sucharski" date="2005-07-12">
      Original version
    </change>
    <change name="Brendan George" date="2007-02-14">
        Added TOPATH parameter
    </change>
    <change name="Brendan George" date="2007-02-15">
        Changed output to default  to current working directory
    </change>
    <change name="Steven Lambright" date="2007-08-14">
        Added an application test
    </change>
    <change name="Tyler Wilson" date ="2015-09-14">
        Added a timeout event handler to gracefully exit the application in the event
        the ftp server response time becomes too long.
    </change>
    <change name="Ian Humphrey" date="2016-04-14">
        Replaced httpget and ftpget classes with ResourceGet class for updating to Qt5.
    </change>
    <change name="Makayla Shepherd" date="2017-03-02">
        Added https to reflect changes in the server.
    </change>
    <change name="Tyler Wilson" date="2017-06-29">
        Changed ResourceGet::getResource function.  If there are SSL handshaking errors
        when attempting to download an https resource,
        and this application is running on OS X, the network reply is instructed to
        ignore the errors.  References #4771.
    </change>
  </history>



  <groups>
    <group name="Files">
      <parameter name="URL">
        <type>string</type>
        <brief>Uniform Resouce Locator (URL) of the desired file. </brief>
        <description>
          <p>
          This is the Uniform Resource Locator (URL) for the network file to downloaded.  The URL 
          must contain the scheme, domain name, path, and file name.<br></br>
          <b>URL Example:</b><br></br>
                   ftp://host.gov/directory/sub_directory/image_name.QUB<br></br>
         or<br></br>
                   http://host.gov/directory/sub_directory/image_name.QUB
          </p>
        </description>      
      </parameter>      
      <parameter name="TOPATH">
        <type>string</type>
        <brief>The path to the output file </brief>
        <description>
            This path describes where the output file is to be located. The
            output filename will be derived from the URL.
        </description>
        <internalDefault>
            Current Working Directory
        </internalDefault>
      </parameter>

    </group>

    <group name = "Timeout (ms)">
    <parameter name ="TIMEOUT">
        <type>integer</type>
        <brief>Timeout (in milliseconds) for file requests.</brief>
        <description>
            If the application does not hear from the server in the
            allotted amount of time, it quits and displays an error.
        </description>
        <internalDefault>
            60000
        </internalDefault>
     </parameter>
    </group>


  </groups>



</application>
Loading