Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[External Storage] Add SimpleCopy backend
- Loading branch information
Showing
7 changed files
with
270 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/core/externalstorage/qgssimplecopyexternalstorage.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/*************************************************************************** | ||
qgssimplecopyexternalstorage.cpp | ||
-------------------------------------- | ||
Date : March 2021 | ||
Copyright : (C) 2021 by Julien Cabieces | ||
Email : julien dot cabieces at oslandia dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#include "qgssimplecopyexternalstorage_p.h" | ||
|
||
#include "qgscopyfiletask.h" | ||
#include "qgsapplication.h" | ||
|
||
#include <QFileInfo> | ||
|
||
QgsSimpleCopyExternalStorageStoredContent::QgsSimpleCopyExternalStorageStoredContent( const QString &filePath, const QString &url, const QString &authcfg ) | ||
{ | ||
Q_UNUSED( authcfg ); | ||
|
||
mCopyTask = new QgsCopyFileTask( filePath, url ); | ||
|
||
QgsApplication::instance()->taskManager()->addTask( mCopyTask ); | ||
|
||
connect( mCopyTask, &QgsTask::taskCompleted, this, [ = ] | ||
{ | ||
mUrl = mCopyTask->destination(); | ||
mStatus = Finished; | ||
emit stored(); | ||
} ); | ||
|
||
connect( mCopyTask, &QgsTask::taskTerminated, this, [ = ] | ||
{ | ||
reportError( mCopyTask->errorString() ); | ||
} ); | ||
|
||
connect( mCopyTask, &QgsTask::progressChanged, this, [ = ]( double progress ) | ||
{ | ||
emit progressChanged( progress ); | ||
} ); | ||
|
||
mStatus = OnGoing; | ||
} | ||
|
||
void QgsSimpleCopyExternalStorageStoredContent::cancel() | ||
{ | ||
if ( !mCopyTask ) | ||
return; | ||
|
||
disconnect( mCopyTask, &QgsTask::taskTerminated, nullptr, nullptr ); | ||
connect( mCopyTask, &QgsTask::taskTerminated, this, [ = ] | ||
{ | ||
mStatus = Canceled; | ||
emit canceled(); | ||
} ); | ||
|
||
mCopyTask->cancel(); | ||
} | ||
|
||
QString QgsSimpleCopyExternalStorageStoredContent::url() const | ||
{ | ||
return mUrl; | ||
} | ||
|
||
QgsSimpleCopyExternalStorageFetchedContent::QgsSimpleCopyExternalStorageFetchedContent( const QString &filePath ) | ||
{ | ||
// no fetching process, we read directly from its location | ||
if ( !QFileInfo::exists( filePath ) ) | ||
{ | ||
reportError( tr( "File '%1' does not exist" ).arg( filePath ) ); | ||
} | ||
else | ||
{ | ||
mStatus = Finished; | ||
mFilePath = filePath; | ||
} | ||
} | ||
|
||
QString QgsSimpleCopyExternalStorageFetchedContent::filePath() const | ||
{ | ||
return mFilePath; | ||
} | ||
|
||
QString QgsSimpleCopyExternalStorage::type() const | ||
{ | ||
return QStringLiteral( "SimpleCopy" ); | ||
}; | ||
|
||
QgsExternalStorageStoredContent *QgsSimpleCopyExternalStorage::store( const QString &filePath, const QString &url, const QString &authcfg ) const | ||
{ | ||
return new QgsSimpleCopyExternalStorageStoredContent( filePath, url, authcfg ); | ||
}; | ||
|
||
QgsExternalStorageFetchedContent *QgsSimpleCopyExternalStorage::fetch( const QString &url, const QString &authConfig ) const | ||
{ | ||
Q_UNUSED( authConfig ); | ||
|
||
return new QgsSimpleCopyExternalStorageFetchedContent( url ); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/*************************************************************************** | ||
qgssimplecopyexternalstorage.h | ||
-------------------------------------- | ||
Date : March 2021 | ||
Copyright : (C) 2021 by Julien Cabieces | ||
Email : julien dot cabieces at oslandia dot com | ||
*************************************************************************** | ||
* * | ||
* This program is free software; you can redistribute it and/or modify * | ||
* it under the terms of the GNU General Public License as published by * | ||
* the Free Software Foundation; either version 2 of the License, or * | ||
* (at your option) any later version. * | ||
* * | ||
***************************************************************************/ | ||
|
||
#ifndef QGSSIMPLECOPYEXTERNALSTORAGE_H | ||
#define QGSSIMPLECOPYEXTERNALSTORAGE_H | ||
|
||
#include "externalstorage/qgsexternalstorage.h" | ||
#include "qgis_core.h" | ||
#include "qgis_sip.h" | ||
|
||
#include <QPointer> | ||
|
||
///@cond PRIVATE | ||
#define SIP_NO_FILE | ||
|
||
class QgsCopyFileTask; | ||
|
||
/** | ||
* \ingroup core | ||
* \brief External storage implementation which simply copy the given resource | ||
* on a given directory file path. | ||
* | ||
* \since QGIS 3.22 | ||
*/ | ||
class CORE_EXPORT QgsSimpleCopyExternalStorage : public QgsExternalStorage | ||
{ | ||
public: | ||
|
||
QString type() const override; | ||
|
||
QgsExternalStorageStoredContent *store( const QString &filePath, const QString &url, const QString &authcfg = QString() ) const override; | ||
|
||
QgsExternalStorageFetchedContent *fetch( const QString &url, const QString &authConfig = QString() ) const override; | ||
}; | ||
|
||
/** | ||
* \ingroup core | ||
* \brief Class for Simple copy stored content | ||
* | ||
* \since QGIS 3.22 | ||
*/ | ||
class QgsSimpleCopyExternalStorageStoredContent : public QgsExternalStorageStoredContent | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
QgsSimpleCopyExternalStorageStoredContent( const QString &filePath, const QString &url, const QString &authcfg = QString() ); | ||
|
||
void cancel() override; | ||
|
||
QString url() const override; | ||
|
||
private: | ||
|
||
QPointer<QgsCopyFileTask> mCopyTask; | ||
QString mUrl; | ||
}; | ||
|
||
/** | ||
* \ingroup core | ||
* \brief Class for Simple copy fetched content | ||
* | ||
* \since QGIS 3.22 | ||
*/ | ||
class QgsSimpleCopyExternalStorageFetchedContent : public QgsExternalStorageFetchedContent | ||
{ | ||
Q_OBJECT | ||
|
||
public: | ||
|
||
QgsSimpleCopyExternalStorageFetchedContent( const QString &filePath ); | ||
|
||
QString filePath() const override; | ||
|
||
private: | ||
|
||
QString mFilePath; | ||
}; | ||
|
||
|
||
#endif // QGSSIMPLECOPYEXTERNALSTORAGE_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# -*- coding: utf-8 -*- | ||
"""QGIS Unit tests for Simple copy external storage | ||
.. note:: This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; either version 2 of the License, or | ||
(at your option) any later version. | ||
""" | ||
|
||
__author__ = 'Julien Cabieces' | ||
__date__ = '31/03/2021' | ||
__copyright__ = 'Copyright 2021, The QGIS Project' | ||
|
||
from shutil import rmtree | ||
import os | ||
import tempfile | ||
import time | ||
|
||
from utilities import unitTestDataPath, waitServer | ||
from test_qgsexternalstorage_base import TestPyQgsExternalStorageBase | ||
|
||
from qgis.PyQt.QtCore import QCoreApplication, QEventLoop, QUrl, QTemporaryDir | ||
|
||
from qgis.core import ( | ||
QgsApplication, | ||
QgsAuthMethodConfig, | ||
QgsExternalStorageFetchedContent) | ||
|
||
from qgis.testing import ( | ||
start_app, | ||
unittest, | ||
) | ||
|
||
|
||
class TestPyQgsExternalStorageSimpleCopy(TestPyQgsExternalStorageBase, unittest.TestCase): | ||
|
||
storageType = "SimpleCopy" | ||
badUrl = "/nothing/here/" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
"""Run before all tests:""" | ||
|
||
cls.temp_dir = QTemporaryDir() | ||
cls.url = cls.temp_dir.path() | ||
|
||
super().setUpClass() | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
"""Run after all tests""" | ||
super().tearDownClass() | ||
cls.temp_dir = None | ||
|
||
def testStoreMissingAuth(self): | ||
"""Override this one because there is authentification for SimpleCopy external storage""" | ||
pass | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |