From 6f14c845034db4963357ee28641aba5d49429c8b Mon Sep 17 00:00:00 2001
From: Endi Sukma Dewata <edewata@redhat.com>
Date: Thu, 1 Nov 2012 21:06:21 -0400
Subject: [PATCH] Merged theme files.

Currently the theme files are copied into each subsystem during
deployment creating duplicates. To reduce the problem the files
should be combined into a common folder /pki.

The process will be done over several patches. Initially this patch
will copy the images and CSS files into /pki/images and /pki/css.
Subsequent patches will update references to these files to the new
location. When it's done, the files no longer need to be copied
into each subsystem.

Ticket #328
---
 base/deploy/src/scriptlets/instance_layout.py | 172 ++++++++++++++++++++++++--
 base/setup/pkicreate                          |  33 ++++-
 2 files changed, 196 insertions(+), 9 deletions(-)

diff --git a/base/deploy/src/scriptlets/instance_layout.py b/base/deploy/src/scriptlets/instance_layout.py
index 219f049c81008a8f9a7ef997fef33dae357630f9..b4d1a5068e208dfec5edf56a4d717181f61aa41c 100644
--- a/base/deploy/src/scriptlets/instance_layout.py
+++ b/base/deploy/src/scriptlets/instance_layout.py
@@ -71,12 +71,90 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
             util.directory.create(master['pki_tomcat_tmpdir_path'])
             util.directory.create(master['pki_tomcat_webapps_path'])
             util.directory.create(master['pki_tomcat_webapps_common_path'])
-            util.directory.copy(
-                os.path.join(
-                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
-                    "common-ui"),
+
+            common_images = os.path.join(
                 master['pki_tomcat_webapps_common_path'],
+                "images")
+
+            # Copy /usr/share/pki/common-ui/admin/console/img
+            # to <instance>/webapp/pki/images
+            util.directory.copy(
+                os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    "common-ui",
+                    "admin",
+                    "console",
+                    "img"),
+                common_images,
                 overwrite_flag=True)
+
+            # Copy /usr/share/pki/common-ui/css
+            # to <instance>/webapp/pki/css
+            util.directory.copy(
+                os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    "common-ui",
+                    "css"),
+                os.path.join(
+                    master['pki_tomcat_webapps_common_path'],
+                    "css"),
+                overwrite_flag=True)
+
+            # Copy /usr/share/pki/common-ui/img
+            # to <instance>/webapp/pki/images
+            util.directory.copy(
+                os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    "common-ui",
+                    "img"),
+                common_images,
+                overwrite_flag=True)
+
+            # Copy /usr/share/pki/<subsystem>-ui/webapps/<subsystem>/admin/graphics
+            # to <instance>/webapp/pki/images
+            dir = os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    master['pki_subsystem'].lower() + "-ui",
+                    "webapps",
+                    master['pki_subsystem'].lower(),
+                    "admin",
+                    "graphics")
+            if (util.directory.exists(dir)):
+                util.directory.copy(
+                    dir,
+                    common_images,
+                    overwrite_flag=True)
+
+            # Copy /usr/share/pki/<subsystem>-ui/webapps/<subsystem>/agent/graphics
+            # to <instance>/webapp/pki/images
+            dir = os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    master['pki_subsystem'].lower() + "-ui",
+                    "webapps",
+                    master['pki_subsystem'].lower(),
+                    "agent",
+                    "graphics")
+            if (util.directory.exists(dir)):
+                util.directory.copy(
+                    dir,
+                    common_images,
+                    overwrite_flag=True)
+
+            # Copy /usr/share/pki/<subsystem>-ui/webapps/<subsystem>/ee/graphics
+            # to <instance>/webapp/pki/images
+            dir = os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    master['pki_subsystem'].lower() + "-ui",
+                    "webapps",
+                    master['pki_subsystem'].lower(),
+                    "ee",
+                    "graphics")
+            if (util.directory.exists(dir)):
+                util.directory.copy(
+                    dir,
+                    common_images,
+                    overwrite_flag=True)
+
             util.directory.create(master['pki_tomcat_webapps_root_path'])
             util.directory.copy(
                 os.path.join(
@@ -180,12 +258,90 @@ class PkiScriptlet(pkiscriptlet.AbstractBasePkiScriptlet):
             util.directory.modify(master['pki_instance_lib'])
             util.directory.modify(master['pki_instance_lib_log4j_properties'])
             util.directory.modify(master['pki_tomcat_webapps_path'])
-            util.directory.copy(
-                os.path.join(
-                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
-                    "common-ui"),
+
+            common_images = os.path.join(
                 master['pki_tomcat_webapps_common_path'],
+                "images")
+
+            # Copy /usr/share/pki/common-ui/admin/console/img
+            # to <instance>/webapp/pki/images
+            util.directory.copy(
+                os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    "common-ui",
+                    "admin",
+                    "console",
+                    "img"),
+                common_images,
                 overwrite_flag=True)
+
+            # Copy /usr/share/pki/common-ui/css
+            # to <instance>/webapp/pki/css
+            util.directory.copy(
+                os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    "common-ui",
+                    "css"),
+                os.path.join(
+                    master['pki_tomcat_webapps_common_path'],
+                    "css"),
+                overwrite_flag=True)
+
+            # Copy /usr/share/pki/common-ui/img
+            # to <instance>/webapp/pki/images
+            util.directory.copy(
+                os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    "common-ui",
+                    "img"),
+                common_images,
+                overwrite_flag=True)
+
+            # Copy /usr/share/pki/<subsystem>-ui/webapps/<subsystem>/admin/graphics
+            # to <instance>/webapp/pki/images
+            dir = os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    master['pki_subsystem'].lower() + "-ui",
+                    "webapps",
+                    master['pki_subsystem'].lower(),
+                    "admin",
+                    "graphics")
+            if (util.directory.exists(dir)):
+                util.directory.copy(
+                    dir,
+                    common_images,
+                    overwrite_flag=True)
+
+            # Copy /usr/share/pki/<subsystem>-ui/webapps/<subsystem>/agent/graphics
+            # to <instance>/webapp/pki/images
+            dir = os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    master['pki_subsystem'].lower() + "-ui",
+                    "webapps",
+                    master['pki_subsystem'].lower(),
+                    "agent",
+                    "graphics")
+            if (util.directory.exists(dir)):
+                util.directory.copy(
+                    dir,
+                    common_images,
+                    overwrite_flag=True)
+
+            # Copy /usr/share/pki/<subsystem>-ui/webapps/<subsystem>/ee/graphics
+            # to <instance>/webapp/pki/images
+            dir = os.path.join(
+                    config.PKI_DEPLOYMENT_SOURCE_ROOT,
+                    master['pki_subsystem'].lower() + "-ui",
+                    "webapps",
+                    master['pki_subsystem'].lower(),
+                    "ee",
+                    "graphics")
+            if (util.directory.exists(dir)):
+                util.directory.copy(
+                    dir,
+                    common_images,
+                    overwrite_flag=True)
+
             util.directory.copy(
                 os.path.join(
                     config.PKI_DEPLOYMENT_SOURCE_ROOT,
diff --git a/base/setup/pkicreate b/base/setup/pkicreate
index 506e766ef56d5df8a32c013a7b0fa33fec2f1767..767960778db7ee7534943577564b21cc74570d16 100755
--- a/base/setup/pkicreate
+++ b/base/setup/pkicreate
@@ -2061,11 +2061,42 @@ sub process_pki_directories
                                     $default_dir_permissions, $default_file_permissions,
                                     $pki_user, $pki_group);
 
-
         return 0 if !copy_directory($ui_subsystem_path, $pki_instance_path,
                                     $default_dir_permissions, $default_file_permissions,
                                     $pki_user, $pki_group);
 
+        # Copy /usr/share/pki/common-ui/admin/console/img
+        # to <instance>/docroot/pki/images
+        return 0 if !copy_directory(
+            "$common_ui_subsystem_path/admin/console/img",
+            "$docroot_instance_path/pki/images",
+            $default_dir_permissions, $default_file_permissions,
+            $pki_user, $pki_group);
+
+        # Copy /usr/share/pki/common-ui/css
+        # to <instance>/docroot/pki/css
+        return 0 if !copy_directory(
+            "$common_ui_subsystem_path/css",
+            "$docroot_instance_path/pki/css",
+            $default_dir_permissions, $default_file_permissions,
+            $pki_user, $pki_group);
+
+        # Copy /usr/share/pki/common-ui/img
+        # to <instance>/docroot/pki/images
+        return 0 if !copy_directory(
+            "$common_ui_subsystem_path/img",
+            "$docroot_instance_path/pki/images",
+            $default_dir_permissions, $default_file_permissions,
+            $pki_user, $pki_group);
+
+        # Copy /usr/share/pki/<subsystem>-ui/docroot/<subsystem>/admin/console/img
+        # to <instance>/docroot/pki/images
+        return 0 if !copy_directory(
+            "$ui_subsystem_path/docroot/$subsystem_type/admin/console/img",
+            "$docroot_instance_path/pki/images",
+            $default_dir_permissions, $default_file_permissions,
+            $pki_user, $pki_group);
+
         # fix permissions
         if (!is_Windows()) {
             # Apache Specific
-- 
1.7.12.1

