Yedidyah Bar David has uploaded a new change for review.

Change subject: packaging: Add ovirt-engine-reports-tool
......................................................................

packaging: Add ovirt-engine-reports-tool

Change-Id: Ida41cf8e0fd04f2bfb0bfd655881625fa5a32cd9
Signed-off-by: Yedidyah Bar David <d...@redhat.com>
---
M Makefile
M ovirt-engine-reports.spec.in
A packaging/bin/ovirt-engine-reports-tool.sh
A packaging/setup/bin/ovirt-engine-reports-tool.env
A packaging/setup/bin/ovirt-engine-reports-tool.sh
M packaging/setup/ovirt_engine_setup/reports/constants.py
M packaging/setup/ovirt_engine_setup/reports/reportsutil.py
A 
packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/__init__.py
A 
packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/actions.py
A 
packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/misc.py
A 
packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/__init__.py
A 
packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/change_admin_password.py
A 
packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/export_import_ad_hoc.py
13 files changed, 798 insertions(+), 64 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-reports refs/changes/32/42032/1

diff --git a/Makefile b/Makefile
index 6144c4d..9d2a90e 100644
--- a/Makefile
+++ b/Makefile
@@ -36,6 +36,7 @@
 PREFIX=/usr/local
 ENGINE_PREFIX=$(PREFIX)
 LOCALSTATE_DIR=$(PREFIX)/var
+BIN_DIR=$(PREFIX)/bin
 SYSCONF_DIR=$(PREFIX)/etc
 ENGINE_SYSCONF_DIR=$(ENGINE_PREFIX)/etc
 ENGINE_VARS=$(ENGINE_SYSCONF_DIR)/$(ENGINE_NAME)/engine.conf
@@ -222,6 +223,7 @@
                $(NULL)
 
        ln -sf ovirt_reports_bundle_en_US.properties.data 
"$(DESTDIR)$(PKG_DATA_DIR)/ovirt-reports/resources/reports_resources/localization/ovirt_reports_bundle.properties.data"
+       ln -sf "$(ENGINE_DATA_DIR)/setup/bin/ovirt-engine-reports-tool" 
"$(DESTDIR)$(BIN_DIR)/ovirt-engine-reports-tool"
        install -dm 755 "$(DESTDIR)$(PKG_STATE_DIR)/backups"
 
 install-jdbc: \
diff --git a/ovirt-engine-reports.spec.in b/ovirt-engine-reports.spec.in
index 0b6c082..204d582 100644
--- a/ovirt-engine-reports.spec.in
+++ b/ovirt-engine-reports.spec.in
@@ -236,6 +236,7 @@
 %{_datadir}/ovirt-engine/setup/ovirt_engine_setup/reports/
 %{_datadir}/ovirt-engine/setup/plugins/*/ovirt-engine-reports/
 %{_datadir}/ovirt-engine/firewalld/reports/
+%{_bindir}/ovirt-engine-reports-tool
 
 %changelog
 * Sun Sep 07 2014 Shirly Radco <sra...@redhat.com> - 3.5.0
diff --git a/packaging/bin/ovirt-engine-reports-tool.sh 
b/packaging/bin/ovirt-engine-reports-tool.sh
new file mode 100755
index 0000000..8fcc330
--- /dev/null
+++ b/packaging/bin/ovirt-engine-reports-tool.sh
@@ -0,0 +1,120 @@
+#!/bin/sh
+# ovirt-engine-reports-tool - oVirt engine reports tool
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#        http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+usage() {
+       cat << __EOF__
+Usage: $0 [OPTIONS]
+
+OPTIONS is one of:
+    --export-ad-hoc-reports-to=FILE     Export Ad Hoc reports to FILE
+    --import-ad-hoc-reports-from=FILE   Import Ad Hoc reports from FILE
+    --change-admin-password-from=FILE   Change internal admin accound 
password, read it from file
+    --change-admin-password             Change internal admin accound 
password, read it interactively
+    --change-admin-password-to=PASS     Change internal admin accound password 
to pass
+__EOF__
+}
+
+load_config() {
+       DEFAULTS="$(dirname "$(readlink -f 
"$0")")"/../services/ovirt-engine-reportsd/ovirt-engine-reportsd.conf
+       [ -r "${DEFAULTS}" ] && . "${DEFAULTS}"
+       for f in \
+               "${SERVICE_VARS}" \
+               $([ -d "${SERVICE_VARS}.d" ] && find "${SERVICE_VARS}.d" -name 
'*.conf' | sort) \
+       ; do
+               [ -r "${f}" ] && . "${f}"
+       done
+}
+
+TODO set env, including jasper home
+
+TMP="$(mktemp -d -t ovirt-engine-reports-tool.XXXXXXXXXX)"
+cleanup() {
+       rm -f "${TMPKEY}"
+}
+trap cleanup 0
+
+while [ -n "$1" ]; do
+       x="$1"
+       v="${x#*=}"
+       shift
+       case "${x}" in
+               --password=*)
+                       PASSWORD="${v}"
+               ;;
+               --help)
+                       usage
+                       exit 0
+               ;;
+               *)
+                       usage
+                       exit 1
+               ;;
+       esac
+done
+
+[ -n "${PASSWORD}" ] || die "Please specify password"
+
+
+https://access.redhat.com/solutions/65412:
+1. Export the configuration directory:
+
+   # export ADDITIONAL_CONFIG_DIR=/var/lib/ovirt-engine-reports/build-conf
+
+2. Create a temporary export directory:
+
+   # mkdir -p /tmp/reports-users
+
+3. Navigate to the Jasper scripts directory:
+
+    # cd /usr/share/jasperreports-server-pro/buildomatic
+
+4. Export users from the jasper reports metadata to temporary directory 
created in Step 2.:
+
+   # ./js-export.sh --output-dir /tmp/reports-users/ --users
+
+5. Edit the exported user detail XML files, and update the existing encrypted 
password with a new password in clear text:
+
+   # vim /tmp/reports-users/users/superuser.xml
+   # vim /tmp/reports-users/users/organization_1/admin.xml
+
+   Note: The password is later encrypted on import.
+
+6. Import the user data into the reports metadata:
+
+   # ./js-import.sh --input-dir /tmp/reports-users/ --update
+
+7. Delete the temporary export directory:
+
+   # rm -rf /tmp/reports-users
+
+
+
+
+
+https://bugzilla.redhat.com/show_bug.cgi?id=1198107:
+ANT_OPTS=-DmasterPropsSource=/var/lib/ovirt-engine-reports/build-conf/master.properties
+
+
+
+
+https://access.redhat.com/solutions/1202463:
+# export ADDITIONAL_CONFIG_DIR=/var/lib/ovirt-engine-reports/build-conf
+# /usr/share/jasperreports-server/buildomatic/js-export.sh --uris 
/organizations/organization_1/adhoc/aru --output-zip < zip file name >.zip
+
+# export ADDITIONAL_CONFIG_DIR=/var/lib/ovirt-engine-reports/build-conf
+# /usr/share/jasperreports-server/buildomatic/js-import.sh --input-zip < zip 
file name >.zip
+
diff --git a/packaging/setup/bin/ovirt-engine-reports-tool.env 
b/packaging/setup/bin/ovirt-engine-reports-tool.env
new file mode 100644
index 0000000..16be950
--- /dev/null
+++ b/packaging/setup/bin/ovirt-engine-reports-tool.env
@@ -0,0 +1,19 @@
+
+ENV="/etc/ovirt-engine-reports-tool.env.d"
+for f in $([ -d "${ENV}" ] && find "${ENV}" -name '*.env' | sort); do
+       [ -r "${f}" ] && . "${f}"
+done
+
+script="$(readlink -f "$0")"
+scriptdir="$(dirname "${script}")"
+extraenv=""
+if [ -z "${OTOPI_SOURCES}" ]; then
+       if [ -x "${scriptdir}/otopi" ]; then
+               otopidir="${scriptdir}"
+       else
+               otopidir="/usr/sbin"
+       fi
+else
+       otopidir="${OTOPI_SOURCES}/src/bin"
+fi
+export PYTHONPATH="$(cd "${scriptdir}" && pwd)/..:${PYTHONPATH}"
diff --git a/packaging/setup/bin/ovirt-engine-reports-tool.sh 
b/packaging/setup/bin/ovirt-engine-reports-tool.sh
new file mode 100644
index 0000000..c962bb2
--- /dev/null
+++ b/packaging/setup/bin/ovirt-engine-reports-tool.sh
@@ -0,0 +1,92 @@
+#!/bin/sh
+#
+# ovirt-engine-reports-tool
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+die() { 
+       local m="$1"
+       echo "FATAL: ${m}" >&2
+       exit 1
+}
+
+usage() {
+       cat << __EOF__
+Usage: $0
+    --log=file
+        write log to this file.
+    --config=file
+        Load configuration files.
+    --config-append=file
+        Load extra configuration files or answer file.
+    --generate-answer=file
+        Generate answer file.
+    --export-ad-hoc-reports
+        Export Ad Hoc reports.
+    --import-ad-hoc-reports
+        Import Ad Hoc reports.
+    --change-reports-admin-password
+        Change Reports admin password.
+
+__EOF__
+       exit 1
+}
+
+script="$(readlink -f "$0")"
+scriptdir="$(dirname "${script}")"
+. "${scriptdir}/ovirt-engine-reports-tool.env"
+baseenv="\"APPEND:BASE/pluginPath=str:${scriptdir}/../plugins\" 
APPEND:BASE/pluginGroups=str:ovirt-engine-common:ovirt-engine-reports-tool"
+otopienv=""
+environment=""
+
+while [ -n "$1" ]; do
+       x="$1"
+       v="${x#*=}"
+       shift
+       case "${x}" in
+               --otopi-environment=*)
+                       otopienv="${v}"
+                       ;;
+               --log=*)
+                       environment="${environment} 
\"CORE/logFileName=str:${v}\""
+                       ;;
+               --config=*)
+                       environment="${environment} 
\"APPEND:CORE/configFileName=str:${v}\""
+                       ;;
+               --config-append=*)
+                       environment="${environment} 
\"APPEND:CORE/configFileAppend=str:${v}\""
+                       ;;
+               --generate-answer=*)
+                       environment="${environment} 
\"OVESETUP_CORE/answerFile=str:${v}\""
+                       ;;
+               --export-ad-hoc-reports)
+                       environment="${environment} 
\"OVESETUP_REPORTS_TOOL/action=str:exportAdHocReports\""
+                       ;;
+               --import-ad-hoc-reports)
+                       environment="${environment} 
\"OVESETUP_REPORTS_TOOL/action=str:importAdHocReports\""
+                       ;;
+               --change-reports-admin-password)
+                       environment="${environment} 
\"OVESETUP_REPORTS_TOOL/action=str:changeAdminPassword\""
+                       ;;
+               --help)
+                       usage
+                       ;;
+               *)
+                       die "Invalid option '${x}'"
+                       ;;
+       esac
+done
+
+exec "${otopidir}/otopi" "${baseenv} ${environment} ${otopienv}"
diff --git a/packaging/setup/ovirt_engine_setup/reports/constants.py 
b/packaging/setup/ovirt_engine_setup/reports/constants.py
index 1a63385..137898a 100644
--- a/packaging/setup/ovirt_engine_setup/reports/constants.py
+++ b/packaging/setup/ovirt_engine_setup/reports/constants.py
@@ -123,6 +123,10 @@
             DEK.DATABASE: DWHDefaults.DEFAULT_DB_DATABASE,
         }
 
+    TOOL_ACTION_EXPORT_AD_HOC = 'exportAdHocReports'
+    TOOL_ACTION_IMPORT_AD_HOC = 'importAdHocReports'
+    TOOL_ACTION_CHANGE_ADMIN_PASSWORD = 'changeAdminPassword'
+
 
 @util.export
 @util.codegen
@@ -338,6 +342,7 @@
         OVIRT_ENGINE_PKICERTSDIR,
         '%s.cer' % Const.PKI_REPORTS_APACHE_CERT_NAME,
     )
+    OVIRT_REPORTS_TOOL_LOG_PREFIX = 'ovirt-engine-reports-tool'
 
 
 @util.export
@@ -356,6 +361,8 @@
 
     # sync with engine
     ENGINE_CORE_ENABLE = 'osetup.engine.core.enable'
+
+    TOOL_ACTION_SELECTED = 'osetup.reports.tool.action.selected'
 
 
 @util.export
@@ -707,4 +714,15 @@
     ENABLE = 'OVESETUP_DWH_CORE/enable'
 
 
+@util.export
+@util.codegen
+@osetupattrsclass
+class ToolEnv(object):
+
+    AVAILABLE_ACTIONS = 'OVESETUP_REPORTS_TOOL/availableActions'
+    ACTION = 'OVESETUP_REPORTS_TOOL/action'
+    FILE = 'OVESETUP_REPORTS_TOOL/file'
+    NEW_ADMIN_PASSWORD = 'OVESETUP_REPORTS_TOOL/newAdminPassword'
+
+
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/packaging/setup/ovirt_engine_setup/reports/reportsutil.py 
b/packaging/setup/ovirt_engine_setup/reports/reportsutil.py
index bd67ed7..9a56fef 100644
--- a/packaging/setup/ovirt_engine_setup/reports/reportsutil.py
+++ b/packaging/setup/ovirt_engine_setup/reports/reportsutil.py
@@ -110,8 +110,38 @@
         pattern='|'.join(_IGNORED_ERRORS),
     )
 
-    def _execute(self, *eargs, **kwargs):
-        rc, stdout, stderr = self._plugin.execute(*eargs, **kwargs)
+    def execute(self, args):
+        rc, stdout, stderr = self._plugin.execute(
+            args=args,
+            cwd=os.path.join(
+                self.environment[
+                    oreportscons.ConfigEnv.JASPER_HOME
+                ],
+                'buildomatic',
+            ),
+            envAppend={
+                'JAVA_HOME': self.environment[
+                    oengcommcons.ConfigEnv.JAVA_HOME
+                ],
+                'PATH': '{java_home}/bin:{cur_path}'.format(
+                    java_home=self.environment[
+                        oengcommcons.ConfigEnv.JAVA_HOME
+                    ],
+                    cur_path=os.environ['PATH'],
+                ),
+                'JAVA_OPTS': '-Djava.io.tmpdir=%s' % self._javatmp,
+                'ADDITIONAL_CONFIG_DIR': (
+                    oreportscons.FileLocations.
+                    OVIRT_ENGINE_REPORTS_BUILDOMATIC_CONFIG
+                ),
+                'ANT_OPTS': '-DmasterPropsSource={master}'.format(
+                    master=(
+                        oreportscons.FileLocations.
+                        OVIRT_ENGINE_REPORTS_BUILDOMATIC_DBPROP
+                    ),
+                ),
+            },
+        )
 
         errors = []
         if stderr:
@@ -129,77 +159,21 @@
             self._temproot,
             what,
         )
-        self._execute(
-            args=(
+        self.execute(
+            (
                 './js-export.sh',
                 '--output-dir', dest,
-            ) + args,
-            cwd=os.path.join(
-                self.environment[
-                    oreportscons.ConfigEnv.JASPER_HOME
-                ],
-                'buildomatic',
-            ),
-            envAppend={
-                'JAVA_HOME': self.environment[
-                    oengcommcons.ConfigEnv.JAVA_HOME
-                ],
-                'PATH': '{java_home}/bin:{cur_path}'.format(
-                    java_home=self.environment[
-                        oengcommcons.ConfigEnv.JAVA_HOME
-                    ],
-                    cur_path=os.environ['PATH'],
-                ),
-                'JAVA_OPTS': '-Djava.io.tmpdir=%s' % self._javatmp,
-                'ADDITIONAL_CONFIG_DIR': (
-                    oreportscons.FileLocations.
-                    OVIRT_ENGINE_REPORTS_BUILDOMATIC_CONFIG
-                ),
-                'ANT_OPTS': '-DmasterPropsSource={master}'.format(
-                    master=(
-                        oreportscons.FileLocations.
-                        OVIRT_ENGINE_REPORTS_BUILDOMATIC_DBPROP
-                    ),
-                ),
-            },
+            ) + args
         )
         return dest
 
     def jsimport(self, src):
-        self._execute(
-            args=(
+        self.execute(
+            (
                 './js-import.sh',
                 '--input-dir', src,
                 '--update',
-            ),
-            cwd=os.path.join(
-                self.environment[
-                    oreportscons.ConfigEnv.JASPER_HOME
-                ],
-                'buildomatic',
-            ),
-            envAppend={
-                'JAVA_HOME': self.environment[
-                    oengcommcons.ConfigEnv.JAVA_HOME
-                ],
-                'PATH': '{java_home}/bin:{cur_path}'.format(
-                    java_home=self.environment[
-                        oengcommcons.ConfigEnv.JAVA_HOME
-                    ],
-                    cur_path=os.environ['PATH'],
-                ),
-                'JAVA_OPTS': '-Djava.io.tmpdir=%s' % self._javatmp,
-                'ADDITIONAL_CONFIG_DIR': (
-                    oreportscons.FileLocations.
-                    OVIRT_ENGINE_REPORTS_BUILDOMATIC_CONFIG
-                ),
-                'ANT_OPTS': '-DmasterPropsSource={master}'.format(
-                    master=(
-                        oreportscons.FileLocations.
-                        OVIRT_ENGINE_REPORTS_BUILDOMATIC_DBPROP
-                    ),
-                ),
-            },
+            )
         )
 
 
diff --git 
a/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/__init__.py
 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/__init__.py
new file mode 100644
index 0000000..28a1bc5
--- /dev/null
+++ 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/__init__.py
@@ -0,0 +1,35 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+"""Reports setup core plugin."""
+
+
+from otopi import util
+
+
+from . import actions
+from . import misc
+
+
+@util.export
+def createPlugins(context):
+    actions.Plugin(context=context)
+    misc.Plugin(context=context)
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/actions.py
 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/actions.py
new file mode 100644
index 0000000..3ce1e63
--- /dev/null
+++ 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/actions.py
@@ -0,0 +1,100 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+"""Actions plugin."""
+
+
+import gettext
+
+from otopi import plugin, util
+
+from ovirt_engine_setup.reports import constants as oreportscons
+
+
+def _(m):
+    return gettext.dgettext(message=m, domain='ovirt-engine-reports')
+
+
+@util.export
+class Plugin(plugin.PluginBase):
+    """Misc plugin."""
+
+    def __init__(self, context):
+        super(Plugin, self).__init__(context=context)
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_INIT,
+    )
+    def _init(self):
+        self.environment.setdefault(
+            oreportscons.ToolEnv.AVAILABLE_ACTIONS,
+            []
+        )
+        self.environment.setdefault(
+            oreportscons.ToolEnv.ACTION,
+            None
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CUSTOMIZATION,
+        name=oreportscons.Stages.TOOL_ACTION_SELECTED,
+        condition=lambda (self): self.environment[
+            oreportscons.ToolEnv.ACTION
+        ] is None,
+    )
+    def _customization(self):
+        actions = [
+            (_(str(i)), action)
+            for i, action in enumerate(
+                sorted(
+                    self.environment[
+                        oreportscons.ToolEnv.AVAILABLE_ACTIONS
+                        ],
+                    key=lambda (action): action['name']
+                ),
+                start=1
+            )
+        ]
+        res = self.dialog.queryString(
+            name='OVESETUP_REPORTS_TOOL_ACTION',
+            note=_(
+                'Please choose the action you would like this tool to take:\n'
+                '{actions}'
+            ).format(
+                actions='\n'.join(
+                    '({i}) {desc}\n'.format(
+                        i=item[0],
+                        desc=item[1]['desc'],
+                    )
+                    for item in actions
+                ),
+            ),
+            prompt=True,
+            validValues=[item[0] for item in actions],
+            caseSensitive=False,
+        )
+        self.environment[
+            oreportscons.ToolEnv.ACTION
+        ] = next(
+            item[1]['name']
+            for i, item in actions
+            if item[0] == res
+        )
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/misc.py
 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/misc.py
new file mode 100644
index 0000000..5fc8c84
--- /dev/null
+++ 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/core/misc.py
@@ -0,0 +1,60 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+"""Misc plugin."""
+
+
+import gettext
+
+from otopi import constants as otopicons
+from otopi import plugin, util
+
+from ovirt_engine_setup import constants as osetupcons
+from ovirt_engine_setup.reports import constants as oreportscons
+
+
+def _(m):
+    return gettext.dgettext(message=m, domain='ovirt-engine-reports')
+
+
+@util.export
+class Plugin(plugin.PluginBase):
+    """Misc plugin."""
+
+    def __init__(self, context):
+        super(Plugin, self).__init__(context=context)
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_BOOT,
+        before=(
+            otopicons.Stages.CORE_LOG_INIT,
+        ),
+        priority=plugin.Stages.PRIORITY_HIGH - 10,
+    )
+    def _preinit(self):
+        self.environment.setdefault(
+            otopicons.CoreEnv.LOG_DIR,
+            osetupcons.FileLocations.OVIRT_SETUP_LOGDIR
+        )
+        self.environment.setdefault(
+            otopicons.CoreEnv.LOG_FILE_NAME_PREFIX,
+            oreportscons.FileLocations.OVIRT_REPORTS_TOOL_LOG_PREFIX
+        )
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/__init__.py
 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/__init__.py
new file mode 100644
index 0000000..9a75a08
--- /dev/null
+++ 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/__init__.py
@@ -0,0 +1,35 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+"""Reports setup core plugin."""
+
+
+from otopi import util
+
+
+from . import change_admin_password
+from . import export_import_ad_hoc
+
+
+@util.export
+def createPlugins(context):
+    change_admin_password.Plugin(context=context)
+    export_import_ad_hoc.Plugin(context=context)
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/change_admin_password.py
 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/change_admin_password.py
new file mode 100644
index 0000000..f992f06
--- /dev/null
+++ 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/change_admin_password.py
@@ -0,0 +1,131 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+"""Change Admin Password plugin."""
+
+
+import gettext
+import os
+
+from otopi import plugin, util
+
+from ovirt_engine_setup import dialog
+from ovirt_engine_setup.reports import constants as oreportscons
+from ovirt_engine_setup.reports import oreportsutil
+
+
+def _(m):
+    return gettext.dgettext(message=m, domain='ovirt-engine-reports')
+
+
+@util.export
+class Plugin(plugin.PluginBase):
+    """Change Admin Password plugin."""
+
+    def __init__(self, context):
+        super(Plugin, self).__init__(context=context)
+        self._oreportsutil = None
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_INIT,
+    )
+    def _init(self):
+        self.environment.setdefault(
+            oreportscons.ToolEnv.NEW_ADMIN_PASSWORD,
+            None
+        )
+        self._oreportsutil = oreportsutil.JasperUtil(plugin=self)
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_SETUP,
+    )
+    def _setup(self):
+        self.environment[
+            oreportscons.ToolEnv.ACTIONS
+        ].extend(
+            (
+                {
+                    'name': (
+                        oreportscons.Const.TOOL_ACTION_CHANGE_ADMIN_PASSWORD
+                    ),
+                    'desc': _(
+                        'Change the password of the internal Reports Admin',
+                    ),
+                },
+            )
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CUSTOMIZATION,
+        after=(
+            oreportscons.Stages.TOOL_ACTION_SELECTED,
+        ),
+        condition=lambda (self): self.environment[
+            oreportscons.ToolEnv.ACTION
+        ] == oreportscons.Const.TOOL_ACTION_CHANGE_ADMIN_PASSWORD,
+    )
+    def _customization(self):
+        dialog.queryPassword(
+            dialog=self.dialog,
+            logger=self.logger,
+            env=self.environment,
+            key=oreportscons.ToolEnv.NEW_ADMIN_PASSWORD,
+            note=_(
+                'Reports admin password: '
+            ),
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_MISC,
+        condition=lambda (self): self.environment[
+            oreportscons.ToolEnv.ACTION
+        ] == oreportscons.Const.TOOL_ACTION_CHANGE_ADMIN_PASSWORD,
+    )
+    def _misc_reports_admin_password(self):
+        users = self._oreportsutil.jsexport(
+            what='users',
+            args=(
+                '--users',
+            ),
+        )
+
+        for f in (
+            os.path.join(
+                users,
+                'users',
+                'superuser.xml'
+            ),
+            os.path.join(
+                users,
+                'users',
+                'organization_1',
+                'admin.xml'
+            )
+        ):
+            with oreportsutil.XMLDoc(f) as xml:
+                xml.setNodesContent(
+                    '/user/password',
+                    self.environment[
+                        oreportscons.ToolEnv.NEW_ADMIN_PASSWORD
+                    ]
+                )
+
+        self._oreportsutil.jsimport(users)
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git 
a/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/export_import_ad_hoc.py
 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/export_import_ad_hoc.py
new file mode 100644
index 0000000..e610ebd
--- /dev/null
+++ 
b/packaging/setup/plugins/ovirt-engine-reports-tool/ovirt-engine-reports/jasper/export_import_ad_hoc.py
@@ -0,0 +1,147 @@
+#
+# ovirt-engine-setup -- ovirt engine setup
+# Copyright (C) 2015 Red Hat, Inc.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+
+"""Export/Import Ad Hoc reports plugin."""
+
+
+import gettext
+import os
+
+from otopi import plugin, util
+
+from ovirt_engine_setup import dialog
+from ovirt_engine_setup.reports import constants as oreportscons
+from ovirt_engine_setup.reports import oreportsutil
+
+
+def _(m):
+    return gettext.dgettext(message=m, domain='ovirt-engine-reports')
+
+
+@util.export
+class Plugin(plugin.PluginBase):
+    """Export/Import Ad Hoc reports plugin."""
+
+    def __init__(self, context):
+        super(Plugin, self).__init__(context=context)
+        self._oreportsutil = None
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_INIT,
+    )
+    def _init(self):
+        self.environment.setdefault(
+            oreportscons.ToolEnv.FILE,
+            None
+        )
+        self._oreportsutil = oreportsutil.JasperUtil(plugin=self)
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_SETUP,
+    )
+    def _setup(self):
+        self.environment[
+            oreportscons.ToolEnv.ACTIONS
+        ].extend(
+            (
+                {
+                    'name': oreportscons.Const.TOOL_ACTION_EXPORT_AD_HOC,
+                    'desc': _(
+                        'Export Jasperreports Ad-Hoc reports to a zip file'
+                    ),
+                },
+                {
+                    'name': oreportscons.Const.TOOL_ACTION_IMPORT_AD_HOC,
+                    'desc': _(
+                        'Import an Ad-Hoc Reports zip file to Jasperreports'
+                    ),
+                },
+            )
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_CUSTOMIZATION,
+        after=(
+            oreportscons.Stages.TOOL_ACTION_SELECTED,
+        ),
+        condition=lambda (self): self.environment[
+            oreportscons.ToolEnv.ACTION
+        ] in (
+            oreportscons.Const.TOOL_ACTION_EXPORT_AD_HOC,
+            oreportscons.Const.TOOL_ACTION_IMPORT_AD_HOC,
+        ) and oreportscons.ToolEnv.FILE is None,
+    )
+    def _customization(self):
+        dialog.queryEnvKey(
+            dialog=self.dialog,
+            logger=self.logger,
+            env=self.environment,
+            key=oreportscons.ToolEnv.FILE,
+            note=(
+                _(
+                    'Filename to export ad-hoc reports to:'
+                ) if self.environment[
+                    oreportscons.ToolEnv.ACTION
+                ] == oreportscons.Const.TOOL_ACTION_EXPORT_AD_HOC else _(
+                    'Filename to import ad-hoc reports from:'
+                ),
+            ),
+            tests=(
+                (
+                    {
+                        'test': lambda(f): (
+                            '' if os.path.exists(f)
+                            else _('File {file} not found')
+                        ),
+                    },
+                ) if self.environment[
+                    oreportscons.ToolEnv.ACTION
+                ] == oreportscons.Const.TOOL_ACTION_EXPORT_AD_HOC else (),
+            ),
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_MISC,
+        condition=lambda (self): self.environment[
+            oreportscons.ToolEnv.ACTION
+        ] == oreportscons.Const.TOOL_ACTION_EXPORT_AD_HOC,
+    )
+    def _misc_export(self):
+        self._oreportsutil.execute(
+            args=(
+                './js-export.sh',
+                '--output-zip', self.environment[oreportscons.ToolEnv.FILE],
+            )
+        )
+
+    @plugin.event(
+        stage=plugin.Stages.STAGE_MISC,
+        condition=lambda (self): self.environment[
+            oreportscons.ToolEnv.ACTION
+        ] == oreportscons.Const.TOOL_ACTION_IMPORT_AD_HOC,
+    )
+    def _misc_import(self):
+        self._oreportsutil.execute(
+            args=(
+                './js-import.sh',
+                '--input-zip', self.environment[oreportscons.ToolEnv.FILE],
+            )
+        )
+
+
+# vim: expandtab tabstop=4 shiftwidth=4


-- 
To view, visit https://gerrit.ovirt.org/42032
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ida41cf8e0fd04f2bfb0bfd655881625fa5a32cd9
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-reports
Gerrit-Branch: master
Gerrit-Owner: Yedidyah Bar David <d...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to