@@ -157,30 +157,33 @@ class AptDistribution(metaclass=NoPublicConstructor):
157
157
"""A distribution in AptRepo
158
158
159
159
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
165
166
"""
166
167
167
168
@classmethod
168
169
def _new (cls ,
169
170
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 )
176
178
177
179
def __init__ (self ,
178
180
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 :
184
187
"""Internal, do not use.
185
188
Use AptRepo.add_distribution to create instances of this class
186
189
"""
@@ -189,6 +192,7 @@ def __init__(self,
189
192
self .origin = origin
190
193
self .label = label
191
194
self .suite = suite
195
+ self .codename = codename
192
196
self .version = version
193
197
self .description = description
194
198
@@ -286,14 +290,24 @@ def _export(self, root: Path, signer: PgpSigner, now: Optional[datetime] = None)
286
290
287
291
Release_path = dist_dir / 'Release' # pylint: disable=invalid-name
288
292
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 ())
294
307
f .write (f'Architectures: { "," .join (archs )} \n ' .encode ())
295
308
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 ())
297
311
f .write (f'Date: { now .strftime ("%a, %d %b %Y %I:%M:%S %z" )} \n ' .encode ())
298
312
299
313
hashes = [
@@ -356,19 +370,22 @@ def __init__(self):
356
370
def add_distribution (self ,
357
371
path : PurePosixPath | str ,
358
372
* ,
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 :
364
379
"""Adds a new distribution to the repository
365
380
366
381
Args:
367
382
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'
369
383
origin: 'Origin' field. See https://wiki.debian.org/DebianRepository/Format#Origin
370
384
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
372
389
version: 'Version' field. See https://wiki.debian.org/DebianRepository/Format#Version
373
390
description: 'Description' field. A description of the distribution
374
391
@@ -379,12 +396,20 @@ def add_distribution(self,
379
396
path = path if isinstance (path , PurePosixPath ) else PurePosixPath (path )
380
397
if path .is_absolute ():
381
398
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 )
388
413
if dist in self .__distributions :
389
414
raise ValueError ('Duplicate distribution' )
390
415
self .__distributions .add (dist )
0 commit comments