diff mbox series

[v2,2/3] lib/oe/package: add LOCALEEXTRADIRS to define extra locations for locales

Message ID CXNASYPMNU9N.2AKRQ4ODCZYTH@joggee.fr
State Superseded, archived
Headers show
Series lib/oe/package: allow to scan extra directories for locale files | expand

Commit Message

Jonathan GUILLOT Dec. 6, 2023, 4:03 p.m. UTC
Some packages may contain localized files not located in
/usr/share/locale. This new variables allows to add these directories in
dedicated locale packages.

Signed-off-by: Jonathan GUILLOT <jonathan@joggee.fr>
---
 meta/lib/oe/package.py | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

Comments

Khem Raj Dec. 13, 2023, 8:45 p.m. UTC | #1
On Wed, Dec 13, 2023 at 7:07 AM Jonathan GUILLOT <jonathan@joggee.fr> wrote:
>
> Some packages may contain localized files not located in
> /usr/share/locale. This new variables allows to add these directories in
> dedicated locale packages.

I think using _ to separate the words would make it more readable so
call it LOCALE_EXTRA_PATHS or something.
secondly, it needs to be documented as well.

>
> Signed-off-by: Jonathan GUILLOT <jonathan@joggee.fr>
> ---
>  meta/lib/oe/package.py | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
> index 2f7a50e144..fc8b20324e 100644
> --- a/meta/lib/oe/package.py
> +++ b/meta/lib/oe/package.py
> @@ -653,24 +653,37 @@ def split_locales(d):
>      except ValueError:
>          locale_index = len(packages)
>
> -    localedir = os.path.join(dvar + datadir, 'locale')
> +    localedirs = [os.path.join(dvar + datadir, 'locale')]
>
> -    if not cpath.isdir(localedir):
> +    for localedir in (d.getVar('LOCALEEXTRADIRS') or "").split():
> +        localedirs.append(dvar + localedir)
> +
> +    locales = set()
> +    locale_found = False
> +    for localedir in localedirs:
> +        if cpath.isdir(localedir):
> +            locale_found = True
> +            locales.update(os.listdir(localedir))
> +
> +    if not locale_found:
>          bb.debug(1, "No locale files in this package")
>          return
>
> -    locales = os.listdir(localedir)
> -
>      summary = d.getVar('SUMMARY') or pn
>      description = d.getVar('DESCRIPTION') or ""
>      locale_section = d.getVar('LOCALE_SECTION')
>      mlprefix = d.getVar('MLPREFIX') or ""
> +    dvar_len = len(dvar)
>      for l in sorted(locales):
>          ln = legitimize_package_name(l)
>          pkg = pn + '-locale-' + ln
>          packages.insert(locale_index, pkg)
>          locale_index += 1
> -        d.setVar('FILES:' + pkg, os.path.join(datadir, 'locale', l))
> +        files = []
> +        for localedir in localedirs:
> +            # Remove dvar prefix
> +            files.append(os.path.join(localedir[dvar_len:], l))
> +        d.setVar('FILES:' + pkg, " ".join(files))
>          d.setVar('RRECOMMENDS:' + pkg, '%svirtual-locale-%s' % (mlprefix, ln))
>          d.setVar('RPROVIDES:' + pkg, '%s-locale %s%s-translation' % (pn, mlprefix, ln))
>          d.setVar('SUMMARY:' + pkg, '%s - %s translations' % (summary, l))
> --
> 2.43.0
>
>
>
> -=-=-=-=-=-=-=-=-=-=-=-
> Links: You receive all messages sent to this group.
> View/Reply Online (#192302): https://lists.openembedded.org/g/openembedded-core/message/192302
> Mute This Topic: https://lists.openembedded.org/mt/103150560/1997914
> Group Owner: openembedded-core+owner@lists.openembedded.org
> Unsubscribe: https://lists.openembedded.org/g/openembedded-core/unsub [raj.khem@gmail.com]
> -=-=-=-=-=-=-=-=-=-=-=-
>
Jonathan GUILLOT Dec. 14, 2023, 10:42 a.m. UTC | #2
Hi Khem Raj,

Le mer. 13 déc. 2023 à 21:45, Khem Raj <raj.khem@gmail.com> a écrit :
> I think using _ to separate the words would make it more readable so
> call it LOCALE_EXTRA_PATHS or something.
> secondly, it needs to be documented as well.

The naming LOCALEEXTRADIRS is inspired from existing FILESEXTRAPATHS.
Is there some guidelines for variable naming?
Definitely, I should add a bit of documentation.
Khem Raj Dec. 14, 2023, 4:45 p.m. UTC | #3
On Thu, Dec 14, 2023 at 2:42 AM Jonathan GUILLOT <jonathan@joggee.fr> wrote:
>
> Hi Khem Raj,
>
> Le mer. 13 déc. 2023 à 21:45, Khem Raj <raj.khem@gmail.com> a écrit :
> > I think using _ to separate the words would make it more readable so
> > call it LOCALE_EXTRA_PATHS or something.
> > secondly, it needs to be documented as well.
>
> The naming LOCALEEXTRADIRS is inspired from existing FILESEXTRAPATHS.
> Is there some guidelines for variable naming?

We used this convention when we used '_'  as an override separator.
That constainst is no more as we use ':' now.

> Definitely, I should add a bit of documentation.
Jonathan GUILLOT Dec. 18, 2023, 10:52 a.m. UTC | #4
Hi,

I am just looking to existing variables to add documentation for
LOCALE_EXTRA_PATHS and it makes me think about separator to use.
FILESEXTRAPATHS use ':' between each path, PACKAGE_FEED_BASE_PATHS
uses simple space ' ' and PSEUDO_IGNORE_PATHS is comma-separated list.
What is the best option here?

Regards,
Jonathan GUILLOT

Le jeu. 14 déc. 2023 à 17:45, Khem Raj <raj.khem@gmail.com> a écrit :
>
> We used this convention when we used '_'  as an override separator.
> That constainst is no more as we use ':' now.
>
diff mbox series

Patch

diff --git a/meta/lib/oe/package.py b/meta/lib/oe/package.py
index 2f7a50e144..fc8b20324e 100644
--- a/meta/lib/oe/package.py
+++ b/meta/lib/oe/package.py
@@ -653,24 +653,37 @@  def split_locales(d):
     except ValueError:
         locale_index = len(packages)
 
-    localedir = os.path.join(dvar + datadir, 'locale')
+    localedirs = [os.path.join(dvar + datadir, 'locale')]
 
-    if not cpath.isdir(localedir):
+    for localedir in (d.getVar('LOCALEEXTRADIRS') or "").split():
+        localedirs.append(dvar + localedir)
+
+    locales = set()
+    locale_found = False
+    for localedir in localedirs:
+        if cpath.isdir(localedir):
+            locale_found = True
+            locales.update(os.listdir(localedir))
+
+    if not locale_found:
         bb.debug(1, "No locale files in this package")
         return
 
-    locales = os.listdir(localedir)
-
     summary = d.getVar('SUMMARY') or pn
     description = d.getVar('DESCRIPTION') or ""
     locale_section = d.getVar('LOCALE_SECTION')
     mlprefix = d.getVar('MLPREFIX') or ""
+    dvar_len = len(dvar)
     for l in sorted(locales):
         ln = legitimize_package_name(l)
         pkg = pn + '-locale-' + ln
         packages.insert(locale_index, pkg)
         locale_index += 1
-        d.setVar('FILES:' + pkg, os.path.join(datadir, 'locale', l))
+        files = []
+        for localedir in localedirs:
+            # Remove dvar prefix
+            files.append(os.path.join(localedir[dvar_len:], l))
+        d.setVar('FILES:' + pkg, " ".join(files))
         d.setVar('RRECOMMENDS:' + pkg, '%svirtual-locale-%s' % (mlprefix, ln))
         d.setVar('RPROVIDES:' + pkg, '%s-locale %s%s-translation' % (pn, mlprefix, ln))
         d.setVar('SUMMARY:' + pkg, '%s - %s translations' % (summary, l))