11
22__author__ = "desultory"
3- __version__ = "0.9.0 "
3+ __version__ = "0.9.1 "
44
55from tomllib import load
6+ from typing import Union
67from pathlib import Path
7- from subprocess import run
8+ from subprocess import run , CompletedProcess
89
910from ugrd .zen_custom import loggify , pretty_print
1011from ugrd .initramfs_dict import InitramfsConfigDict
@@ -25,7 +26,7 @@ def __init__(self, config='/etc/ugrd/config.toml', *args, **kwargs):
2526 self .config_dict .verify_mask ()
2627 self .config_dict .import_args (kwargs )
2728
28- def load_config (self ):
29+ def load_config (self ) -> None :
2930 """
3031 Loads the config from the specified toml file.
3132 Populates self.config_dict with the config.
@@ -49,7 +50,7 @@ def load_config(self):
4950 else :
5051 raise KeyError ("Required parameter '%s' not found in config" % parameter )
5152
52- def clean_build_dir (self ):
53+ def clean_build_dir (self ) -> None :
5354 """
5455 Cleans the build directory
5556 """
@@ -66,7 +67,7 @@ def clean_build_dir(self):
6667 else :
6768 self .logger .info ("Build dir is not present, not cleaning: %s" % self .build_dir )
6869
69- def build_structure (self ):
70+ def build_structure (self ) -> None :
7071 """
7172 builds the initramfs structure.
7273 Cleans the build dir first if clean is set
@@ -78,7 +79,7 @@ def build_structure(self):
7879 self ._run_hook ('build_pre' , return_output = False )
7980 self ._run_hook ('build_tasks' , return_output = False )
8081
81- def _run_func (self , function , external = False , return_output = True ):
82+ def _run_func (self , function : str , external = False , return_output = True ) -> list [ str ] :
8283 """
8384 Runs a function, returning the output in a list
8485 """
@@ -102,9 +103,10 @@ def _run_func(self, function, external=False, return_output=True):
102103 self .logger .debug ("[%s] Function returned no output" % function .__name__ )
103104 return []
104105
105- def _run_funcs (self , functions , external = False , return_output = True ):
106+ def _run_funcs (self , functions : list [ str ] , external = False , return_output = True ) -> list [ str ] :
106107 """
107108 Runs a list of functions
109+ Returns the output if return_output is set
108110 """
109111 self .logger .debug ("Running functions: %s" % functions )
110112 out = []
@@ -116,7 +118,7 @@ def _run_funcs(self, functions, external=False, return_output=True):
116118 self ._run_func (function , external = external , return_output = return_output )
117119 return out
118120
119- def _run_hook (self , hook , return_output = True ):
121+ def _run_hook (self , hook : str , return_output = True ) -> list [ str ] :
120122 """
121123 Runs a hook for imported functions
122124 """
@@ -135,15 +137,15 @@ def _run_hook(self, hook, return_output=True):
135137 self .logger .debug ("[%s] Hook output: %s" % (hook , out ))
136138 return out
137139
138- def _run_init_hook (self , level ) :
140+ def _run_init_hook (self , level : str ) -> list [ str ] :
139141 """
140142 Runs the specified init hook, returning the output
141143 """
142144 out = ['\n \n # Begin %s' % level ]
143145 out += self ._run_hook (level )
144146 return out
145147
146- def generate_init_main (self ):
148+ def generate_init_main (self ) -> list [ str ] :
147149 """
148150 Generates the main init file.
149151 Just runs each hook in self.init_types and returns the output
@@ -158,7 +160,7 @@ def generate_init_main(self):
158160 self .logger .debug ("No output from init hook: %s" % init_type )
159161 return out
160162
161- def generate_init (self ):
163+ def generate_init (self ) -> None :
162164 """
163165 Generates the init file
164166 """
@@ -181,7 +183,7 @@ def generate_init(self):
181183 self ._write ('init' , init , 0o755 )
182184 self .logger .debug ("Final config:\n %s" % pretty_print (self .config_dict ))
183185
184- def generate_structure (self ):
186+ def generate_structure (self ) -> None :
185187 """
186188 Generates the initramfs directory structure
187189 """
@@ -195,7 +197,7 @@ def generate_structure(self):
195197
196198 self ._mkdir (target_dir )
197199
198- def pack_build (self ):
200+ def pack_build (self ) -> None :
199201 """
200202 Packs the initramfs based on self.config_dict['imports']['pack']
201203 """
@@ -204,7 +206,7 @@ def pack_build(self):
204206 else :
205207 self .logger .warning ("No pack functions specified, the final build is present in: %s" % self .build_dir )
206208
207- def _mkdir (self , path ) :
209+ def _mkdir (self , path : Path ) -> None :
208210 """
209211 Creates a directory, chowns it as self.config_dict['_file_owner_uid']
210212 """
@@ -230,7 +232,7 @@ def _mkdir(self, path):
230232
231233 self ._chown (path_dir )
232234
233- def _chown (self , path ) :
235+ def _chown (self , path : Path ) -> None :
234236 """
235237 Chowns a file or directory as self.config_dict['_file_owner_uid']
236238 """
@@ -246,7 +248,7 @@ def _chown(self, path):
246248 else :
247249 self .logger .debug ("[%s] Set file owner: %s" % (path , self .config_dict ['_file_owner_uid' ]))
248250
249- def _write (self , file_name , contents , chmod_mask = 0o644 , in_build_dir = True ):
251+ def _write (self , file_name : Union [ Path , str ], contents : list [ str ] , chmod_mask = 0o644 , in_build_dir = True ) -> None :
250252 """
251253 Writes a file and owns it as self.config_dict['_file_owner_uid']
252254 Sets the passed chmod
@@ -278,7 +280,7 @@ def _write(self, file_name, contents, chmod_mask=0o644, in_build_dir=True):
278280
279281 self ._chown (file_path )
280282
281- def _copy (self , source , dest = None , in_build_dir = True ):
283+ def _copy (self , source : Union [ Path , str ], dest = None , in_build_dir = True ) -> None :
282284 """
283285 Copies a file, chowns it as self.config_dict['_file_owner_uid']
284286 """
@@ -314,7 +316,7 @@ def _copy(self, source, dest=None, in_build_dir=True):
314316
315317 self ._chown (dest_path )
316318
317- def _rotate_old (self , file_name : Path , sequence = 0 ):
319+ def _rotate_old (self , file_name : Path , sequence = 0 ) -> None :
318320 """
319321 Copies a file to file_name.old then file_nane.old.n, where n is the next number in the sequence
320322 """
@@ -359,7 +361,7 @@ def _rotate_old(self, file_name: Path, sequence=0):
359361 self .logger .info ("[%d] Cycling file: %s -> %s" % (sequence , file_name , target_file ))
360362 file_name .rename (target_file )
361363
362- def _get_build_path (self , path ) :
364+ def _get_build_path (self , path : Union [ Path , str ]) -> Path :
363365 """
364366 Returns the build path
365367 """
@@ -371,7 +373,7 @@ def _get_build_path(self, path):
371373 else :
372374 return self .build_dir / path
373375
374- def _symlink (self , source , target , in_build_dir = True ):
376+ def _symlink (self , source : Union [ Path , str ], target : Union [ Path , str ], in_build_dir = True ) -> None :
375377 """
376378 Creates a symlink
377379 """
@@ -393,7 +395,7 @@ def _symlink(self, source, target, in_build_dir=True):
393395 self .logger .debug ("Creating symlink: %s -> %s" % (source , target ))
394396 symlink (source , target )
395397
396- def _run (self , args ) :
398+ def _run (self , args : list [ str ]) -> CompletedProcess :
397399 """
398400 Runs a command, returns the object
399401 """
0 commit comments