setup.py 3.36 KB
Newer Older
1 2
#!/usr/bin/env python

3
import os
4 5
import glob
import re
6
import copy
7

8 9
from setuptools import setup
from setuptools.command.build_py import build_py
10

11
from foris import __version__
12 13


14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
BASE_DIR = os.path.dirname(os.path.abspath(__file__))


def merge_po_files():
    from babel.messages.pofile import read_po, write_po
    trans_dirs = glob.glob(os.path.join(BASE_DIR, "foris/locale/*/LC_MESSAGES/"))

    # iterate through translations
    for trans_dir in trans_dirs:
        locale = re.match(r".*\/([a-zA-Z_]+)\/LC_MESSAGES/", trans_dir).group(1)
        foris_path = os.path.join(trans_dir, "foris.po")
        if not os.path.exists(foris_path):
            continue

        # read foris translations
29
        with open(foris_path, "rb") as f:
30 31 32 33 34
            foris_catalog = read_po(f, locale=locale, domain="messages")

        # read tzinfo translations
        tzinfo_path = os.path.join(trans_dir, "tzinfo.po")
        if os.path.exists(tzinfo_path):
35
            with open(tzinfo_path, "rb") as f:
36 37 38 39 40 41 42 43 44
                tzinfo_catalog = read_po(f, locale=locale, domain="messages")
            for msg in tzinfo_catalog:
                # foris messages will be preffered
                if msg.id not in foris_catalog:
                    # append to foris messages
                    foris_catalog[msg.id] = msg

        # write merged catalogs
        target_path = os.path.join(trans_dir, "messages.po")
45
        with open(target_path, "wb") as f:
46 47 48
            write_po(f, foris_catalog, no_location=True)


49 50
class BuildCmd(build_py):
    def run(self):
51 52 53
        # prepare messages.po
        merge_po_files()

54 55
        # compile translation
        from babel.messages import frontend as babel
56 57
        distribution = copy.copy(self.distribution)
        cmd = babel.compile_catalog(distribution)
58
        cmd.directory = os.path.join(os.path.dirname(__file__), "foris", "locale")
59
        cmd.domain = "messages"
60
        cmd.ensure_finalized()
61
        cmd.run()
62

63 64
        # run original build cmd
        build_py.run(self)
65

66

67 68
setup(
    name="Foris",
69
    version=__version__,
70 71
    description="Web administration interface for OpenWrt based on NETCONF",
    author="CZ.NIC, z. s. p. o.",
72
    author_email="stepan.henek@nic.cz",
73
    url="https://gitlab.labs.nic.cz/turris/foris/",
74
    license="GPL-3.0",
75
    install_requires=[
76 77
        "bottle",
        "bottle_i18n",
78 79
        'pbkdf2',
        'flup',
80
        "ubus @ git+https://gitlab.labs.nic.cz/turris/python-ubus.git",
81
        "paho-mqtt",
82 83 84
    ],
    setup_requires=[
        'babel',
85
        'jinja2',
86 87 88 89 90 91 92
    ],
    provides=[
        "foris"
    ],
    packages=[
        "foris",
        "foris.config_handlers",
Štěpán Henek's avatar
Štěpán Henek committed
93
        "foris.config",
94
        "foris.common",
95
        "foris.langs",
96
        "foris.plugins",
97
        "foris.utils",
98 99
        "foris.ubus",
        "foris.middleware",
100
        "foris_plugins",
101 102 103
    ],
    package_data={
        '': [
104
            "LICENSE",
105 106
            "locale/**/LC_MESSAGES/*.mo",
            "templates/**",
107
            "templates/**/*",
108
            "static/css/*.css",
109
            "static/fonts/*",
110
            "static/img/*",
111
            "static/js/*.js",
112
            "static/js/contrib/*",
113
            "utils/*.pickle2",
114 115
        ]
    },
116 117 118
    namespace_packages=[
        'foris_plugins',
    ],
119 120
    cmdclass={
        "build_py": BuildCmd,
121 122 123 124 125 126
    },
    entry_points={
        "console_scripts": [
            "foris = foris.__main__:main",
        ]
    },
127
)