Skip to content

Commit 44efdec

Browse files
committedJun 18, 2024
Making APT distro metadata fields optional
1 parent 1bf70d9 commit 44efdec

File tree

1 file changed

+60
-35
lines changed

1 file changed

+60
-35
lines changed
 

‎src/repopulator/apt.py

+60-35
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,33 @@ class AptDistribution(metaclass=NoPublicConstructor):
157157
"""A distribution in AptRepo
158158
159159
Attributes:
160-
origin (str): Origin of the distribution
161-
label (str): Label of the distribution
162-
suite (str): Suite of the distribution
163-
version (str): Version of the distribution
164-
description (str): Description of the distribution
160+
origin (Optional[str]): Origin of the distribution
161+
label (Optional[str]): Label of the distribution
162+
suite (Optional[str]): Suite of the distribution
163+
codename (Optional[str]): Codename of the distribution
164+
version (Optional[str]): Version of the distribution
165+
description (Optional[str]): Description of the distribution
165166
"""
166167

167168
@classmethod
168169
def _new(cls,
169170
path: PurePosixPath,
170-
origin: str,
171-
label: str,
172-
suite: str,
173-
version: str,
174-
description: str) -> AptDistribution:
175-
return cls._create(path, origin, label, suite, version, description)
171+
origin: Optional[str],
172+
label: Optional[str],
173+
suite: Optional[str],
174+
codename: Optional[str],
175+
version: Optional[str],
176+
description: Optional[str]) -> AptDistribution:
177+
return cls._create(path, origin, label, suite, codename, version, description)
176178

177179
def __init__(self,
178180
path: PurePosixPath,
179-
origin: str,
180-
label: str,
181-
suite: str,
182-
version: str,
183-
description: str) -> None:
181+
origin: Optional[str],
182+
label: Optional[str],
183+
suite: Optional[str],
184+
codename: Optional[str],
185+
version: Optional[str],
186+
description: Optional[str]) -> None:
184187
"""Internal, do not use.
185188
Use AptRepo.add_distribution to create instances of this class
186189
"""
@@ -189,6 +192,7 @@ def __init__(self,
189192
self.origin = origin
190193
self.label = label
191194
self.suite = suite
195+
self.codename = codename
192196
self.version = version
193197
self.description = description
194198

@@ -286,14 +290,24 @@ def _export(self, root: Path, signer: PgpSigner, now: Optional[datetime] = None)
286290

287291
Release_path = dist_dir / 'Release' # pylint: disable=invalid-name
288292
with open(Release_path, "wb") as f:
289-
f.write(f'Origin: {self.origin}\n'.encode())
290-
f.write(f'Label: {self.label}\n'.encode())
291-
f.write(f'Suite: {self.suite}\n'.encode())
292-
f.write(f'Codename: {self.__path.name}\n'.encode())
293-
f.write(f'Version: {self.version}\n'.encode())
293+
if self.origin is not None:
294+
f.write(f'Origin: {self.origin}\n'.encode())
295+
if self.label is not None:
296+
f.write(f'Label: {self.label}\n'.encode())
297+
if self.suite is not None:
298+
f.write(f'Suite: {self.suite}\n'.encode())
299+
else:
300+
f.write(f'Suite: {self.__path.name}\n'.encode())
301+
if self.codename is not None:
302+
f.write(f'Codename: {self.codename}\n'.encode())
303+
else:
304+
f.write(f'Codename: {self.__path.name}\n'.encode())
305+
if self.version is not None:
306+
f.write(f'Version: {self.version}\n'.encode())
294307
f.write(f'Architectures: {",".join(archs)}\n'.encode())
295308
f.write(f'Components: {",".join(components)}\n'.encode())
296-
f.write(f'Description: {self.description}\n'.encode())
309+
if self.description is not None:
310+
f.write(f'Description: {self.description}\n'.encode())
297311
f.write(f'Date: {now.strftime("%a, %d %b %Y %I:%M:%S %z")}\n'.encode())
298312

299313
hashes = [
@@ -356,19 +370,22 @@ def __init__(self):
356370
def add_distribution(self,
357371
path: PurePosixPath | str,
358372
*,
359-
origin: str,
360-
label: str,
361-
suite: str,
362-
version: str,
363-
description: str) -> AptDistribution:
373+
origin: Optional[str]=None,
374+
label: Optional[str]=None,
375+
suite: Optional[str]=None,
376+
codename: Optional[str]=None,
377+
version: Optional[str]=None,
378+
description: Optional[str]=None) -> AptDistribution:
364379
"""Adds a new distribution to the repository
365380
366381
Args:
367382
path: distribution "name" inside the repo (e.g. 'jammy' or 'focal'), which is also its path.
368-
The last component of this path is also automatically used as the distribution 'Codename'
369383
origin: 'Origin' field. See https://wiki.debian.org/DebianRepository/Format#Origin
370384
label: 'Label' field. See https://wiki.debian.org/DebianRepository/Format#Label
371-
suite: 'Suite' field. See https://wiki.debian.org/DebianRepository/Format#Suite
385+
suite: 'Suite' field. See https://wiki.debian.org/DebianRepository/Format#Suite If omitted, Suite is
386+
set to the last component of the path
387+
codename: 'Codename' field. See https://wiki.debian.org/DebianRepository/Format#Codename If omitted, Codename is
388+
set to the last component of the path
372389
version: 'Version' field. See https://wiki.debian.org/DebianRepository/Format#Version
373390
description: 'Description' field. A description of the distribution
374391
@@ -379,12 +396,20 @@ def add_distribution(self,
379396
path = path if isinstance(path, PurePosixPath) else PurePosixPath(path)
380397
if path.is_absolute():
381398
raise ValueError('path value must be a relative path')
382-
origin = ensure_one_line_str(origin, 'origin')
383-
label = ensure_one_line_str(label, 'label')
384-
suite = ensure_one_line_str(suite, 'sutie')
385-
version = ensure_one_line_str(version, 'version')
386-
description = ensure_one_line_str(description, 'description')
387-
dist = AptDistribution._new(path, origin=origin, label=label, suite=suite, version=version, description=description)
399+
if origin is not None:
400+
origin = ensure_one_line_str(origin, 'origin')
401+
if label is not None:
402+
label = ensure_one_line_str(label, 'label')
403+
if suite is not None:
404+
suite = ensure_one_line_str(suite, 'suite')
405+
if codename is not None:
406+
codename = ensure_one_line_str(codename, 'codename')
407+
if version is not None:
408+
version = ensure_one_line_str(version, 'version')
409+
if description is not None:
410+
description = ensure_one_line_str(description, 'description')
411+
dist = AptDistribution._new(path, origin=origin, label=label, suite=suite, codename=codename,
412+
version=version, description=description)
388413
if dist in self.__distributions:
389414
raise ValueError('Duplicate distribution')
390415
self.__distributions.add(dist)

0 commit comments

Comments
 (0)
Please sign in to comment.