From a1443dea6b2b02df5e398a1929e816c17e1581cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jean-No=C3=ABl=20Avila?= <jn.avila@free.fr>
Date: Sat, 25 Mar 2023 18:02:40 +0100
Subject: [PATCH] convert creation of po4a.conf to a python script
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

We unify the creation of po4a.conf in a python script. This
script is called by the Makefile.

Signed-off-by: Jean-No챘l Avila <jn.avila@free.fr>
---
 Makefile                    |  4 ++--
 scripts/create_po4a_conf    | 17 +++++++++++++++++
 scripts/create_po4a_conf.sh | 26 --------------------------
 3 files changed, 19 insertions(+), 28 deletions(-)
 create mode 100755 scripts/create_po4a_conf
 delete mode 100755 scripts/create_po4a_conf.sh

diff --git a/Makefile b/Makefile
index 51d972f..5eb482b 100644
--- a/Makefile
+++ b/Makefile
@@ -15,8 +15,8 @@ ifndef V
 endif
 endif
 
-po4a.conf: scripts/create_po4a_conf.sh sources.txt $(LANGUAGE_PO)
-	@./scripts/create_po4a_conf.sh
+po4a.conf: scripts/create_po4a_conf sources.txt $(LANGUAGE_PO)
+	@./scripts/create_po4a_conf
 
 po4a-stamp: po4a.conf $(EN_SOURCES) $(LANGUAGE_PO) Makefile
 	$(QUIET_PO4A)PERL5LIB=./po4a/lib po4a/po4a -v po4a.conf
diff --git a/scripts/create_po4a_conf b/scripts/create_po4a_conf
new file mode 100755
index 0000000..fa982fe
--- /dev/null
+++ b/scripts/create_po4a_conf
@@ -0,0 +1,17 @@
+#!/usr/bin/env python3
+import glob
+
+with open('po4a.conf', 'w') as f:
+    f.write('[po4a_langs]')
+    langs = [ l[17:-3] for l in glob.glob('po/documentation.*.po')]
+    langs.sort()
+    f.write(' '.join(langs))
+    f.write('\n[po4a_paths] po/documentation.pot $lang:po/documentation.$lang.po\n[options] opt: " -k 80"\n')
+    with open('sources.txt', 'r') as sources:
+        for source in sources:
+            source = source.strip()
+            f.write(f"[type: asciidoc] en/{source} $lang:./$lang/{source}")
+            if source.startswith('git'):
+                f.write(' add_$lang:?addenda/addendum.$lang.txt\n')
+            else:
+                f.write('\n')
diff --git a/scripts/create_po4a_conf.sh b/scripts/create_po4a_conf.sh
deleted file mode 100755
index ff10936..0000000
--- a/scripts/create_po4a_conf.sh
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/bin/bash
-
-echo -n "[po4a_langs]" >po4a.conf
-langs=$(for l in po/documentation.*.po
-do
-    rstripped=${l%%.po}
-    echo -n " ${rstripped##po/documentation.}"
-done)
-echo $langs >> po4a.conf
-
-cat <<EOF >>po4a.conf
-[po4a_paths] po/documentation.pot \$lang:po/documentation.\$lang.po
-[options] opt: " -k 80"
-
-EOF
-
-for f in $(cat sources.txt)
-do
-    echo -n "[type: asciidoc] en/$f \$lang:./\$lang/$f" >> po4a.conf
-    if [ ${f:0:3} = git ]
-    then
-        echo " add_\$lang:?addenda/addendum.\$lang.txt" >> po4a.conf
-    else
-        echo >> po4a.conf
-    fi
-done
-- 
GitLab