def _request_finished(self, reply): if reply.error() == QtNetwork.QNetworkReply.NoError: json_doc = QtCore.QJsonDocument.fromJson(reply.readAll()) json_obj = json_doc.object() latest_release = Version(json_obj['tag_name'].toString()) is_draft = json_obj['draft'].toBool() assets = json_obj['assets'].toArray() asset_url = '' if len(assets) > 0: asset = assets[0] asset_url = asset['browser_download_url'] if asset_url == '': LOGGER.error("Update Manager: Assets object was null or empty") self._setup_msgbox( "Error checking for Updates", 'No downloads available for this release. Redirect to website downloads page ?', "Release API 'Assets' object was null or empty") self._msgbox.exec() if self._msgbox.clickedButton() == self._msgox_btn_ok: QtGui.QDesktopServices.openUrl( QtCore.QUrl( "https://juliendz.github.io/imagius/#download")) return if latest_release > Version( settings.app_version) and is_draft is False: LOGGER.info("Update found. New version(%s) is available" % str(latest_release)) self._setup_msgbox( "Update info !", 'Update found. Latest version is (%s)' % str(latest_release), None, "Download", "Later") self._msgbox.exec() if self._msgbox.clickedButton() == self._msgox_btn_ok: QtGui.QDesktopServices.openUrl( QtCore.QUrl(asset_url.toString())) else: LOGGER.info("No updates found! Already on latest release.") msgbox = QtWidgets.QMessageBox() msgbox.setIcon(QtWidgets.QMessageBox.Information) msgbox.setWindowTitle('Update Info') msgbox.setText("No updates found! Already on latest release.") msgbox.exec() else: LOGGER.error( "Update Manager: Unable to retrieve updates from release api (Error: %s)" % error_code) self._setup_msgbox( "Error checking for Updates", 'Unable to load the release api. Redirect to website downloads page ?', 'Network Request Error Code: %s' % error_code) self._msgbox.exec() if self._msgbox.clickedButton() == self._msgox_btn_ok: QtGui.QDesktopServices.openUrl( QtCore.QUrl( "https://juliendz.github.io/imagius/#download"))
def _generate_thumb(self, abspath, thumb_size): thumb_bytes = io.BytesIO() try: ext = QtCore.QFileInfo(abspath).suffix() if ext == 'png': with Image.open(abspath) as image: image.verify() with Image.open(abspath) as image: image.thumbnail(thumb_size, Image.ANTIALIAS) image.save(thumb_bytes, image.format) except Exception as err: LOGGER.error('Error while generating thumbs: %s' % err) return thumb_bytes
def run_insert_query(self, query, params, commit=True): """ Description: Executes an insert sql query using Pythons DB-API (Parameter substitution) Arguments: 'query': The sql query string 'params' : tuple containing parameters """ cursor = self.conn.cursor() try: cursor.execute(query, params) if commit: self.conn.commit() except sqlite3.OperationalError as msg: LOGGER.error('[DB]: %s' % msg) except sqlite3.IntegrityError as msg: LOGGER.debug('[DB]: %s : %s : %s' % (msg, query, params)) LOGGER.error('[DB]: %s : %s' % (msg, params)) return cursor.lastrowid
def run_select_query(self, query, params=()): """ Description: Executes an select sql query using Pythons DB-API (Parameter substitution) Arguments: 'query: The sql query string 'params' : tuple containing parameters # Returns: False on failure | list[row_number][column_name] on success """ self.conn.row_factory = dict_factory cursor = self.conn.cursor() try: cursor.execute(query, params) except sqlite3.OperationalError as msg: LOGGER.error('[DB]: %s' % msg) data = cursor.fetchall() return data