1414
1515
1616class XmlPowerToolsEngine (object ):
17- def __init__ (self ):
17+ def __init__ (self , reload_binary : bool = False ):
1818 self .extracted_binaries_path = self ._unzip_binary ()
19+ self ._reload_binary = reload_binary
1920
2021 def _unzip_binary (self ):
2122 """
@@ -27,39 +28,53 @@ def _unzip_binary(self):
2728 binaries_path = os .path .join (base_path , 'dist' )
2829 logger .debug (f"Python redlining binaries path: { binaries_path } " )
2930
31+ os_name = platform .system ().lower ()
32+ arch = 'x64' # Assuming x64 architecture
33+
34+ if os_name == 'linux' :
35+ zip_name = f"linux-{ arch } -{ __version__ } .tar.gz"
36+ binary_name = 'linux-x64/redlines'
37+
38+ elif os_name == "windows" :
39+ zip_name = f"win-{ arch } -{ __version__ } .zip"
40+ binary_name = 'win-x64/redlines.exe'
41+
42+ elif os_name == "darwin" :
43+ zip_name = f"osx-{ arch } -{ __version__ } .tar.gz"
44+ binary_name = 'osx-x64/redlines'
45+ else :
46+ raise EnvironmentError ("Unsupported OS" )
47+
3048 target_path = os .path .join (base_path , 'bin' )
3149 logger .debug (f"Target path: { target_path } " )
3250
51+ # If target folder doesn't exist... created
3352 if not os .path .exists (target_path ):
3453 os .makedirs (target_path )
54+ else :
55+ # If we don't want to reload the binary and it already exists... just return path
56+ if not self ._reload_binary :
57+ return os .path .join (target_path , binary_name )
3558
36- os_name = platform .system ().lower ()
37- arch = 'x64' # Assuming x64 architecture
38-
59+ # Otherwise, go ahead and unzip... and this may vary depending on the architecture & env
3960 if os_name == 'linux' :
40- zip_name = f"linux-{ arch } -{ __version__ } .tar.gz"
41- binary_name = 'linux-x64/redlines'
4261 zip_path = os .path .join (binaries_path , zip_name )
4362 if os .path .exists (zip_path ):
4463 with tarfile .open (zip_path , 'r:gz' ) as tar_ref :
4564 tar_ref .extractall (target_path )
4665
4766 elif os_name == 'windows' :
48- zip_name = f"win-{ arch } -{ __version__ } .zip"
49- binary_name = 'win-x64/redlines.exe'
5067 zip_path = os .path .join (binaries_path , zip_name )
5168 if os .path .exists (zip_path ):
5269 with zipfile .ZipFile (zip_path , 'r' ) as zip_ref :
5370 zip_ref .extractall (target_path )
5471
5572 elif os_name == 'darwin' :
56- zip_name = f"osx-{ arch } -{ __version__ } .tar.gz"
57- binary_name = 'osx-x64/redlines'
5873 zip_path = os .path .join (binaries_path , zip_name )
5974 if os .path .exists (zip_path ):
6075 with tarfile .open (zip_path , 'r:gz' ) as tar_ref :
6176 tar_ref .extractall (target_path )
62-
77+ # This is redundant given above test... but I'm leaving it here.
6378 else :
6479 raise EnvironmentError ("Unsupported OS" )
6580
0 commit comments