[Bug 270] Copy icons to UI filesystem location when descriptor is copied. Also delete...
authorsinhan <nandan.sinha@riftio.com>
Tue, 16 May 2017 19:41:09 +0000 (19:41 +0000)
committersinhan <nandan.sinha@riftio.com>
Tue, 16 May 2017 19:42:08 +0000 (19:42 +0000)
Signed-off-by: sinhan <nandan.sinha@riftio.com>
rwlaunchpad/plugins/rwpkgmgr/rift/tasklets/rwpkgmgr/downloader/copy.py
rwlaunchpad/plugins/rwpkgmgr/rift/tasklets/rwpkgmgr/proxy/filesystem.py

index c296c91..c64a3f5 100644 (file)
@@ -33,6 +33,8 @@ from gi.repository import (
     RwPkgMgmtYang
 )
 
+import rift.package.icon as icon 
+
 class PackageCopyError(Exception): 
     pass
 
@@ -136,6 +138,19 @@ class PackageFileCopier:
                 format(src=src_path, dest=self.dest_copy_path))
 
         shutil.copytree(src_path, self.dest_copy_path)
+        # If there are icon files, also need to copy them in UI location
+        if os.path.exists(os.path.join(src_path, "icons")): 
+            src_icon_path = os.path.join(
+                    icon.PackageIconExtractor.DEFAULT_INSTALL_DIR, 
+                    self.package_type, 
+                    self.src_package_id)
+            dest_icon_path = os.path.join(
+                    os.path.dirname(src_icon_path), 
+                    self.dest_package_id)
+            
+            self.log.debug("Copying UI icon location from {} to {}".format(src_icon_path, 
+                dest_icon_path))
+            shutil.copytree(src_icon_path, dest_icon_path)
 
     def _create_descriptor_file(self):
         """ Update descriptor file for the newly copied descriptor catalog.
index 7111092..6b4aba1 100644 (file)
@@ -123,21 +123,32 @@ class FileSystemProxy(AbstractPackageManagerProxy):
         store = self._get_store(package_type)
         package = store.get_package(package_id)
 
-        # for files other than README, create the package path from the asset type
-        package_path = package_file_type + "/" + package_path \
+        # for files other than README, create the relative package path from the asset type
+        package_path_rel = package_file_type + "/" + package_path \
             if package_file_type != "readme" else package_path
 
         # package_path has to be relative, so strip off the starting slash if
         # provided incorrectly.
-        if package_path[0] == "/":
-            package_path = package_path[1:]
+        if package_path_rel[0] == "/":
+            package_path_rel = package_path_rel[1:]
 
         # Construct abs path of the destination obj
         path = store._get_package_dir(package_id)
-        dest_file = os.path.join(path, package.prefix, package_path)
+        dest_file = os.path.join(path, package.prefix, package_path_rel)
 
         try:
-            package.delete_file(dest_file, package_path)
+            package.delete_file(dest_file, package_path_rel)
+
+            if package_file_type == 'icons': 
+                ui_icon_path = os.path.join(
+                        icon.PackageIconExtractor.DEFAULT_INSTALL_DIR, 
+                        package_type, 
+                        package_id)
+                if os.path.exists(ui_icon_path): 
+                    icon_file = os.path.join(ui_icon_path, package_path)
+                    self.log.debug("Deleting UI icon file path {}".format(icon_file))
+                    os.remove(icon_file)
+
         except rift.package.package.PackageAppendError as e:
             self.log.exception(e)
             return False