Exemplo n.º 1
0
    def uploadZip(self, zip_path, widget, convertLayer=None, convert=False):
        """Upload Zipfile"""
        def completeUpload(data):
            """On complete upload"""
            timer = QTimer(self)

            self.ui.uploadBar.hide()
            self.ui.uploadingLB.hide()
            self.ui.uploadBT.setEnabled(True)
            self.ui.bar.clearWidgets()
            self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Upload Complete'),
                                    level=QgsMessageBar.INFO, duration=5)

            def statusComplete(res):
                """On CartoDB import proccess complete o fail"""
                if res['state'] == 'complete':
                    timer.stop()
                    self.ui.statusLB.setText(QApplication.translate('CartoDBPlugin', 'Ready'))
                    widget.setStatus(res['state'], 100)
                    self.ui.bar.clearWidgets()
                    self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Table {} created').format(res['table_name']),
                                            level=QgsMessageBar.INFO, duration=5)

                    if convert:
                        self.convert2CartoDB(convertLayer if convertLayer is not None else widget.layer, res['table_name'])
                elif res['state'] == 'failure':
                    timer.stop()
                    self.ui.statusLB.setText(QApplication.translate('CartoDBPlugin', '{} failed, {}').format(
                        widget.layer.name(), res['get_error_text']['title']))
                    widget.setStatus(res['state'])
                    self.ui.bar.clearWidgets()
                    self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Error uploading {}').format(widget.layer.name()),
                                            level=QgsMessageBar.WARNING, duration=5)
                else:
                    widget.setStatus(res['state'])

            def timerComplete():
                """On timer complete, check import process in CartoDB Servers"""
                # pylint: disable-msg=E1101
                cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
                cartodb_api.fetchContent.connect(statusComplete)
                cartodb_api.checkUploadStatus(data['item_queue_id'])

            timer.timeout.connect(timerComplete)
            timer.start(500)


        # pylint: disable-msg=E1101
        cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
        cartodb_api.fetchContent.connect(completeUpload)
        cartodb_api.progress.connect(self.progressUpload)
        self.ui.uploadBar.show()
        self.ui.uploadBT.setEnabled(False)
        self.ui.uploadingLB.setText(QApplication.translate('CartoDBPlugin', 'Uploading {}').format(widget.layer.name()))
        self.ui.uploadingLB.show()
        self.ui.bar.clearWidgets()
        cartodb_api.upload(zip_path)
Exemplo n.º 2
0
 def uploadZip(self, zipPath, widget):
     cartodbApi = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
     cartodbApi.fetchContent.connect(self.completeUpload)
     cartodbApi.progress.connect(self.progressUpload)
     self.ui.uploadBar.show()
     self.ui.uploadBT.setEnabled(False)
     self.ui.uploadingLB.setText(QApplication.translate('CartoDBPlugin', 'Uploading {}').format(widget.layer.name()))
     self.ui.uploadingLB.show()
     self.ui.bar.clearWidgets()
     cartodbApi.upload(zipPath)
Exemplo n.º 3
0
 def uploadZip(self, zipPath, widget):
     cartodbApi = CartoDBApi(self.currentUser, self.currentApiKey,
                             self.currentMultiuser)
     cartodbApi.fetchContent.connect(self.completeUpload)
     cartodbApi.progress.connect(self.progressUpload)
     self.ui.uploadBar.show()
     self.ui.uploadBT.setEnabled(False)
     self.ui.uploadingLB.setText(
         QApplication.translate('CartoDBPlugin',
                                'Uploading {}').format(widget.layer.name()))
     self.ui.uploadingLB.show()
     self.ui.bar.clearWidgets()
     cartodbApi.upload(zipPath)
Exemplo n.º 4
0
 def upload(self):
     registry = QgsMapLayerRegistry.instance()
     for layerItem in self.ui.layersList.selectedItems():
         widget = self.ui.layersList.itemWidget(layerItem)
         qDebug('Layer: ' + str(widget.layer.storageType()))
         if widget.layer.storageType() == 'ESRI Shapefile':
             zipPath = self.zipLayer(widget.layer)
             cartodbApi = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
             cartodbApi.fetchContent.connect(self.completeUpload)
             cartodbApi.progress.connect(self.progressUpload)
             self.ui.uploadBar.show()
             self.ui.uploadBT.setEnabled(False)
             self.ui.uploadingLB.setText('Uploading {}'.format(widget.layer.name()))
             self.ui.uploadingLB.show()
             cartodbApi.upload(zipPath)
Exemplo n.º 5
0
    def uploadZip(self, zip_path, widget, convertLayer=None, convert=False):
        """Upload Zipfile"""
        def completeUpload(data):
            """On complete upload"""
            timer = QTimer(self)
            qDebug('data: {}'.format(str(data)))

            if 'error' in data and data['error'] is not None:
                self.ui.bar.clearWidgets()
                self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Error uploading layer: {}').format(data['error']),
                                        level=QgsMessageBar.CRITICAL, duration=5)
                widget.setStatus('Error', 0)
                return

            self.ui.uploadBar.hide()
            self.ui.uploadingLB.hide()
            self.ui.uploadBT.setEnabled(True)
            self.ui.bar.clearWidgets()
            self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Upload Complete'),
                                    level=QgsMessageBar.INFO, duration=5)

            def statusComplete(res):
                """On CARTO import proccess complete o fail"""
                if res['state'] == 'complete':
                    timer.stop()
                    self.ui.statusLB.setText(QApplication.translate('CartoDBPlugin', 'Ready'))
                    widget.setStatus(res['state'], 100)
                    self.ui.bar.clearWidgets()
                    self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Table {} created').format(res['table_name']),
                                            level=QgsMessageBar.INFO, duration=5)

                    if convert:
                        self.convert2CartoDB(convertLayer if convertLayer is not None else widget.layer, res['table_name'])
                elif res['state'] == 'failure':
                    timer.stop()
                    self.ui.statusLB.setText(QApplication.translate('CartoDBPlugin', '{} failed, {}').format(
                        widget.layer.name(), res['get_error_text']['title']))
                    widget.setStatus(res['state'])
                    self.ui.bar.clearWidgets()
                    self.ui.bar.pushMessage(QApplication.translate('CartoDBPlugin', 'Error uploading {}').format(widget.layer.name()),
                                            level=QgsMessageBar.WARNING, duration=5)
                else:
                    widget.setStatus(res['state'])

            def timerComplete():
                """On timer complete, check import process in CARTO Servers"""
                # pylint: disable-msg=E1101
                cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
                cartodb_api.fetchContent.connect(statusComplete)
                cartodb_api.checkUploadStatus(data['item_queue_id'])

            timer.timeout.connect(timerComplete)
            timer.start(500)


        # pylint: disable-msg=E1101
        cartodb_api = CartoDBApi(self.currentUser, self.currentApiKey, self.currentMultiuser)
        cartodb_api.fetchContent.connect(completeUpload)
        cartodb_api.progress.connect(self.progressUpload)
        self.ui.uploadBar.show()
        self.ui.uploadBT.setEnabled(False)
        self.ui.uploadingLB.setText(QApplication.translate('CartoDBPlugin', 'Uploading {}').format(widget.layer.name()))
        self.ui.uploadingLB.show()
        self.ui.bar.clearWidgets()
        cartodb_api.upload(zip_path)