@@ -363,26 +363,6 @@ def linkStaticAsset(fileNode: FileNode, shouldCopy: bool) -> None:
363
363
else :
364
364
os .symlink (fileNode .absoluteFilePath , fileNode .fileName )
365
365
366
- @staticmethod
367
- def resetOutputDir (outputDir : str , shouldDelete : bool ) -> None :
368
- if os .path .isfile (outputDir ):
369
- raise AltezaException (
370
- f"A file named { outputDir } already exists. Please move it or delete it. "
371
- "Note that if this had been a directory, we would have erased it."
372
- )
373
- if os .path .isdir (outputDir ):
374
- if not shouldDelete :
375
- raise AltezaException (
376
- f"Specified output directory { outputDir } already exists.\n "
377
- "Please use --clear_output_dir to delete it prior to site generation."
378
- )
379
- print (
380
- f"Deleting directory { Fore .dark_red_2 } %s{ Style .reset } and all of its content...\n "
381
- % outputDir
382
- )
383
- shutil .rmtree (outputDir )
384
- os .mkdir (outputDir )
385
-
386
366
@staticmethod
387
367
def generate (args : Args , content : Content ) -> None :
388
368
def walk (curDir : DirNode ) -> None :
@@ -412,30 +392,61 @@ def enterDir(newDir: str) -> Generator[None, None, None]:
412
392
os .chdir (oldDir )
413
393
414
394
415
- def run ( args : Args ) -> None :
416
- startTimeNs = time . time_ns ()
417
- contentDir = args . content
418
- if not os .path .isdir (contentDir ):
419
- raise AltezaException (
420
- f"The provided path '{ contentDir } ' does not exist or is not a directory."
421
- )
395
+ class Engine :
396
+ @ staticmethod
397
+ def checkContentDir ( contentDir : str ) -> None :
398
+ if not os .path .isdir (contentDir ):
399
+ raise AltezaException (
400
+ f"The provided path '{ contentDir } ' does not exist or is not a directory."
401
+ )
422
402
423
- Generate .resetOutputDir (args .output , args .clear_output_dir )
403
+ @staticmethod
404
+ def resetOutputDir (outputDir : str , shouldDelete : bool ) -> None :
405
+ if os .path .isfile (outputDir ):
406
+ raise AltezaException (
407
+ f"A file named { outputDir } already exists. Please move it or delete it. "
408
+ "Note that if this had been a directory, we would have erased it."
409
+ )
410
+ if os .path .isdir (outputDir ):
411
+ if not shouldDelete :
412
+ raise AltezaException (
413
+ f"Specified output directory { outputDir } already exists.\n "
414
+ "Please use --clear_output_dir to delete it prior to site generation."
415
+ )
416
+ print (
417
+ f"Deleting directory { Fore .dark_red_2 } %s{ Style .reset } and all of its content...\n "
418
+ % outputDir
419
+ )
420
+ shutil .rmtree (outputDir )
421
+ os .mkdir (outputDir )
422
+
423
+ @staticmethod
424
+ def process (args : Args ) -> Content :
425
+ with enterDir (args .content ):
426
+ print ("Analyzing content directory..." )
427
+ fs = Fs ()
428
+ print (fs .nameRegistry )
429
+ content = Content (args , fs )
430
+ print ("Processing...\n " )
431
+ content .process ()
432
+ print ("\n Successfully completed processing.\n " )
424
433
425
- with enterDir (args .content ):
426
- fs = Fs ()
427
- print (fs .nameRegistry )
428
- content = Content (args , fs )
429
- print ("Processing...\n " )
430
- content .process ()
431
- print ("\n Successfully completed processing.\n " )
434
+ print ("File Tree:" )
435
+ print (fs .rootDir .displayDir ())
436
+
437
+ return content
438
+
439
+ @staticmethod
440
+ def run (args : Args ) -> None :
441
+ startTimeNs = time .time_ns ()
432
442
433
- print ( "File Tree:" )
434
- print ( fs . rootDir . displayDir () )
443
+ Engine . checkContentDir ( args . content )
444
+ Engine . resetOutputDir ( args . output , args . clear_output_dir )
435
445
436
- print ("Generating..." )
437
- Generate .generate (args , content )
446
+ content = Engine .process (args )
447
+ print ("Generating..." )
448
+ Generate .generate (args , content )
438
449
439
- elapsedMilliseconds = (time .time_ns () - startTimeNs ) / 10 ** 6
440
- # pylint: disable=consider-using-f-string
441
- print ("\n Time elapsed: %.2f ms" % elapsedMilliseconds )
450
+ elapsedMilliseconds = (time .time_ns () - startTimeNs ) / 10 ** 6
451
+ # pylint: disable=consider-using-f-string
452
+ print ("\n Time elapsed: %.2f ms" % elapsedMilliseconds )
0 commit comments