Skip to content

Commit 533faa3

Browse files
committed
Update or add "docstrings"
Signed-off-by: Tobias Wolf <wolf@b1-systems.de>
1 parent f9db818 commit 533faa3

File tree

16 files changed

+758
-120
lines changed

16 files changed

+758
-120
lines changed

src/gardenlinux/apt/__init__.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# -*- coding: utf-8 -*-
22

3+
"""
4+
APT module
5+
"""
6+
37
from .debsource import Debsrc, DebsrcFile
48

5-
__all__ = ["Parser"]
9+
__all__ = ["Debsrc", "DebsrcFile"]

src/gardenlinux/apt/debsource.py

Lines changed: 66 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,63 @@
11
# -*- coding: utf-8 -*-
2-
# SPDX-License-Identifier: MIT
32

4-
# Based on code from glvd https://github.com/gardenlinux/glvd/blob/7ca2ff54e01da5e9eae61d1cd565eaf75f3c62ce/src/glvd/data/debsrc.py#L1
5-
6-
from __future__ import annotations
3+
"""
4+
deb sources
5+
"""
76

87
import re
98
from typing import TextIO
109

1110

1211
class Debsrc:
12+
"""
13+
Class to reflect deb sources.
14+
15+
:author: Garden Linux Maintainers
16+
:copyright: Copyright 2024 SAP SE
17+
:package: gardenlinux
18+
:subpackage: apt
19+
:since: 0.7.0
20+
:license: https://www.apache.org/licenses/LICENSE-2.0
21+
Apache License, Version 2.0
22+
"""
23+
1324
def __init__(self, deb_source, deb_version):
14-
self.deb_source = deb_source
15-
self.deb_version = deb_version
25+
"""
26+
Constructor __init__(Debsrc)
27+
28+
:param deb_source: Source name
29+
:param deb_version: Source version
1630
17-
deb_source: str
18-
deb_version: str
31+
:since: 0.7.0
32+
"""
33+
34+
self.deb_source: str = deb_source
35+
self.deb_version: str = deb_version
1936

2037
def __repr__(self) -> str:
38+
"""
39+
python.org: Called by the repr() built-in function to compute the "official" string representation of an object.
40+
41+
:return: (str) String representation
42+
:since: 0.7.0
43+
"""
44+
2145
return f"{self.deb_source} {self.deb_version}"
2246

2347

2448
class DebsrcFile(dict[str, Debsrc]):
49+
"""
50+
Class to represent deb sources loaded and parsed as dict.
51+
52+
:author: Garden Linux Maintainers
53+
:copyright: Copyright 2024 SAP SE
54+
:package: gardenlinux
55+
:subpackage: apt
56+
:since: 0.7.0
57+
:license: https://www.apache.org/licenses/LICENSE-2.0
58+
Apache License, Version 2.0
59+
"""
60+
2561
__re = re.compile(
2662
r"""
2763
^(?:
@@ -43,18 +79,16 @@ class DebsrcFile(dict[str, Debsrc]):
4379
re.VERBOSE,
4480
)
4581

46-
def _read_source(self, source: str, version: str) -> None:
47-
self[source] = Debsrc(
48-
deb_source=source,
49-
deb_version=version,
50-
)
51-
5282
def read(self, f: TextIO) -> None:
53-
current_source = current_version = None
83+
"""
84+
Read and parse the given TextIO data to extract deb sources.
85+
86+
:param f: TextIO data to parse
5487
55-
def finish():
56-
if current_source and current_version:
57-
self._read_source(current_source, current_version)
88+
:since: 0.7.0
89+
"""
90+
91+
current_source = current_version = None
5892

5993
for line in f.readlines():
6094
if match := self.__re.match(line):
@@ -70,4 +104,17 @@ def finish():
70104
else:
71105
raise RuntimeError(f"Unable to read line: {line}")
72106

73-
finish()
107+
if current_source and current_version:
108+
self._set_source(current_source, current_version)
109+
110+
def _set_source(self, source: str, version: str) -> None:
111+
"""
112+
Sets the dict value based on the given source key.
113+
114+
:since: 0.7.0
115+
"""
116+
117+
self[source] = Debsrc(
118+
deb_source=source,
119+
deb_version=version,
120+
)

src/gardenlinux/apt/package_repo_info.py

Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,110 @@
11
# -*- coding: utf-8 -*-
22

3+
"""
4+
APT repositories
5+
"""
6+
37
from apt_repo import APTRepository
48
from typing import Optional
59

610

711
class GardenLinuxRepo(APTRepository):
12+
"""
13+
Class to reflect APT based GardenLinux repositories.
14+
15+
:author: Garden Linux Maintainers
16+
:copyright: Copyright 2024 SAP SE
17+
:package: gardenlinux
18+
:subpackage: apt
19+
:since: 0.7.0
20+
:license: https://www.apache.org/licenses/LICENSE-2.0
21+
Apache License, Version 2.0
22+
"""
23+
824
def __init__(
925
self,
1026
dist: str,
1127
url: Optional[str] = "http://packages.gardenlinux.io/gardenlinux",
1228
components: Optional[list[str]] = ["main"],
13-
) -> None:
29+
):
30+
"""
31+
Constructor __init__(GardenLinuxRepo)
32+
33+
:param dist: Repository dist
34+
:param url: Repository url
35+
:param components: Repository components provided
36+
37+
:since: 0.7.0
38+
"""
39+
1440
self.components = components
1541
self.url = url
1642
self.dist = dist
1743
self.repo = APTRepository(self.url, self.dist, self.components)
1844

1945
def get_package_version_by_name(self, name: str) -> list[tuple[str, str]]:
2046
"""
21-
:param str name: name of package to find
22-
:returns: packages matching the input name
47+
Returns the package version matching the given name.
48+
49+
:param name: name of package to find
50+
51+
:return: (list) Packages matching the input name
52+
:since: 0.7.0
2353
"""
54+
2455
return [
2556
(package.package, package.version)
2657
for package in self.repo.get_packages_by_name(name)
2758
]
2859

29-
def get_packages_versions(self):
60+
def get_packages_versions(self) -> list[tuple[str, str]]:
3061
"""
3162
Returns list of (package, version) tuples
63+
64+
:return: (list) Packages versions
65+
:since: 0.7.0
3266
"""
67+
3368
return [(p.package, p.version) for p in self.repo.packages]
3469

3570

36-
def compare_gardenlinux_repo_version(version_a: str, version_b: str):
71+
def compare_gardenlinux_repo_version(
72+
version_a: str, version_b: str
73+
) -> list[tuple[str, str, str]]:
3774
"""
38-
:param str version_a: Version of first Garden Linux repo
39-
:param str version_b: Version of first Garden Linux repo
75+
Compares differences between repository versions given.
4076
4177
Example: print(compare_gardenlinux_repo_version("1443.2", "1443.1"))
78+
79+
:param version_a: Version of first Garden Linux repo
80+
:param version_b: Version of first Garden Linux repo
81+
82+
:return: (list) Differences between repo a and repo b
83+
:since: 0.7.0
4284
"""
85+
4386
return compare_repo(GardenLinuxRepo(version_a), GardenLinuxRepo(version_b))
4487

4588

4689
def compare_repo(
4790
a: GardenLinuxRepo, b: GardenLinuxRepo, available_in_both: Optional[bool] = False
48-
):
91+
) -> list[tuple[str, str, str]]:
4992
"""
50-
:param a GardenLinuxRepo: first repo to compare
51-
:param b GardenLinuxRepo: second repo to compare
52-
:returns: differences between repo a and repo b
93+
Compares differences between repositories given.
94+
95+
Example:
96+
gl_repo = GardenLinuxRepo("today")
97+
gl_repo_1592 = GardenLinuxRepo("1592.0")
98+
deb_testing = GardenLinuxRepo("testing", "https://deb.debian.org/debian/")
99+
print(compare_repo(gl_repo, gl_repo_1592, available_in_both=True))
100+
print(compare_repo(gl_repo, deb_testing, available_in_both=False))
101+
102+
:param a GardenLinuxRepo: First repo to compare
103+
:param b GardenLinuxRepo: Second repo to compare
104+
:param available_in_both: Compare packages available in both repos only
105+
106+
:return: (list) Differences between repo a and repo b
107+
:since: 0.7.0
53108
"""
54109

55110
packages_a = dict(a.get_packages_versions())
@@ -69,15 +124,3 @@ def compare_repo(
69124
)
70125
or (name not in packages_b or name not in packages_a)
71126
]
72-
73-
74-
# EXAMPLE USAGE.
75-
# print(compare_gardenlinux_repo_version("1443.2", "1443.1"))
76-
77-
# gl_repo = GardenLinuxRepo("today")
78-
# gl_repo_1592 = GardenLinuxRepo("1592.0")
79-
# deb_testing = GardenLinuxRepo("testing", "https://deb.debian.org/debian/")
80-
# print(compare_repo(gl_repo, gl_repo_1592, available_in_both=True))
81-
# print(compare_repo(gl_repo, deb_testing, available_in_both=True))
82-
# # print(gl_repo.get_packages_versions())
83-
# print(gl_repo.get_package_version_by_name("wget"))

src/gardenlinux/features/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# -*- coding: utf-8 -*-
22

3+
"""
4+
Features module
5+
"""
6+
37
from .cname import CName
48
from .parser import Parser
59

0 commit comments

Comments
 (0)