Addon Manager: Fix ZIP-based update
This commit is contained in:
@@ -374,23 +374,36 @@ class AddonInstaller(QtCore.QObject):
|
||||
# after the branch. If that is the setup that we just extracted, move all files out of
|
||||
# that subdirectory.
|
||||
if self._code_in_branch_subdirectory(destination):
|
||||
actual_path = os.path.join(
|
||||
destination, f"{self.addon_to_install.name}-{self.addon_to_install.branch}"
|
||||
)
|
||||
FreeCAD.Console.PrintLog(
|
||||
f"ZIP installation moving code from {actual_path} to {destination}"
|
||||
)
|
||||
self._move_code_out_of_subdirectory(destination)
|
||||
|
||||
FreeCAD.Console.PrintLog("ZIP installation complete.\n")
|
||||
self._finalize_successful_installation()
|
||||
|
||||
def _code_in_branch_subdirectory(self, destination: str) -> bool:
|
||||
subdirectories = os.listdir(destination)
|
||||
if len(subdirectories) == 1:
|
||||
subdir_name = subdirectories[0]
|
||||
if subdir_name.endswith(os.path.sep):
|
||||
subdir_name = subdir_name[:-1] # Strip trailing slash if present
|
||||
if subdir_name.endswith(self.addon_to_install.branch):
|
||||
return True
|
||||
test_path = os.path.join(destination, self._expected_subdirectory_name())
|
||||
FreeCAD.Console.PrintLog(f"Checking for possible zip sub-path {test_path}...")
|
||||
if os.path.isdir(test_path):
|
||||
FreeCAD.Console.PrintLog(f"path exists.\n")
|
||||
return True
|
||||
FreeCAD.Console.PrintLog(f"path does not exist.\n")
|
||||
return False
|
||||
|
||||
def _expected_subdirectory_name(self) -> str:
|
||||
url = self.addon_to_install.url
|
||||
if url.endswith(".git"):
|
||||
url = url[:-4]
|
||||
_, _, name = url.rpartition("/")
|
||||
branch = self.addon_to_install.branch
|
||||
return f"{name}-{branch}"
|
||||
|
||||
def _move_code_out_of_subdirectory(self, destination):
|
||||
subdirectory = os.listdir(destination)[0]
|
||||
subdirectory = os.path.join(destination, self._expected_subdirectory_name())
|
||||
for extracted_filename in os.listdir(os.path.join(destination, subdirectory)):
|
||||
shutil.move(
|
||||
os.path.join(destination, subdirectory, extracted_filename),
|
||||
|
||||
Reference in New Issue
Block a user