@@ -185,6 +185,10 @@ def __init__(self, path: Path = Path('/var/log/archinstall')) -> None:
185185 def path (self ) -> Path :
186186 return self ._path / 'install.log'
187187
188+ @path .setter
189+ def path (self , value : Path ) -> None :
190+ self ._path = value
191+
188192 @property
189193 def directory (self ) -> Path :
190194 return self ._path
@@ -212,6 +216,17 @@ def log(self, level: int, content: str) -> None:
212216 level_name = logging .getLevelName (level )
213217 f .write (f'[{ ts } ] - { level_name } - { content } \n ' )
214218
219+ def get_content (self , max_bytes : int | None = None ) -> bytes :
220+ content = self .path .read_bytes ()
221+
222+ if max_bytes is not None :
223+ size = self .path .stat ().st_size
224+
225+ if size > max_bytes :
226+ content = content [- max_bytes :]
227+
228+ return content
229+
215230
216231logger = Logger ()
217232
@@ -295,6 +310,11 @@ def _stylize_output(
295310 return f'\033 [{ ansi } m{ text } \033 [0m'
296311
297312
313+ def _timestamp () -> str :
314+ now = datetime .now (tz = UTC )
315+ return now .strftime ('%Y-%m-%d %H:%M:%S' )
316+
317+
298318def info (
299319 * msgs : str ,
300320 level : int = logging .INFO ,
@@ -306,11 +326,6 @@ def info(
306326 log (* msgs , level = level , fg = fg , bg = bg , reset = reset , font = font )
307327
308328
309- def _timestamp () -> str :
310- now = datetime .now (tz = UTC )
311- return now .strftime ('%Y-%m-%d %H:%M:%S' )
312-
313-
314329def debug (
315330 * msgs : str ,
316331 level : int = logging .DEBUG ,
@@ -368,48 +383,31 @@ def log(
368383
369384
370385def share_install_log (
371- paste_url : str = 'https://paste.rs' ,
372- max_size : int = 10 * 1024 * 1024 ,
373- confirm : Callable [[str ], bool ] = lambda _ : True ,
374- ) -> int :
386+ paste_url : str ,
387+ max_bytes : int | None = None ,
388+ ) -> str | None :
375389 log_path = logger .path
376390
377391 if not log_path .exists ():
378392 info (f'Log file not found: { log_path } ' )
379- return 1
393+ return None
380394
381- size = log_path .stat ().st_size
382- if size == 0 :
383- info (f'Log file is empty: { log_path } ' )
384- return 1
385-
386- if size > max_size :
387- info (f'Log file exceeds { max_size } bytes, uploading last { max_size } bytes' )
388- content = log_path .read_bytes ()[- max_size :]
389- else :
390- content = log_path .read_bytes ()
395+ content = logger .get_content (max_bytes = max_bytes )
391396
392- header = f'About to upload { log_path } ({ len (content )} bytes) to { paste_url } \n \n '
393- header += 'The log may contain hostname, mirror URLs, package list and partition layout.\n '
394- header += 'The uploaded paste is public.\n \n '
395- header += 'Continue?'
396-
397- if not confirm (header ):
398- info ('Cancelled.' )
399- return 1
397+ if len (content ) == 0 :
398+ info (f'Log file is empty: { log_path } ' )
399+ return None
400400
401401 try :
402402 req = urllib .request .Request (paste_url , data = content )
403403 with urllib .request .urlopen (req ) as response :
404404 url = response .read ().decode ().strip ()
405405 except urllib .error .URLError as e :
406406 info (f'Upload failed: { e } ' )
407- return 1
407+ return None
408408
409409 if not url .startswith ('http' ):
410410 info (f'Unexpected response from { paste_url } : { url [:200 ]!r} ' )
411- return 1
411+ return None
412412
413- # raw print so the URL is pipe-friendly (no ANSI colors, no log prefix)
414- print (url )
415- return 0
413+ return url
0 commit comments