collective / i18ndude

i18ndude performs various tasks related to ZPT's, Python Scripts and i18n.
https://pypi.org/project/i18ndude
4 stars 9 forks source link

Expand file globs in command line arguments #82

Open mauritsvanrees opened 4 years ago

mauritsvanrees commented 4 years ago

This command works, because the shell automatically expands the star before passing it to i18ndude:

i18ndude sync --pot locales/plone.pot locales/*/LC_MESSAGES/plone.po

The same command in tox fails, because tox does not do expansion:

$ cat tox.ini
...
[testenv:locales]
basepython = python3
skip_install = true
deps =
    i18ndude
commands =
    i18ndude sync --pot locales/plone.pot locales/*/LC_MESSAGES/plone.po
$ tox -e locales
...
locales run-test: commands[1] | i18ndude sync --pot locales/plone.pot 'locales/*/LC_MESSAGES/plone.po'
Warning: locales/*/LC_MESSAGES/plone.po is not a file or is ignored.

When I replace the star with nl the tox command works fine for the Dutch locale.

See https://stackoverflow.com/a/62113401/621201, also for basic glob code example.

mauritsvanrees commented 2 years ago

I just noticed that since Python 3.5, ** is supported by glob. Trying it out:

$ ls **/*.po
ls: **/*.po: No such file or directory
$ python -i **/*.po
python: can't open file '.../plone/app/locales/**/*.po': [Errno 2] No such file or directory
>>> import glob
>>> import sys
>>> sys.argv
['**/*.po']
>>> glob.glob(sys.argv[0])
[]
>>> glob.glob(sys.argv[0], recursive=True)
['locales/sl/LC_MESSAGES/widgets.po', ... 'locales-addons/es/LC_MESSAGES/plone.app.ldap.po']
>>> len(glob.glob(sys.argv[0], recursive=True))
472

That would mean that you could write the command like this, if we start supporting it:

i18ndude sync --pot locales/plone.pot **/plone.po