Beispiel #1
0
class ProgressThread(QtCore.QThread):
    conclude_op = QtCore.pyqtSignal()

    def __init__(self, file_in, install):
        QtCore.QThread.__init__(self)
        self.op_progress = None
        self.cache = apt.Cache(self.op_progress)
        self.cache.open()
        self.file_in = file_in
        self.isDone = False
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        handler = logging.FileHandler('/var/log/resetter/resetter.log')
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter(
            '%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s'
        )
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)
        self.install = install

        self.aprogress = UIAcquireProgress(False)
        self.thread1 = QtCore.QThread()
        self.aprogress.moveToThread(self.thread1)
        self.thread1.started.connect(
            lambda: self.aprogress.play(0.0, False, ""))
        self.aprogress.finished.connect(self.thread1.quit)

        self.iprogress = UIInstallProgress()
        self.thread2 = QtCore.QThread()
        self.iprogress.moveToThread(self.thread2)
        self.thread2.started.connect(lambda: self.iprogress.play(0.0, ""))
        self.iprogress.finished.connect(self.thread2.quit)

        self.broken_list = []

    def lineCount(self, file_path):
        x = open(file_path).readlines()
        line_count = len(x)
        return line_count

    def run(self):
        if self.lineCount(self.file_in) != 0:
            loading = 0
            x = float(100) / self.lineCount(self.file_in)
            with open(self.file_in) as packages:
                for pkg_name in packages:
                    try:
                        loading += x
                        self.pkg = self.cache[pkg_name.strip()]
                        self.pkg.mark_delete(True, True)
                        self.emit(
                            QtCore.SIGNAL('updateProgressBar(int, bool)'),
                            loading, self.isDone)
                    except (KeyError, SystemError) as error:
                        self.logger.error("{}".format(error))
                        if self.pkg.is_inst_broken or self.pkg.is_now_broken:
                            self.broken_list.append(self.pkg.fullname)
                            self.logger.critical("{}".format(error))
                            continue
                        else:
                            text = "Error loading apps"
                            error2 = "Problems trying to remove: {}\n{}".format(
                                self.pkg.fullname, error.message)
                            self.logger.critical("{} {}".format(error,
                                                                error2,
                                                                exc_info=True))
                            self.emit(
                                QtCore.SIGNAL('showError(QString, QString)'),
                                error2, text)
                            break
                self.thread1.start()
                self.thread2.start()
                self.removePackages()
                self.conclude_op.emit()
        else:
            print "All removable packages are already removed"
            self.emit(QtCore.SIGNAL('updateProgressBar(int, bool)'), 100, True)

    def removePackages(self):
        self.logger.info("Removing Programs")
        try:
            package = self.cache['snapd']
            package.mark_delete(True, True)
            self.logger.info("Keep Count before commit: {}".format(
                self.cache.keep_count))
            self.logger.info("Delete Count before commit: {}".format(
                self.cache.delete_count))
            self.logger.info("Broken Count before commit: {}".format(
                self.cache.broken_count))
            self.cache.commit(self.aprogress, self.iprogress)
            self.logger.info("Broken Count after commit: {}".format(
                self.cache.broken_count))
        except Exception as e:
            self.logger.error("Error: [{}]".format(e, exc_info=True))
            error = "Problems trying to remove: {}\n{}".format(
                self.pkg.fullname, e.message)
            text = "Package removal failed"
            self.emit(QtCore.SIGNAL('showError(QString, QString)'), error,
                      text)
Beispiel #2
0
class ProgressThread(QtCore.QThread):
    end_of_threads = QtCore.pyqtSignal()
    start_op = QtCore.pyqtSignal(str, str)  # Error string transmitter
    start_op1 = QtCore.pyqtSignal(int, bool)  # Loading progress transmitter


    def __init__(self, file_in, install):
        QtCore.QThread.__init__(self)
        self.cache = apt.Cache(None)
        self.cache.open()
        self.file_in = file_in
        self.install = install
        self.isDone = False
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        handler = logging.FileHandler('/var/log/resetter/resetter.log')
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)
        self.resolver = apt.cache.ProblemResolver(self.cache)
        self.aprogress = UIAcquireProgress(False)
        self.thread1 = QtCore.QThread()
        self.aprogress.moveToThread(self.thread1)
        self.thread1.started.connect(lambda: self.aprogress.play(0.0, False, ""))
        self.aprogress.finished.connect(self.thread1.quit)

        self.thread2 = QtCore.QThread()
        self.iprogress = UIInstallProgress()
        self.iprogress.moveToThread(self.thread2)
        self.thread2.started.connect(lambda: self.iprogress.play(0.0, ""))
        self.iprogress.finished.connect(self.thread2.quit)
        self.broken_list = []

    def run(self):
        lc = UsefulTools().lineCount(self.file_in)
        if lc > 0:
            loading = 0
            x = float(100) / lc
            with open(self.file_in) as packages:
                for pkg_name in packages:
                    try:
                        loading += x
                        self.pkg = self.cache[pkg_name.strip()]
                        if not self.install:
                            self.pkg.mark_delete(True, True)
                            print ("{} will be removed".format(self.pkg))
                        else:
                            self.pkg.mark_install()
                            print ("{} will be installed ".format(self.pkg.shortname))
                        self.start_op1.emit(loading, self.isDone)
                    except (KeyError, SystemError) as error:
                        # if resolver cannot find a way to cleanly install packages, move it to the broken list
                        if self.pkg.is_inst_broken:
                            self.broken_list.append(self.pkg.fullname)
                            self.logger.critical("{}".format(error), exc_info=True)
                            continue
                        else:
                            text = "Error loading apps"
                            error2 = "Problems trying to install: {}\n{}".format(self.pkg.fullname, error.message)
                            self.logger.critical("{} {}".format(error, error2, exc_info=True))
                            self.start_op.emit(error2, text)
                            break
                self.thread1.start()
                self.thread2.start()
                self.installPackages()
                self.end_of_threads.emit()
        else:
            print ("All removable packages are already removed")
            self.start_op1.emit(100, True)

    def installPackages(self):
        try:
            self.logger.info("treating Packages")
            self.cache.commit(self.aprogress, self.iprogress)
        except Exception as e:
            self.logger.error("Action on package failed. Error: [{}]".format(e, exc_info=True))
            error = str(e)
            if self.install:
                text = "Package install failed"
                self.start_op.emit(error, text)
            else:
                text = "Package removal failed"
                self.start_op.emit(error, text)
Beispiel #3
0
class ProgressThread(QtCore.QThread):

    start_op = QtCore.pyqtSignal(str, str)  # Error string transmitter
    start_op1 = QtCore.pyqtSignal(int, bool)  # Loading progress transmitter
    conclude_op = QtCore.pyqtSignal()
    start_op2 = QtCore.pyqtSignal(bool)


    def __init__(self, file_in, install):

        QtCore.QThread.__init__(self)
        self.cache = apt.Cache(None)
        self.cache.open()
        self.file_in = file_in
        self.isDone = False
        self.error_msg = QMessageBox()
        self.error_msg.setIcon(QMessageBox.Critical)
        self.error_msg.setWindowTitle("Error")
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        handler = logging.FileHandler('/var/log/resetter/resetter.log')
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)
        self.install = install

        self.aprogress = UIAcquireProgress(False)
        self.thread1 = QtCore.QThread()
        self.aprogress.moveToThread(self.thread1)
        self.thread1.started.connect(lambda: self.aprogress.play(0.0, False, ""))
        self.aprogress.finished.connect(self.thread1.quit)

        self.iprogress = UIInstallProgress()
        self.thread2 = QtCore.QThread()
        self.iprogress.moveToThread(self.thread2)
        self.thread2.started.connect(lambda: self.iprogress.play(0.0, ""))
        self.iprogress.finished.connect(self.thread2.quit)

        self.broken_list = []

    def lineCount(self, file_path):
        x = open(file_path).readlines()
        line_count = len(x)
        return line_count

    def run(self):
        if self.lineCount(self.file_in) != 0:
            loading = 0
            x = float(100) / (self.lineCount(self.file_in)+1)
            with open(self.file_in) as packages:
                for pkg_name in packages:
                    try:
                        loading += x
                        self.pkg = self.cache[pkg_name.strip()]
                        self.pkg.mark_delete(True, True)
                        self.start_op1.emit(loading, self.isDone)
                    except (KeyError, SystemError) as error:
                        self.logger.error("{}".format(error))
                        if self.pkg.is_inst_broken or self.pkg.is_now_broken:
                            self.broken_list.append(self.pkg.fullname)
                            self.logger.critical("{}".format(error))
                            continue
                        else:
                            text = "Error loading apps"
                            error2 = "Problems trying to remove: {}\n{}".format(self.pkg.fullname, str(error))
                            self.logger.critical("{} {}".format(error, error2, exc_info=True))
                            self.start_op.emit(error2, text)
                            break
                self.thread1.start()
                self.thread2.start()
                self.removePackages()
                self.removeSystemDirs()
                self.start_op2.emit(False)
                self.fixBroken()
                self.conclude_op.emit()
        else:
            print ("All removable packages are already removed")
            self.start_op1.emit(100, True)

    def removePackages(self):
        self.logger.info("Removing Programs")
        try:
            package = self.cache['snapd']
            package.mark_delete(True, True)
            self.logger.info("Keep Count before commit: {}".format(self.cache.keep_count))
            self.logger.info("Delete Count before commit: {}".format(self.cache.delete_count))
            self.logger.info("Broken Count before commit: {}".format(self.cache.broken_count))
            self.cache.commit(self.aprogress, self.iprogress)
            self.logger.info("Broken Count after commit: {}".format(self.cache.broken_count))
        except Exception as e:
            self.logger.error("Error: [{}]".format(e, exc_info=True))
            error = "Problems trying to remove: {}\n{}".format(self.pkg.fullname, str(e))
            text = "Package removal failed"
            self.start_op.emit(error, text)

    def removeSystemDirs(self):
        self.logger.info("Removing Dirs")
        self.logger.critical("aaaaaa")
        try:
            p = subprocess.check_output(['bash', '/usr/lib/resetter/data/scripts/reset-dirs.sh'])
            print ("ccalled")
            self.start_op1.emit(100, self.isDone)
        except subprocess.CalledProcessError as e:
            self.logger.error("unable to add user Error: {}".format(e.output))
        else:
            self.logger.info("Default user added")
class ProgressThread(QtCore.QThread):

    conclude_op = QtCore.pyqtSignal()

    def __init__(self, file_in, install):
        QtCore.QThread.__init__(self)
        self.op_progress = None
        self.cache = apt.Cache(self.op_progress)
        self.cache.open()
        self.file_in = file_in
        self.isDone = False
        self.error_msg = QtGui.QMessageBox()
        self.error_msg.setIcon(QtGui.QMessageBox.Critical)
        self.error_msg.setWindowTitle("Error")
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        handler = logging.FileHandler('/var/log/resetter/resetter.log')
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)
        self.install = install

        self.aprogress = UIAcquireProgress(False)
        self.thread1 = QtCore.QThread()
        self.aprogress.moveToThread(self.thread1)
        self.thread1.started.connect(lambda: self.aprogress.play(0.0, False, ""))
        self.aprogress.finished.connect(self.thread1.quit)

        self.iprogress = UIInstallProgress()
        self.thread2 = QtCore.QThread()
        self.iprogress.moveToThread(self.thread2)
        self.thread2.started.connect(lambda: self.iprogress.play(0.0, ""))
        self.iprogress.finished.connect(self.thread2.quit)

        self.broken_list = []

    def lineCount(self, appfile):
        try:
            p = subprocess.Popen(['wc', '-l', appfile], stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            result, err = p.communicate()
            return int(result.strip().split()[0])
        except subprocess.CalledProcessError:
            pass

    def removePackages(self):
        self.logger.info("Removing Programs")
        try:
            self.logger.info("Keep Count before commit: {}".format(self.cache.keep_count))
            self.logger.info("Delete Count before commit: {}".format(self.cache.delete_count))
            self.logger.info("Broken Count before commit: {}".format(self.cache.broken_count))
            self.cache.commit(self.aprogress, self.iprogress)
            self.logger.info("Broken Count after commit: {}".format(self.cache.broken_count))
        except Exception as e:
            self.logger.error("Error: [{}]".format(e, exc_info=True))
            error = e.message
            text = "Package removal failed"
            self.emit(QtCore.SIGNAL('showError(QString, QString)'), error, text)

    def run(self):
        if self.lineCount(self.file_in) != 0:
            loading = 0
            x = float(100) / self.lineCount(self.file_in)
            with open(self.file_in) as packages:
                for pkg_name in packages:
                    try:
                        loading += x
                        self.pkg = self.cache[pkg_name.strip()]
                        self.pkg.mark_delete(True, True)
                        self.emit(QtCore.SIGNAL('updateProgressBar(int, bool)'), loading, self.isDone)
                    except (KeyError, SystemError) as error:
                        self.logger.error("{}".format(error))
                        if self.pkg.is_inst_broken or self.pkg.is_now_broken:
                            self.broken_list.append(self.pkg.fullname)
                        self.logger.critical("{}".format(error))
                        continue
                self.thread1.start()
                self.thread2.start()
                self.removePackages()
                self.conclude_op.emit()

        else:
            print "All removable packages are already removed"
            self.emit(QtCore.SIGNAL('updateProgressBar(int, bool)'), 100, True)
class ProgressThread(QtCore.QThread):
    conclude_op = QtCore.pyqtSignal()

    def __init__(self, file_in, install):
        QtCore.QThread.__init__(self)
        self.op_progress = None
        self.cache = apt.Cache(self.op_progress)
        self.cache.open()
        self.file_in = file_in
        self.isDone = False
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        handler = logging.FileHandler('/var/log/resetter/resetter.log')
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)
        self.install = install

        self.aprogress = UIAcquireProgress(False)
        self.thread1 = QtCore.QThread()
        self.aprogress.moveToThread(self.thread1)
        self.thread1.started.connect(lambda: self.aprogress.play(0.0, False, ""))
        self.aprogress.finished.connect(self.thread1.quit)

        self.iprogress = UIInstallProgress()
        self.thread2 = QtCore.QThread()
        self.iprogress.moveToThread(self.thread2)
        self.thread2.started.connect(lambda: self.iprogress.play(0.0, ""))
        self.iprogress.finished.connect(self.thread2.quit)

        self.broken_list = []

    def lineCount(self, file_path):
        x = open(file_path).readlines()
        line_count = len(x)
        return line_count

    def run(self):
        if self.lineCount(self.file_in) != 0:
            loading = 0
            x = float(100) / self.lineCount(self.file_in)
            with open(self.file_in) as packages:
                for pkg_name in packages:
                    try:
                        loading += x
                        self.pkg = self.cache[pkg_name.strip()]
                        self.pkg.mark_delete(True, True)
                        self.emit(QtCore.SIGNAL('updateProgressBar(int, bool)'), loading, self.isDone)
                    except (KeyError, SystemError) as error:
                        self.logger.error("{}".format(error))
                        if self.pkg.is_inst_broken or self.pkg.is_now_broken:
                            self.broken_list.append(self.pkg.fullname)
                            self.logger.critical("{}".format(error))
                            continue
                        else:
                            text = "Error loading apps"
                            error2 = "Problems trying to remove: {}\n{}".format(self.pkg.fullname, error.message)
                            self.logger.critical("{} {}".format(error, error2, exc_info=True))
                            self.emit(QtCore.SIGNAL('showError(QString, QString)'), error2, text)
                            break
                self.thread1.start()
                self.thread2.start()
                self.removePackages()
                self.conclude_op.emit()
        else:
            print "All removable packages are already removed"
            self.emit(QtCore.SIGNAL('updateProgressBar(int, bool)'), 100, True)

    def removePackages(self):
        self.logger.info("Removing Programs")
        try:
            package = self.cache['snapd']
            package.mark_delete(True, True)
            self.logger.info("Keep Count before commit: {}".format(self.cache.keep_count))
            self.logger.info("Delete Count before commit: {}".format(self.cache.delete_count))
            self.logger.info("Broken Count before commit: {}".format(self.cache.broken_count))
            self.cache.commit(self.aprogress, self.iprogress)
            self.logger.info("Broken Count after commit: {}".format(self.cache.broken_count))
        except Exception as e:
            self.logger.error("Error: [{}]".format(e, exc_info=True))
            error = "Problems trying to remove: {}\n{}".format(self.pkg.fullname, e.message)
            text = "Package removal failed"
            self.emit(QtCore.SIGNAL('showError(QString, QString)'), error, text)
class ProgressThread(QtCore.QThread):

    end_of_threads = QtCore.pyqtSignal()

    def __init__(self, file_in, install):
        QtCore.QThread.__init__(self)
        self.cache = apt.Cache(None)
        self.cache.open()
        self.file_in = file_in
        self.install = install
        self.isDone = False
        self.logger = logging.getLogger(__name__)
        self.logger.setLevel(logging.DEBUG)
        handler = logging.FileHandler('/var/log/resetter/resetter.log')
        handler.setLevel(logging.DEBUG)
        formatter = logging.Formatter('%(asctime)s - %(name)s - %(funcName)s - %(levelname)s - %(message)s')
        handler.setFormatter(formatter)
        self.logger.addHandler(handler)
        self.resolver = apt.cache.ProblemResolver(self.cache)
        self.aprogress = UIAcquireProgress(False)
        self.thread1 = QtCore.QThread()
        self.aprogress.moveToThread(self.thread1)
        self.thread1.started.connect(lambda: self.aprogress.play(0.0, False, ""))
        self.aprogress.finished.connect(self.thread1.quit)

        self.error_msg = QtGui.QMessageBox()
        self.error_msg.setIcon(QtGui.QMessageBox.Critical)
        self.error_msg.setWindowTitle("Error")

        self.thread2 = QtCore.QThread()
        self.iprogress = UIInstallProgress()
        self.iprogress.moveToThread(self.thread2)
        self.thread2.started.connect(lambda: self.iprogress.play(0.0, ""))
        self.iprogress.finished.connect(self.thread2.quit)
        self.broken_list = []

    def lineCount(self):
        try:
            p = subprocess.Popen(['wc', '-l', self.file_in], stdout=subprocess.PIPE,
                                 stderr=subprocess.PIPE)
            result, err = p.communicate()
            return int(result.strip().split()[0])
        except subprocess.CalledProcessError:
            pass

    def run(self):
        if self.lineCount() > 0:
            loading = 0
            x = float(100) / self.lineCount()
            with open(self.file_in) as packages:
                for pkg_name in packages:
                    try:
                        loading += x
                        self.pkg = self.cache[pkg_name.strip()]
                        if not self.install:
                            self.pkg.mark_delete(True, True)
                            print "{} will be removed".format(self.pkg)
                        else:
                            self.pkg.mark_install()
                            print "{} will be installed ".format(self.pkg.shortname)
                        self.emit(QtCore.SIGNAL('updateProgressBar(int, bool)'), loading, self.isDone)
                    except (KeyError, SystemError) as error:
                        # if resolver cannot find a way to cleanly install packages, move it to the broken list
                        if self.pkg.is_inst_broken:
                            self.broken_list.append(self.pkg.fullname)
                        self.logger.critical("{}".format(error), exc_info=True)
                        continue
                self.thread1.start()
                self.thread2.start()
                self.installPackages()
                self.end_of_threads.emit()
        else:
            print "All removable packages are already removed"
            self.emit(QtCore.SIGNAL('updateProgressBar(int, bool)'), 100, True)

    def installPackages(self):
        try:
            self.logger.info("treating Packages")
            self.cache.commit(self.aprogress, self.iprogress)
        except Exception as e:
            self.logger.error("Action on package failed. Error: [{}]".format(e, exc_info=True))
            error = e.message
            if self.install:
                text = "Package install failed"
                self.emit(QtCore.SIGNAL('showError(QString, QString)'), error, text)
            else:
                text = "Package removal failed"
                self.emit(QtCore.SIGNAL('showError(QString, QString)'), error, text)