def testFetchBadUrl(self): fetcher = QgsNetworkContentFetcherTask(QUrl('http://x')) self.loaded = False def check_reply(): r = fetcher.reply() assert r.error() != QNetworkReply.NoError self.loaded = True fetcher.fetched.connect(check_reply) QgsApplication.taskManager().addTask(fetcher) while not self.loaded: app.processEvents()
def download_report_dependency(self): self.qgis_utils.clear_message_bar_emitted.emit() if not self._downloading: # Already downloading report dependency? if self.qgis_utils.is_connected(TEST_SERVER): self._downloading = True fetcher_task = QgsNetworkContentFetcherTask(QUrl(URL_REPORTS_LIBRARIES)) fetcher_task.fetched.connect(functools.partial(self.save_dependency_file, fetcher_task)) QgsApplication.taskManager().addTask(fetcher_task) else: self.qgis_utils.message_emitted.emit( QCoreApplication.translate("ReportGenerator", "There was a problem connecting to Internet."), Qgis.Warning) self._downloading = False
def download_help(self): if is_connected(TEST_SERVER): self.btn_download_help.setEnabled(False) url = '/'.join( [HELP_DOWNLOAD, PLUGIN_VERSION, 'asistente_ladm_col_docs.zip']) fetcher_task = QgsNetworkContentFetcherTask(QUrl(url)) fetcher_task.taskCompleted.connect(self.enable_download_button) fetcher_task.fetched.connect(partial(self.save_file, fetcher_task)) QgsApplication.taskManager().addTask(fetcher_task) else: self.logger.warning_msg( __name__, QCoreApplication.translate( "AboutDialog", "There was a problem connecting to Internet."))
def testFetchUrlContent(self): fetcher = QgsNetworkContentFetcherTask( QUrl('http://localhost:' + str(self.port) + '/qgis_local_server/index.html')) self.loaded = False def check_reply(): r = fetcher.reply() assert r.error() == QNetworkReply.NoError, r.error() assert b'QGIS' in r.readAll() self.loaded = True fetcher.fetched.connect(check_reply) QgsApplication.taskManager().addTask(fetcher) while not self.loaded: app.processEvents()
def download_help(self): if self.qgis_utils.is_connected(TEST_SERVER): self.btn_download_help.setEnabled(False) url = '/'.join([ HELP_DOWNLOAD, PLUGIN_VERSION, 'asistente_ladm_col_docs_{lang}.zip'.format(lang=QGIS_LANG) ]) fetcher_task = QgsNetworkContentFetcherTask(QUrl(url)) fetcher_task.taskCompleted.connect(self.enable_download_button) fetcher_task.fetched.connect(partial(self.save_file, fetcher_task)) QgsApplication.taskManager().addTask(fetcher_task) else: self.qgis_utils.message_emitted.emit( QCoreApplication.translate( "AboutDialog", "There was a problem connecting to Internet."), Qgis.Warning)
def download_dependency(self, uri): if not uri: self.logger.warning_msg( __name__, QCoreApplication.translate( "Dependency", "Invalid URL to download dependency.")) self.logger.clear_message_bar() is_valid = self.check_if_dependency_is_valid() if is_valid: self.logger.debug( __name__, QCoreApplication.translate( "Dependency", "The {} dependency is already valid, so it won't be downloaded! (Dev, why did you asked to download it :P?)" .format(self.dependency_name))) return if not self._downloading: # Already downloading dependency? if is_connected(TEST_SERVER): self._downloading = True self.logger.clear_message_bar() self.logger.info_msg( __name__, QCoreApplication.translate( "Dependency", "A {} dependency will be downloaded...".format( self.dependency_name))) self.fetcher_task = QgsNetworkContentFetcherTask(QUrl(uri)) self.fetcher_task.begun.connect(self._task_begun) self.fetcher_task.progressChanged.connect( self._task_progress_changed) self.fetcher_task.fetched.connect( partial(self._save_dependency_file, self.fetcher_task)) self.fetcher_task.taskCompleted.connect(self._task_completed) QgsApplication.taskManager().addTask(self.fetcher_task) else: self.logger.clear_message_bar() self.logger.warning_msg( __name__, QCoreApplication.translate( "Dependency", "There was a problem connecting to Internet.")) self._downloading = False
def download_java_dependency(self, uri): self.logger.clear_message_bar() if not self._downloading: # Already downloading report dependency? if QGISUtils.is_connected(TEST_SERVER): self._downloading = True fetcher_task = QgsNetworkContentFetcherTask(QUrl(uri)) fetcher_task.begun.connect(self.task_begun) fetcher_task.progressChanged.connect( self.task_progress_changed) fetcher_task.fetched.connect( functools.partial(self.save_java_dependency_file, fetcher_task)) fetcher_task.taskCompleted.connect(self.task_completed) QgsApplication.taskManager().addTask(fetcher_task) else: self.logger.warning_msg( __name__, QCoreApplication.translate( "JavaUtils", "There was a problem connecting to Internet.")) self._downloading = False