Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/models
diff options
context:
space:
mode:
authorAnton Hvornum <anton@hvornum.se>2022-02-02 14:22:52 +0100
committerGitHub <noreply@github.com>2022-02-02 14:22:52 +0100
commitc08520f9902aeb1b4ce22e1159060792081b0327 (patch)
tree934ac279ac0e6d675b409d7936c97ce73d721a6a /archinstall/lib/models
parentdfd064a57f6a0006e9fc614ea229fd9883722085 (diff)
SysCommand() to remove ANSII VT100 Esc codes & archlinux-keyring fix (#933)
* Fixed SysCommandWorker() so that it removes ANSII VT100 escape codes. I also moved package.py into it's own folder, as that's something I want to expand on a lot, so package related stuff should go in there. I created a installed_package() function which gets information about the locally installed package. I changed so that find_packages() and find_package() returns a data-model instead for the package information. This should unify and make sure we detect issues down the line. * Working on structuring .version constructor that works with BaseModel * Added version contructors to VersionDef(). Also added __eq__ and __lt__ to LocalPackage() and PackageSearchResult(). * removed debug and added a TODO * Removed whitespace * Removed mirror-database function from myrepo
Diffstat (limited to 'archinstall/lib/models')
-rw-r--r--archinstall/lib/models/__init__.py129
1 files changed, 129 insertions, 0 deletions
diff --git a/archinstall/lib/models/__init__.py b/archinstall/lib/models/__init__.py
new file mode 100644
index 00000000..c7920cdf
--- /dev/null
+++ b/archinstall/lib/models/__init__.py
@@ -0,0 +1,129 @@
+from typing import Optional, List
+from pydantic import BaseModel, validator
+
+class VersionDef(BaseModel):
+ version_string: str
+
+ @classmethod
+ def parse_version(self) -> List[str]:
+ if '.' in self.version_string:
+ versions = self.version_string.split('.')
+ else:
+ versions = [self.version_string]
+
+ return versions
+
+ @classmethod
+ def major(self) -> str:
+ return self.parse_version()[0]
+
+ @classmethod
+ def minor(self) -> str:
+ versions = self.parse_version()
+ if len(versions) >= 2:
+ return versions[1]
+
+ @classmethod
+ def patch(self) -> str:
+ versions = self.parse_version()
+ if '-' in versions[-1]:
+ _, patch_version = versions[-1].split('-', 1)
+ return patch_version
+
+ def __eq__(self, other :'VersionDef') -> bool:
+ if other.major == self.major and \
+ other.minor == self.minor and \
+ other.patch == self.patch:
+
+ return True
+ return False
+
+ def __lt__(self, other :'VersionDef') -> bool:
+ if self.major > other.major:
+ return False
+ elif self.minor and other.minor and self.minor > other.minor:
+ return False
+ elif self.patch and other.patch and self.patch > other.patch:
+ return False
+
+ def __str__(self) -> str:
+ return self.version_string
+
+
+class PackageSearchResult(BaseModel):
+ pkgname: str
+ pkgbase: str
+ repo: str
+ arch: str
+ pkgver: str
+ pkgrel: str
+ epoch: int
+ pkgdesc: str
+ url: str
+ filename: str
+ compressed_size: int
+ installed_size: int
+ build_date: str
+ last_update: str
+ flag_date: Optional[str]
+ maintainers: List[str]
+ packager: str
+ groups: List[str]
+ licenses: List[str]
+ conflicts: List[str]
+ provides: List[str]
+ replaces: List[str]
+ depends: List[str]
+ optdepends: List[str]
+ makedepends: List[str]
+ checkdepends: List[str]
+
+ @property
+ def pkg_version(self) -> str:
+ return self.pkgver
+
+ def __eq__(self, other :'VersionDef') -> bool:
+ return self.pkg_version == other.pkg_version
+
+ def __lt__(self, other :'VersionDef') -> bool:
+ return self.pkg_version < other.pkg_version
+
+
+class PackageSearch(BaseModel):
+ version: int
+ limit: int
+ valid: bool
+ results: List[PackageSearchResult]
+
+
+class LocalPackage(BaseModel):
+ name: str
+ version: str
+ description:str
+ architecture: str
+ url: str
+ licenses: str
+ groups: str
+ depends_on: str
+ optional_deps: str
+ required_by: str
+ optional_for: str
+ conflicts_with: str
+ replaces: str
+ installed_size: str
+ packager: str
+ build_date: str
+ install_date: str
+ install_reason: str
+ install_script: str
+ validated_by: str
+
+ @property
+ def pkg_version(self) -> str:
+ return self.version
+
+ def __eq__(self, other :'VersionDef') -> bool:
+ return self.pkg_version == other.pkg_version
+
+ def __lt__(self, other :'VersionDef') -> bool:
+ return self.pkg_version < other.pkg_version \ No newline at end of file