From f86e137683778362f22d58a43fe30546a5693f38 Mon Sep 17 00:00:00 2001
From: Andreas Jaeger <aj@suse.de>
Date: Sun, 1 Jun 2014 09:18:53 +0200
Subject: [PATCH] Fix translation setup for api-site

After a recent change to api-site, the translation scripts tried to
translate the www directory which is wrong.

This patch  unifies the translation setup of both propose and upstream
jobs into the common library and enhances the initial setup so that it
skips non-directories (like pom.xml) and special directories like www
and tools.

Change-Id: I9402d75ca9c8df67c62c56bbad582cb1166824c6
---
 .../common_translation_update.sh              | 45 +++++++++++++++++++
 .../propose_translation_update_manuals.sh     | 27 ++---------
 .../upstream_translation_update_manuals.sh    | 25 ++---------
 3 files changed, 52 insertions(+), 45 deletions(-)

diff --git a/modules/openstack_project/files/slave_scripts/common_translation_update.sh b/modules/openstack_project/files/slave_scripts/common_translation_update.sh
index f3befd53de..a83e33cee7 100644
--- a/modules/openstack_project/files/slave_scripts/common_translation_update.sh
+++ b/modules/openstack_project/files/slave_scripts/common_translation_update.sh
@@ -63,6 +63,51 @@ function setup_horizon ()
         -t PO --execute
 }
 
+# Set global variable DocFolder for manuals projects
+function init_manuals ()
+{
+    project=$1
+
+    DocFolder="doc"
+    if [ $project = "api-site" ] ; then
+        DocFolder="./"
+    fi
+}
+
+# Setup project manuals projects (api-site, openstack-manuals,
+# operations-guide) for transifex
+function setup_manuals ()
+{
+    # Generate pot one by one
+    for FILE in ${DocFolder}/*
+    do
+        # Skip non-directories
+        if [ ! -d $FILE ]
+        then
+            continue
+        fi
+        DOCNAME=${FILE#${DocFolder}/}
+        # Ignore directories that will not get translated
+        if [ "$DOCNAME" == "www" -o "$DOCNAME" == "tools" -o "$DOCNAME" == "generated" -o "$DOCNAME" == "publish-docs" ]
+        then
+            continue
+        fi
+        # Update the .pot file
+        ./tools/generatepot ${DOCNAME}
+        if [ -f ${DocFolder}/${DOCNAME}/locale/${DOCNAME}.pot ]
+        then
+            # Add all changed files to git
+            git add ${DocFolder}/${DOCNAME}/locale/*
+            # Set auto-local
+            tx set --auto-local -r openstack-manuals-i18n.${DOCNAME} \
+                "${DocFolder}/${DOCNAME}/locale/<lang>.po" --source-lang en \
+                --source-file ${DocFolder}/${DOCNAME}/locale/${DOCNAME}.pot \
+                -t PO --execute
+        fi
+    done
+
+}
+
 # Setup git so that git review works
 function setup_git ()
 {
diff --git a/modules/openstack_project/files/slave_scripts/propose_translation_update_manuals.sh b/modules/openstack_project/files/slave_scripts/propose_translation_update_manuals.sh
index b903544dd2..e8ec37667a 100755
--- a/modules/openstack_project/files/slave_scripts/propose_translation_update_manuals.sh
+++ b/modules/openstack_project/files/slave_scripts/propose_translation_update_manuals.sh
@@ -20,34 +20,15 @@
 ORG="openstack"
 PROJECT=$1
 
-DocFolder="doc"
-if [ $PROJECT = "api-site" ] ; then
-    DocFolder="./"
-fi
-
 source /usr/local/jenkins/slave_scripts/common_translation_update.sh
 
+init_manuals "$PROJECT"
+
 setup_git
 setup_review "$ORG" "$PROJECT"
 setup_translation
 
-# Generate pot one by one
-for FILE in ${DocFolder}/*
-do
-    DOCNAME=${FILE#${DocFolder}/}
-    # Update the .pot file
-    ./tools/generatepot ${DOCNAME}
-    if [ -f ${DocFolder}/${DOCNAME}/locale/${DOCNAME}.pot ]
-    then 
-        # Add all changed files to git
-        git add ${DocFolder}/${DOCNAME}/locale/*
-        # Set auto-local
-        tx set --auto-local -r openstack-manuals-i18n.${DOCNAME} \
-"${DocFolder}/${DOCNAME}/locale/<lang>.po" --source-lang en \
---source-file ${DocFolder}/${DOCNAME}/locale/${DOCNAME}.pot \
--t PO --execute
-    fi
-done
+setup_manuals
 
 # Pull upstream translations of files that are at least 75 %
 # translated
@@ -61,7 +42,7 @@ if [ $PROJECT = "openstack-manuals" ] ; then
     tx pull -f  --minimum-perc=8 -r openstack-manuals-i18n.common
 fi
 
-
+# Add imported upstream translations to git
 for FILE in ${DocFolder}/*
 do
     DOCNAME=${FILE#${DocFolder}/}
diff --git a/modules/openstack_project/files/slave_scripts/upstream_translation_update_manuals.sh b/modules/openstack_project/files/slave_scripts/upstream_translation_update_manuals.sh
index a6afb8f944..3468a67feb 100755
--- a/modules/openstack_project/files/slave_scripts/upstream_translation_update_manuals.sh
+++ b/modules/openstack_project/files/slave_scripts/upstream_translation_update_manuals.sh
@@ -18,11 +18,6 @@
 
 PROJECT=$1
 
-DocFolder="doc"
-if [ $PROJECT = "api-site" ] ; then
-    DocFolder="./"
-fi
-
 if [ ! `echo $ZUUL_REFNAME | grep master` ]
 then
     exit 0
@@ -30,26 +25,12 @@ fi
 
 source /usr/local/jenkins/slave_scripts/common_translation_update.sh
 
+init_manuals "$PROJECT"
+
 setup_git
 setup_translation
 
-# Generate pot one by one
-for FILE in ${DocFolder}/*
-do
-    DOCNAME=${FILE#${DocFolder}/}
-    # Update the .pot file
-    ./tools/generatepot ${DOCNAME}
-    if [ -f ${DocFolder}/${DOCNAME}/locale/${DOCNAME}.pot ]
-    then 
-        # Add all changed files to git
-        git add ${DocFolder}/${DOCNAME}/locale/*
-        # Set auto-local
-        tx set --auto-local -r openstack-manuals-i18n.${DOCNAME} \
-"${DocFolder}/${DOCNAME}/locale/<lang>.po" --source-lang en \
---source-file ${DocFolder}/${DOCNAME}/locale/${DOCNAME}.pot \
--t PO --execute
-    fi
-done
+setup_manuals
 
 if [ ! `git diff --cached --quiet HEAD --` ]
 then