Example #1
0
    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 = []
Example #2
0
    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 __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 = []
Example #4
0
 def __init__(self, file_in, response, parent=None):
     super(Apply, self).__init__(parent)
     self.setMinimumSize(400, 250)
     self.file_in = file_in
     self.response = response
     self.setWindowTitle("Applying")
     self.error_msg = QtGui.QMessageBox()
     self.error_msg.setIcon(QtGui.QMessageBox.Critical)
     self.error_msg.setWindowTitle("Error")
     self.buttonCancel = QtGui.QPushButton()
     self.buttonCancel.setText("Cancel")
     self.buttonCancel.clicked.connect(self.cancel)
     self.progress = QtGui.QProgressBar(self)
     self.lbl1 = QtGui.QLabel()
     gif = os.path.abspath(
         "/usr/lib/resetter/data/icons/chassingarrows.gif")
     self.movie = QtGui.QMovie(gif)
     self.movie.setScaledSize(QtCore.QSize(20, 20))
     self.pixmap = QtGui.QPixmap(
         "/usr/lib/resetter/data/icons/checkmark.png")
     self.pixmap2 = self.pixmap.scaled(20, 20)
     verticalLayout = QtGui.QVBoxLayout(self)
     verticalLayout.addWidget(self.lbl1)
     verticalLayout.addWidget(self.progress)
     gridLayout = QtGui.QGridLayout()
     self.labels = {}
     for i in range(1, 6):
         for j in range(1, 3):
             self.labels[(i, j)] = QtGui.QLabel()
             self.labels[(i, j)].setMinimumHeight(20)
             gridLayout.addWidget(self.labels[(i, j)], i, j)
     gridLayout.setAlignment(QtCore.Qt.AlignCenter)
     self.labels[(1, 2)].setText("Loading Apps")
     self.labels[(2, 2)].setText("Removing Apps")
     self.labels[(3, 2)].setText("Deleting Users")
     self.labels[(4, 2)].setText("Cleaning Up")
     if self.response:
         self.labels[(5, 2)].setText("Removing old kernels")
     verticalLayout.addSpacing(20)
     verticalLayout.addLayout(gridLayout)
     verticalLayout.addWidget(self.buttonCancel, 0, QtCore.Qt.AlignRight)
     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.progressView = ProgressThread(self.file_in)
     self.account = AccountDialog(self)
     self.connect(self.progressView,
                  QtCore.SIGNAL("updateProgressBar(int, bool)"),
                  self.updateProgressBar)
     self._cache = self.progressView._cache
     self.aprogress = UIAcquireProgress(self.progress, self.lbl1)
     self.iprogress = UIInstallProgress(self.progress, self.lbl1)
     self.addUser()
 def __init__(self, f_name, action, answer):
     self.win = None
     self.screen = curses.initscr()
     self.aprogress = UIAcquireProgress(6)
     self.iprogress = UIInstallProgress(6)
     self.answer = answer
     self.cache = apt.Cache(None)
     self.cache.open()
     self.percent = ''
     self.load(f_name, action)
Example #6
0
 def __init__(self, file_in, action, action_type, parent=None):
     super(Install, self).__init__(parent)
     self.setMinimumSize(305, 100)
     self.file_in = file_in
     self.setWindowTitle("Working...")
     self.error_msg = QtGui.QMessageBox()
     self.error_msg.setIcon(QtGui.QMessageBox.Critical)
     self.error_msg.setWindowTitle("Error")
     self.buttonCancel = QtGui.QPushButton()
     self.buttonCancel.setText("Cancel")
     self.buttonCancel.clicked.connect(self.cancel)
     self.progress = QtGui.QProgressBar(self)
     self.lbl1 = QtGui.QLabel()
     gif = os.path.abspath(
         "/usr/lib/resetter/data/icons/chassingarrows.gif")
     self.movie = QtGui.QMovie(gif)
     self.movie.setScaledSize(QtCore.QSize(20, 20))
     self.pixmap = QtGui.QPixmap(
         "/usr/lib/resetter/data/icons/checkmark.png")
     self.pixmap2 = self.pixmap.scaled(20, 20)
     verticalLayout = QtGui.QVBoxLayout(self)
     verticalLayout.addWidget(self.lbl1)
     verticalLayout.addWidget(self.progress)
     gridLayout = QtGui.QGridLayout()
     self.labels = {}
     for i in range(1, 3):
         for j in range(1, 3):
             self.labels[(i, j)] = QtGui.QLabel()
             self.labels[(i, j)].setMinimumHeight(20)
             gridLayout.addWidget(self.labels[(i, j)], i, j)
     gridLayout.setAlignment(QtCore.Qt.AlignCenter)
     self.labels[(1, 2)].setText("Loading packages")
     self.labels[(2, 2)].setText(action)
     verticalLayout.addSpacing(20)
     verticalLayout.addLayout(gridLayout)
     verticalLayout.addWidget(self.buttonCancel, 0, QtCore.Qt.AlignRight)
     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.installProgress = ProgressThread(file_in, action_type)
     self.connect(self.installProgress,
                  QtCore.SIGNAL("updateProgressBar(int, bool)"),
                  self.updateProgressBar)
     self.install_cache = self.installProgress._cache
     self.aprogress = UIAcquireProgress(self.progress, self.lbl1, False)
     self.iprogress = UIInstallProgress(self.progress, self.lbl1)
     self.start()
Example #7
0
 def __init__(self, f_name, action, answer):
     self.directory = ".resetter-cli/data"
     self.user = os.environ['SUDO_USER']
     working_dir = '/home/{}'.format(self.user)
     os.chdir(working_dir)
     if os.path.isdir(self.directory):
         os.chdir(self.directory)
     self.win = None
     #self.screen = curses.initscr()
     self.aprogress = UIAcquireProgress(8)
     self.iprogress = UIInstallProgress(8)
     self.answer = answer
     self.cache = apt.Cache(None)
     self.cache.open()
     self.percent = ''
     self.load(f_name, action)
Example #8
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)
Example #9
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)
Example #10
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")
Example #11
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.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)
Example #12
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)
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)