Beispiel #1
0
 def cache_to_disk(self, pkg: SoftwarePackage, icon_bytes: bytes,
                   only_icon: bool):
     """
     Saves the package data to the hard disk.
     :param pkg:
     :param icon_bytes:
     :param only_icon: if only the icon should be saved
     :return:
     """
     if pkg.supports_disk_cache():
         self.serialize_to_disk(pkg, icon_bytes, only_icon)
Beispiel #2
0
    def downgrade(self, app: SoftwarePackage, root_password: str, handler: ProcessWatcher) -> bool:
        man = self._get_manager_for(app)

        if man and app.can_be_downgraded():
            mti = time.time()
            res = man.downgrade(app, root_password, handler)
            mtf = time.time()
            self.logger.info('Took {0:.2f} seconds'.format(mtf - mti))
            return res
        else:
            raise Exception("downgrade is not possible for {}".format(app.__class__.__name__))
Beispiel #3
0
 def fill(self, pkg: SoftwarePackage, sync: bool = False):
     """
     Adds a package which data must be read from the disk to a queue (if not sync)
     :param pkg:
     :param sync:
     :return:
     """
     if pkg and pkg.supports_disk_cache():
         if sync or not self._working:
             self._fill_cached_data(pkg)
         else:
             self.pkgs.append(pkg)
Beispiel #4
0
    def cache_to_disk(self, pkg: SoftwarePackage, icon_bytes: bytes,
                      only_icon: bool):
        """
        Saves the package data to the hard disk.
        :param pkg:
        :param icon_bytes:
        :param only_icon: if only the icon should be saved
        :return:
        """
        if self.context.disk_cache and pkg.supports_disk_cache():

            if not only_icon:
                Path(pkg.get_disk_cache_path()).mkdir(parents=True,
                                                      exist_ok=True)
                data = pkg.get_data_to_cache()

                if data:
                    with open(pkg.get_disk_data_path(), 'w+') as f:
                        f.write(json.dumps(data))

            if icon_bytes:
                Path(pkg.get_disk_cache_path()).mkdir(parents=True,
                                                      exist_ok=True)

                with open(pkg.get_disk_icon_path(), 'wb+') as f:
                    f.write(icon_bytes)
Beispiel #5
0
    def downgrade(self, app: SoftwarePackage, root_password: Optional[str],
                  handler: ProcessWatcher) -> bool:
        man = self._get_manager_for(app)

        if man and app.can_be_downgraded():
            mti = time.time()
            res = man.downgrade(app, root_password, handler)
            mtf = time.time()
            self.logger.info(f'Took {mtf - mti:.2f} seconds')
            return res
        else:
            raise Exception(
                f"Downgrading is not possible for {app.__class__.__name__}")
Beispiel #6
0
    def serialize_to_disk(self, pkg: SoftwarePackage, icon_bytes: bytes,
                          only_icon: bool):
        """
        Sames as above, but does not check if disk cache is enabled or supported by the package instance
        :param pkg:
        :param icon_bytes:
        :param only_icon:
        :return:
        """
        if not only_icon:
            Path(pkg.get_disk_cache_path()).mkdir(parents=True, exist_ok=True)
            data = pkg.get_data_to_cache()

            if data:
                with open(pkg.get_disk_data_path(), 'w+') as f:
                    f.write(json.dumps(data))

        if icon_bytes:
            Path(pkg.get_disk_cache_path()).mkdir(parents=True, exist_ok=True)

            with open(pkg.get_disk_icon_path(), 'wb+') as f:
                f.write(icon_bytes)
Beispiel #7
0
    def cache_to_disk(self, pkg: SoftwarePackage, icon_bytes: bytes, only_icon: bool):
        if pkg.supports_disk_cache():
            man = self._get_manager_for(pkg)

            if man:
                return man.cache_to_disk(pkg, icon_bytes=icon_bytes, only_icon=only_icon)
Beispiel #8
0
    def _fill_post_transaction_status(self, pkg: SoftwarePackage, installed: bool):
        pkg.installed = installed
        pkg.update = False

        if pkg.latest_version:
            pkg.version = pkg.latest_version