<commit_before>#!/usr/bin/env python

"""Based on the PyQt4 port of the dialogs/trivialwizard example from Qt v4.x"""

import sys
import platform
import tarfile
import zipfile
import tempfile
import json
import urllib.request
from appdirs import AppDirs
import os
from PySide import QtGui, QtCore, QtNetwork

class DownloadWithProgress:
    def __init__(self, parent, url, downloaddir, finished, canceled, error, text):
        self.url = url
        self.downloaddir = downloaddir
        self.hasError = False
        self.parent = parent
        self.text = text
        self.manager = QtNetwork.QNetworkAccessManager(parent)
        self.finished = finished
        self.cancel = False
        self.error = error
        self.canceled = canceled

    def ended(self):
        if not self.cancel and not self.hasError:
            try:
                self.content = self.reply.readAll()
                if self.downloaddir:
                    fileInfo = QtCore.QFileInfo(self.url)
                    fileName = os.path.join(self.downloaddir, fileInfo.fileName())
                    f = QtCore.QFile(os.path.join(self.downloaddir, fileName))
                    f.open(QtCore.QIODevice.WriteOnly)
                    f.write(self.content)
                    f.close()
                self.finished(self.content)
            except OSError:
                QtGui.QMessageBox.critical(self.parent, "Network Error","An error occured downloading.")

    def cancelDownload(self):
        self.cancel = True
        self.reply.abort()
        if self.canceled:
            self.canceled()

    def download(self):
        self.pd = QtGui.QProgressDialog(self.text, "Abort", 0 ,100, self.parent)
        self.pd.setWindowModality(QtCore.Qt.WindowModal)
        self.pd.canceled.connect(self.cancelDownload)
        request = QtNetwork.QNetworkRequest()
        request.setUrl(QtCore.QUrl(self.url))

        self.reply = self.manager.get(request)
        self.reply.error[QtNetwork.QNetworkReply.NetworkError].connect(self.slotError)
        #self.reply.finished.connect(self.ended)
        self.reply.downloadProgress.connect(self.updateProgress)

        self.pd.exec_()
        self.ended()

    def updateProgress(self, rec, total):
        if total == -1:
            total = rec+1
        self.pd.setMaximum(total)
        self.pd.setValue(rec)




    def slotError(self):
        self.hasError = True
        if self.error:
            self.error()


    def sslErrors(self, errors):
        errorString = ", ".join([str(error.errorString()) for error in errors])

        ret = QtGui.QMessageBox.warning(self, "HTTP Example",
                "One or more SSL errors has occurred: %s" % errorString,
                QtGui.QMessageBox.Ignore | QtGui.QMessageBox.Abort)

        if ret == QtGui.QMessageBox.Ignore:
            self.http.ignoreSslErrors()


class Wizard(QtGui.QWizard):
    def createIntroPage(self):
        page = QtGui.QWizardPage()
        page.setTitle("PySpellbook")

        label = QtGui.QLabel("It seems you are running PySpellbook for the first time. Please allow this wizard to help you setting everything up.")
        label.setWordWrap(True)

        layout = QtGui.QVBoxLayout()
        layout.addWidget(label)
        page.setLayout(layout)

        return page

    def createPrincePage(self):

        def downloadPrince(parent, statusLabel):

            filename = ""
            if sys.platform == "win32":
                if platform.machine() == "AMD64":
                    filename = "prince-10r4p1-win64.zip"
                else:
                    filename = "prince-10r4p1-win32.zip"
            elif sys.platform == "linux":
                if platform.machine() == "x86_64":
                    filename = "prince-10r4-linux-generic-x86_64.tar.gz"
                else:
                    filename = "prince-10r4-linux-generic-x86.tar.gz"
            elif sys.platform == "darwin":
                filename = "prince-10r4-macosx.tar.gz"
            else:
                raise RuntimeError("Non supported platform")

            def download():
                tempdir = tempfile.mkdtemp(prefix="pySpellbook-")
                def error():
                    pass
                def canceled():
                    os.removedirs(tempdir)

                def finished(content):
                    statusLabel.setText("Extracting...")
                    dirs = AppDirs("pySpellbook")
                    datadir = dirs.user_data_dir
                    if filename.endswith("zip"):
                        zf = zipfile.ZipFile(os.path.join(tempdir, filename))<commit_msg>Wrong 32bit linux path for princexml<commit_after>#!/usr/bin/env python

"""Based on the PyQt4 port of the dialogs/trivialwizard example from Qt v4.x"""

import sys
import platform
import tarfile
import zipfile
import tempfile
import json
import urllib.request
from appdirs import AppDirs
import os
from PySide import QtGui, QtCore, QtNetwork

class DownloadWithProgress:
    def __init__(self, parent, url, downloaddir, finished, canceled, error, text):
        self.url = url
        self.downloaddir = downloaddir
        self.hasError = False
        self.parent = parent
        self.text = text
        self.manager = QtNetwork.QNetworkAccessManager(parent)
        self.finished = finished
        self.cancel = False
        self.error = error
        self.canceled = canceled

    def ended(self):
        if not self.cancel and not self.hasError:
            try:
                self.content = self.reply.readAll()
                if self.downloaddir:
                    fileInfo = QtCore.QFileInfo(self.url)
                    fileName = os.path.join(self.downloaddir, fileInfo.fileName())
                    f = QtCore.QFile(os.path.join(self.downloaddir, fileName))
                    f.open(QtCore.QIODevice.WriteOnly)
                    f.write(self.content)
                    f.close()
                self.finished(self.content)
            except OSError:
                QtGui.QMessageBox.critical(self.parent, "Network Error","An error occured downloading.")

    def cancelDownload(self):
        self.cancel = True
        self.reply.abort()
        if self.canceled:
            self.canceled()

    def download(self):
        self.pd = QtGui.QProgressDialog(self.text, "Abort", 0 ,100, self.parent)
        self.pd.setWindowModality(QtCore.Qt.WindowModal)
        self.pd.canceled.connect(self.cancelDownload)
        request = QtNetwork.QNetworkRequest()
        request.setUrl(QtCore.QUrl(self.url))

        self.reply = self.manager.get(request)
        self.reply.error[QtNetwork.QNetworkReply.NetworkError].connect(self.slotError)
        #self.reply.finished.connect(self.ended)
        self.reply.downloadProgress.connect(self.updateProgress)

        self.pd.exec_()
        self.ended()

    def updateProgress(self, rec, total):
        if total == -1:
            total = rec+1
        self.pd.setMaximum(total)
        self.pd.setValue(rec)




    def slotError(self):
        self.hasError = True
        if self.error:
            self.error()


    def sslErrors(self, errors):
        errorString = ", ".join([str(error.errorString()) for error in errors])

        ret = QtGui.QMessageBox.warning(self, "HTTP Example",
                "One or more SSL errors has occurred: %s" % errorString,
                QtGui.QMessageBox.Ignore | QtGui.QMessageBox.Abort)

        if ret == QtGui.QMessageBox.Ignore:
            self.http.ignoreSslErrors()


class Wizard(QtGui.QWizard):
    def createIntroPage(self):
        page = QtGui.QWizardPage()
        page.setTitle("PySpellbook")

        label = QtGui.QLabel("It seems you are running PySpellbook for the first time. Please allow this wizard to help you setting everything up.")
        label.setWordWrap(True)

        layout = QtGui.QVBoxLayout()
        layout.addWidget(label)
        page.setLayout(layout)

        return page

    def createPrincePage(self):

        def downloadPrince(parent, statusLabel):

            filename = ""
            if sys.platform == "win32":
                if platform.machine() == "AMD64":
                    filename = "prince-10r4p1-win64.zip"
                else:
                    filename = "prince-10r4p1-win32.zip"
            elif sys.platform == "linux":
                if platform.machine() == "x86_64":
                    filename = "prince-10r4-linux-generic-x86_64.tar.gz"
                else:
                    filename = "prince-10r4-linux-generic-i686.tar.gz"
            elif sys.platform == "darwin":
                filename = "prince-10r4-macosx.tar.gz"
            else:
                raise RuntimeError("Non supported platform")

            def download():
                tempdir = tempfile.mkdtemp(prefix="pySpellbook-")
                def error():
                    pass
                def canceled():
                    os.removedirs(tempdir)

                def finished(content):
                    statusLabel.setText("Extracting...")
                    dirs = AppDirs("pySpellbook")
                    datadir = dirs.user_data_dir
                    if filename.endswith("zip"):
                        zf = zipfile.ZipFile(os.path.join(tempdir, filename))
{'fraction_non_alphanumeric': 0.10019392372333549, 'fraction_numerical': 0.009588450764921354, 'mean_word_length': 1.8668931439159975, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 1}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 28, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4492492', 'n_tokens_mistral': 2739, 'n_tokens_neox': 2556, 'n_words': 550}