1818logger = logging .getLogger ('fab.installer' )
1919
2020import hashlib
21- import debian
21+ from debian import debfile
2222
2323from chroot import Chroot
2424from fablib import common
@@ -86,7 +86,7 @@ def __init__(self, path: str, lines: Iterable[str]):
8686class Installer :
8787 def __init__ (
8888 self , chroot_path : str ,
89- environ : Optional [ Dict [ str , str ]] = None
89+ environ : dict [ str , str ] = None
9090 ):
9191 if environ is None :
9292 environ = {}
@@ -96,7 +96,7 @@ def __init__(
9696 self .chroot = Chroot (chroot_path , environ = env )
9797
9898 @staticmethod
99- def _get_packages_priority (packages : List [str ]) -> Tuple [ List [str ], List [str ]]:
99+ def _get_packages_priority (packages : list [str ]) -> tuple [ list [str ], list [str ]]:
100100 """high priority packages must be installed before regular packages
101101 APT should handle this, but in some circumstances it chokes...
102102 """
@@ -114,9 +114,9 @@ def _get_packages_priority(packages: List[str]) -> Tuple[List[str], List[str]]:
114114 return high , regular
115115
116116 def _install (
117- self , packages : List [str ],
118- ignore_errors : Optional [ List [ str ]] = None ,
119- extra_apt_args : Optional [ List [ str ]] = None ) -> None :
117+ self , packages : list [str ],
118+ ignore_errors : list [ str ] = None ,
119+ extra_apt_args : list [ str ] = None ) -> None :
120120
121121 if ignore_errors is None :
122122 ignore_errors = []
@@ -139,7 +139,7 @@ def _install(
139139 "#!/bin/sh" ,
140140 "echo" ,
141141 'echo "Warning: Deferring update-initramfs $@"' ,
142- 'echo "update-initramfs $@" >> /%s' % defer_log ,
142+ f 'echo "update-initramfs $@" >> /{ defer_log } '
143143 ]
144144
145145 for packages in (high , regular ):
@@ -150,7 +150,7 @@ def _install(
150150 f"apt-get { ' ' .join ((args + packages ))} " )
151151 if apt_return_code != 0 :
152152
153- def get_last_log (path : str ) -> List [str ]:
153+ def get_last_log (path : str ) -> list [str ]:
154154 log = []
155155 with open (path ) as fob :
156156 for line in fob :
@@ -163,7 +163,7 @@ def get_last_log(path: str) -> List[str]:
163163 log .reverse ()
164164 return log
165165
166- def get_errors (log : List [str ], error_str : str ) -> List [str ]:
166+ def get_errors (log : list [str ], error_str : str ) -> list [str ]:
167167 errors = []
168168 for line in reversed (log ):
169169 if line == error_str :
@@ -195,13 +195,11 @@ def get_errors(log: List[str], error_str: str) -> List[str]:
195195 errors = set (errors ) - set (ignore_errors )
196196
197197 if ignored_errors :
198- print (
199- "Warning: ignoring package installation errors (%s)"
200- % " " .join (ignored_errors )
201- )
198+ print (f"Warning: ignoring package installation errors"
199+ f" ({ ' ' .join (ignored_errors )} )" )
202200
203201 if errors :
204- for error in error :
202+ for error in errors :
205203 common .error (error )
206204 raise Error ('package installation errors' )
207205
@@ -225,15 +223,15 @@ def get_errors(log: List[str], error_str: str) -> List[str]:
225223 os .remove (defer_log )
226224
227225 def install (
228- self , packages : List [str ],
229- ignore_errors : Optional [ List [ str ]] = None ) -> None :
226+ self , packages : list [str ],
227+ ignore_errors : list [ str ] = None ) -> None :
230228 raise NotImplementedError ()
231229
232230
233231class PoolInstaller (Installer ):
234232 def __init__ (
235233 self , chroot_path : str , pool_path : str ,
236- arch : str , environ : Optional [ Dict [ str , str ]] = None ):
234+ arch : str , environ : dict [ str , str ] = None ):
237235 super (PoolInstaller , self ).__init__ (chroot_path , environ )
238236
239237 from pool_lib import Pool
@@ -244,7 +242,7 @@ def __init__(
244242 self .arch = arch
245243
246244 @staticmethod
247- def _get_package_index (packagedir : str ) -> List [str ]:
245+ def _get_package_index (packagedir : str ) -> list [str ]:
248246 def filesize (path : str ) -> str :
249247 return str (os .stat (path ).st_size )
250248
@@ -262,7 +260,7 @@ def sha256sum(path: str) -> str:
262260 # dl_path would best be calculated; but we don't have access to chroot_path here...
263261 dl_path = os .path .join ("var/cache/apt/archives" , package )
264262 if path .endswith (".deb" ):
265- control = debian . debfile .DebFile (path ).debcontrol ()
263+ control = debfile .DebFile (path ).debcontrol ()
266264 for field in list (control .keys ()):
267265 index .append (field + ": " + control [field ])
268266
@@ -275,8 +273,8 @@ def sha256sum(path: str) -> str:
275273 return index
276274
277275 def install (
278- self , packages : List [str ],
279- ignore_errors : Optional [ List [ str ]] = None
276+ self , packages : list [str ],
277+ ignore_errors : list [ str ] = None
280278 ) -> None :
281279 """install packages into chroot via pool"""
282280
@@ -297,7 +295,7 @@ def install(
297295 print ("deb file:/// local debs" , file = cast (TextIO , sources_list ))
298296 sources_list .close ()
299297
300- index_file = "_dists_local_debs_binary-%s_Packages" % self .arch
298+ index_file = f "_dists_local_debs_binary-{ self .arch } _Packages"
301299 index_path = join (self .chroot .path , "var/lib/apt/lists" , index_file )
302300 index = self ._get_package_index (packagedir )
303301 with open (index_path , "w" ) as fob :
@@ -311,15 +309,15 @@ def install(
311309class LiveInstaller (Installer ):
312310 def __init__ (
313311 self , chroot_path : str ,
314- apt_proxy : Optional [ str ] = None ,
315- environ : Optional [ Dict [ str , str ]] = None ):
312+ apt_proxy : str = None ,
313+ environ : dict [ str , str ] = None ):
316314 super (LiveInstaller , self ).__init__ (chroot_path , environ )
317315
318316 self .apt_proxy = apt_proxy
319317
320318 def install (
321- self , packages : List [str ],
322- ignore_errors : Optional [ List [ str ]] = None ) -> None :
319+ self , packages : list [str ],
320+ ignore_errors : list [ str ] = None ) -> None :
323321 """install packages into chroot via live apt"""
324322 if ignore_errors is None :
325323 ignore_errors = []
0 commit comments