index : archinstall32 | |
Archlinux32 installer | gitolite user |
summaryrefslogtreecommitdiff |
author | Anton Hvornum <anton@hvornum.se> | 2022-02-02 15:01:17 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-02 15:01:17 +0100 |
commit | 389feef035cfbb1bd2c4f8be070fa085c088f151 (patch) | |
tree | e305eb7866224117487eaae73ecab53c2ebb7fb4 /archinstall | |
parent | 37d6da7e4eb8897dfb80797f28db85ccdd09d376 (diff) |
-rw-r--r-- | archinstall/__init__.py | 2 | ||||
-rw-r--r-- | archinstall/lib/models/__init__.py | 129 | ||||
-rw-r--r-- | archinstall/lib/models/dataclasses.py | 136 | ||||
-rw-r--r-- | archinstall/lib/models/pydantic.py | 134 | ||||
-rw-r--r-- | archinstall/lib/packages/packages.py | 2 |
diff --git a/archinstall/__init__.py b/archinstall/__init__.py index b5b4dd79..f31d8b3d 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -14,7 +14,7 @@ from .lib.luks import * from .lib.mirrors import * from .lib.networking import * from .lib.output import * -from .lib.models import ( +from .lib.models.dataclasses import ( VersionDef, PackageSearchResult, PackageSearch, diff --git a/archinstall/lib/models/__init__.py b/archinstall/lib/models/__init__.py index c7920cdf..e69de29b 100644 --- a/archinstall/lib/models/__init__.py +++ b/archinstall/lib/models/__init__.py @@ -1,129 +0,0 @@ -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 diff --git a/archinstall/lib/models/dataclasses.py b/archinstall/lib/models/dataclasses.py new file mode 100644 index 00000000..99221fe3 --- /dev/null +++ b/archinstall/lib/models/dataclasses.py @@ -0,0 +1,136 @@ +from dataclasses import dataclass +from typing import Optional, List + +@dataclass +class VersionDef: + 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 + +@dataclass +class PackageSearchResult: + 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 + +@dataclass +class PackageSearch: + version: int + limit: int + valid: bool + num_pages: int + page: int + results: List[PackageSearchResult] + + def __post_init__(self): + self.results = [PackageSearchResult(**x) for x in self.results] + +@dataclass +class LocalPackage: + 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 + provides: 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 diff --git a/archinstall/lib/models/pydantic.py b/archinstall/lib/models/pydantic.py new file mode 100644 index 00000000..799e92af --- /dev/null +++ b/archinstall/lib/models/pydantic.py @@ -0,0 +1,134 @@ +from typing import Optional, List +from pydantic import BaseModel + +""" +This python file is not in use. +Pydantic is not a builtin, and we use the dataclasses.py instead! +""" + +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 diff --git a/archinstall/lib/packages/packages.py b/archinstall/lib/packages/packages.py index 7dc74b32..5b94aa59 100644 --- a/archinstall/lib/packages/packages.py +++ b/archinstall/lib/packages/packages.py @@ -3,7 +3,7 @@ import urllib.request import json from typing import Dict, Any from ..general import SysCommand -from ..models import PackageSearch, PackageSearchResult, LocalPackage +from ..models.dataclasses import PackageSearch, PackageSearchResult, LocalPackage from ..exceptions import PackageError, SysCallError, RequirementError BASE_URL_PKG_SEARCH = 'https://archlinux.org/packages/search/json/?name={package}' |