4
4
from enum import Enum
5
5
from typing import List , Optional
6
6
7
+ from strictdoc .core .environment import SDocRuntimeEnvironment
7
8
from strictdoc .core .project_config import ProjectConfig
8
9
9
10
EXPORT_FORMATS = ["html" , "html-standalone" , "rst" , "excel" , "reqif-sdoc" ]
@@ -281,8 +282,16 @@ def __init__(self, input_file, output_file):
281
282
282
283
283
284
class ServerCommandConfig :
284
- def __init__ (self , * , input_path : str , output_path : str , reload : bool ):
285
+ def __init__ (
286
+ self ,
287
+ * ,
288
+ environment : SDocRuntimeEnvironment ,
289
+ input_path : str ,
290
+ output_path : str ,
291
+ reload : bool ,
292
+ ):
285
293
assert os .path .exists (input_path )
294
+ self .environment : SDocRuntimeEnvironment = environment
286
295
abs_input_path = os .path .abspath (input_path )
287
296
self .input_path : str = abs_input_path
288
297
self .output_path : str = output_path
@@ -298,7 +307,7 @@ class ExportMode(Enum):
298
307
class ExportCommandConfig : # pylint: disable=too-many-instance-attributes
299
308
def __init__ ( # pylint: disable=too-many-arguments
300
309
self ,
301
- strictdoc_root_path ,
310
+ environment : SDocRuntimeEnvironment ,
302
311
input_paths ,
303
312
output_dir : str ,
304
313
project_title : Optional [str ],
@@ -309,7 +318,7 @@ def __init__( # pylint: disable=too-many-arguments
309
318
experimental_enable_file_traceability ,
310
319
):
311
320
assert isinstance (input_paths , list ), f"{ input_paths } "
312
- self .strictdoc_root_path = strictdoc_root_path
321
+ self .environment : SDocRuntimeEnvironment = environment
313
322
self .input_paths : List [str ] = input_paths
314
323
self .output_dir : str = output_dir
315
324
self .project_title : Optional [str ] = project_title
@@ -333,27 +342,15 @@ def get_export_mode(self):
333
342
return ExportMode .STANDALONE
334
343
raise NotImplementedError
335
344
345
+ @property
346
+ def strictdoc_root_path (self ):
347
+ return self .environment .path_to_strictdoc
348
+
336
349
def get_static_files_path (self ):
337
- if getattr (sys , "frozen" , False ):
338
- # If the application is run as a bundle, the PyInstaller bootloader
339
- # extends the sys module by a flag frozen=True and sets the app
340
- # path into variable _MEIPASS'.
341
- bundle_dir = sys ._MEIPASS # pylint: disable=protected-access
342
- return os .path .join (bundle_dir , "_static" )
343
- return os .path .join (
344
- self .strictdoc_root_path , "strictdoc/export/html/_static"
345
- )
350
+ return self .environment .get_static_files_path ()
346
351
347
352
def get_extra_static_files_path (self ):
348
- if getattr (sys , "frozen" , False ):
349
- # If the application is run as a bundle, the PyInstaller bootloader
350
- # extends the sys module by a flag frozen=True and sets the app
351
- # path into variable _MEIPASS'.
352
- bundle_dir = sys ._MEIPASS # pylint: disable=protected-access
353
- return os .path .join (bundle_dir , "_static_extra" )
354
- return os .path .join (
355
- self .strictdoc_root_path , "strictdoc/export/html/_static_extra"
356
- )
353
+ return self .environment .get_extra_static_files_path ()
357
354
358
355
def integrate_project_config (self , project_config : ProjectConfig ):
359
356
if self .project_title is None :
@@ -410,7 +407,10 @@ def get_passthrough_config(self) -> PassthroughCommandConfig:
410
407
self .args .input_file , self .args .output_file
411
408
)
412
409
413
- def get_export_config (self , strictdoc_root_path ) -> ExportCommandConfig :
410
+ def get_export_config (
411
+ self , environment : SDocRuntimeEnvironment
412
+ ) -> ExportCommandConfig :
413
+ assert isinstance (environment , SDocRuntimeEnvironment )
414
414
project_title : Optional [str ] = self .args .project_title
415
415
416
416
output_dir = self .args .output_dir if self .args .output_dir else "output"
@@ -419,7 +419,7 @@ def get_export_config(self, strictdoc_root_path) -> ExportCommandConfig:
419
419
output_dir = os .path .join (cwd , output_dir )
420
420
421
421
return ExportCommandConfig (
422
- strictdoc_root_path ,
422
+ environment ,
423
423
self .args .input_paths ,
424
424
output_dir ,
425
425
project_title ,
@@ -440,8 +440,12 @@ def get_import_config_excel(self, _) -> ImportExcelCommandConfig:
440
440
self .args .input_path , self .args .output_path , self .args .parser
441
441
)
442
442
443
- def get_server_config (self ) -> ServerCommandConfig :
443
+ def get_server_config (
444
+ self , environment : SDocRuntimeEnvironment
445
+ ) -> ServerCommandConfig :
446
+ assert isinstance (environment , SDocRuntimeEnvironment ), environment
444
447
return ServerCommandConfig (
448
+ environment = environment ,
445
449
input_path = self .args .input_path ,
446
450
output_path = self .args .output_path ,
447
451
reload = self .args .reload ,
0 commit comments