mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 01:34:15 +02:00
supporting snaps
This commit is contained in:
@@ -2,7 +2,6 @@ from abc import ABC, abstractmethod
|
||||
from enum import Enum
|
||||
|
||||
from fpakman.core import resource
|
||||
from fpakman.core.structure import flatpak_cache_path
|
||||
|
||||
|
||||
class ApplicationStatus(Enum):
|
||||
@@ -49,6 +48,10 @@ class Application(ABC):
|
||||
def can_be_installed(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def can_be_refreshed(self):
|
||||
return self.installed
|
||||
|
||||
@abstractmethod
|
||||
def get_type(self):
|
||||
pass
|
||||
@@ -60,74 +63,12 @@ class Application(ABC):
|
||||
def is_library(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def supports_disk_cache(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_disk_cache_path(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_disk_icon_path(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_disk_data_path(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_data_to_cache(self):
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def fill_cached_data(self, data: dict):
|
||||
pass
|
||||
|
||||
|
||||
class FlatpakApplication(Application):
|
||||
|
||||
def __init__(self, base_data: ApplicationData, branch: str, arch: str, origin: str, runtime: bool, ref: str, commit: str):
|
||||
super(FlatpakApplication, self).__init__(base_data=base_data)
|
||||
self.ref = ref
|
||||
self.branch = branch
|
||||
self.arch = arch
|
||||
self.origin = origin
|
||||
self.runtime = runtime
|
||||
self.commit = commit
|
||||
|
||||
def is_incomplete(self):
|
||||
return self.base_data.description is None and self.base_data.icon_url
|
||||
|
||||
def has_history(self):
|
||||
return True
|
||||
|
||||
def has_info(self):
|
||||
return True
|
||||
|
||||
def can_be_downgraded(self):
|
||||
return not self.runtime
|
||||
|
||||
def can_be_uninstalled(self):
|
||||
return True
|
||||
|
||||
def can_be_installed(self):
|
||||
return True
|
||||
|
||||
def get_type(self):
|
||||
return 'flatpak'
|
||||
|
||||
def get_default_icon_path(self):
|
||||
return resource.get_path('img/flathub.svg')
|
||||
|
||||
def is_library(self):
|
||||
return self.runtime
|
||||
|
||||
def supports_disk_cache(self):
|
||||
return self.installed and not self.is_library()
|
||||
|
||||
@abstractmethod
|
||||
def get_disk_cache_path(self):
|
||||
return '{}/{}'.format(flatpak_cache_path, self.base_data.id)
|
||||
pass
|
||||
|
||||
def get_disk_icon_path(self):
|
||||
return '{}/icon.png'.format(self.get_disk_cache_path())
|
||||
@@ -135,16 +76,13 @@ class FlatpakApplication(Application):
|
||||
def get_disk_data_path(self):
|
||||
return '{}/data.json'.format(self.get_disk_cache_path())
|
||||
|
||||
@abstractmethod
|
||||
def get_data_to_cache(self):
|
||||
return {
|
||||
'description': self.base_data.description,
|
||||
'icon_url': self.base_data.icon_url,
|
||||
'latest_version': self.base_data.latest_version,
|
||||
'version': self.base_data.version,
|
||||
'name': self.base_data.name
|
||||
}
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def fill_cached_data(self, data: dict):
|
||||
for attr in self.get_data_to_cache().keys():
|
||||
if not getattr(self.base_data, attr):
|
||||
setattr(self.base_data, attr, data[attr])
|
||||
pass
|
||||
|
||||
def __str__(self):
|
||||
return '{} (id={}, name={})'.format(self.__class__.__name__, self.base_data.id, self.base_data.name)
|
||||
|
||||
Reference in New Issue
Block a user