|
1 | | -import os, sys, site |
2 | | -import subprocess |
3 | | -import setuptools |
4 | | - |
5 | | - |
6 | | -requires = [ |
7 | | - 'pywayland', |
8 | | - 'babel', |
9 | | - 'psutil', |
10 | | - 'croniter', |
11 | | - 'PyGObject', |
12 | | - 'packaging', |
13 | | - 'python-xlib' |
14 | | -] |
15 | | - |
16 | | -_ROOT = os.path.abspath(os.path.dirname(__file__)) |
17 | | - |
18 | | -with open(os.path.join(_ROOT, 'README.md')) as f: |
19 | | - long_description = f.read() |
20 | | - |
21 | | - |
22 | | -def __compile_po_files(): |
23 | | - """ |
24 | | - Compile the *.po trainslation files. |
25 | | - """ |
26 | | - localedir = 'safeeyes/config/locale' |
27 | | - po_dirs = [localedir + '/' + l + '/LC_MESSAGES/' |
28 | | - for l in next(os.walk(localedir))[1]] |
29 | | - for po_dir in po_dirs: |
30 | | - po_files = [f |
31 | | - for f in next(os.walk(po_dir))[2] |
32 | | - if os.path.splitext(f)[1] == '.po'] |
33 | | - for po_file in po_files: |
34 | | - filename, _ = os.path.splitext(po_file) |
35 | | - mo_file = filename + '.mo' |
36 | | - msgfmt_cmd = 'msgfmt {} -o {}'.format( |
37 | | - po_dir + po_file, po_dir + mo_file) |
38 | | - subprocess.call(msgfmt_cmd, shell=True) |
39 | | - |
40 | | - |
41 | | -def __data_files(): |
42 | | - """ |
43 | | - Collect the data files. |
44 | | - """ |
45 | | - root_dir = sys.prefix |
46 | | - return [(os.path.join(root_dir, "share/applications"), ["safeeyes/platform/io.github.slgobinath.SafeEyes.desktop"]), |
47 | | - (os.path.join(root_dir, "share/icons/hicolor/24x24/status"), ["safeeyes/platform/icons/hicolor/24x24/status/io.github.slgobinath.SafeEyes-disabled.png", "safeeyes/platform/icons/hicolor/24x24/status/io.github.slgobinath.SafeEyes-enabled.png", "safeeyes/platform/icons/hicolor/24x24/status/io.github.slgobinath.SafeEyes-timer.png"]), |
48 | | - (os.path.join(root_dir, "share/icons/hicolor/24x24/apps"), ["safeeyes/platform/icons/hicolor/24x24/apps/io.github.slgobinath.SafeEyes.png"]), |
49 | | - (os.path.join(root_dir, "share/icons/hicolor/16x16/status"), ["safeeyes/platform/icons/hicolor/16x16/status/io.github.slgobinath.SafeEyes-disabled.png", "safeeyes/platform/icons/hicolor/16x16/status/io.github.slgobinath.SafeEyes-enabled.png", "safeeyes/platform/icons/hicolor/16x16/status/io.github.slgobinath.SafeEyes-timer.png"]), |
50 | | - (os.path.join(root_dir, "share/icons/hicolor/16x16/apps"), ["safeeyes/platform/icons/hicolor/16x16/apps/io.github.slgobinath.SafeEyes.png"]), |
51 | | - (os.path.join(root_dir, "share/icons/hicolor/32x32/status"), ["safeeyes/platform/icons/hicolor/32x32/status/io.github.slgobinath.SafeEyes-disabled.png", "safeeyes/platform/icons/hicolor/32x32/status/io.github.slgobinath.SafeEyes-enabled.png"]), |
52 | | - (os.path.join(root_dir, "share/icons/hicolor/32x32/apps"), ["safeeyes/platform/icons/hicolor/32x32/apps/io.github.slgobinath.SafeEyes.png"]), |
53 | | - (os.path.join(root_dir, "share/icons/hicolor/64x64/apps"), ["safeeyes/platform/icons/hicolor/64x64/apps/io.github.slgobinath.SafeEyes.png"]), |
54 | | - (os.path.join(root_dir, "share/icons/hicolor/128x128/apps"), ["safeeyes/platform/icons/hicolor/128x128/apps/io.github.slgobinath.SafeEyes.png"]), |
55 | | - (os.path.join(root_dir, "share/icons/hicolor/48x48/status"), ["safeeyes/platform/icons/hicolor/48x48/status/io.github.slgobinath.SafeEyes-disabled.png", "safeeyes/platform/icons/hicolor/48x48/status/io.github.slgobinath.SafeEyes-enabled.png"]), |
56 | | - (os.path.join(root_dir, "share/icons/hicolor/48x48/apps"), ["safeeyes/platform/icons/hicolor/48x48/apps/io.github.slgobinath.SafeEyes.png"]),] |
57 | | - |
58 | | - |
59 | | -def __package_files(directory): |
60 | | - """ |
61 | | - Collect the package files. |
62 | | - """ |
63 | | - paths = [] |
64 | | - for (path, _, filenames) in os.walk(directory): |
65 | | - for filename in filenames: |
66 | | - paths.append(os.path.join('..', path, filename)) |
67 | | - return paths |
68 | | - |
69 | | - |
70 | | -def __package_data(): |
71 | | - """ |
72 | | - Return a list of package data. |
73 | | - """ |
74 | | - __compile_po_files() |
75 | | - data = ['glade/*.glade', 'resource/*'] |
76 | | - data.extend(__package_files('safeeyes/config')) |
77 | | - data.extend(__package_files('safeeyes/plugins')) |
78 | | - data.extend(__package_files('safeeyes/platform')) |
79 | | - return data |
80 | | - |
81 | | -setuptools.setup( |
82 | | - name="safeeyes", |
83 | | - version="2.2.3", |
84 | | - description="Protect your eyes from eye strain using this continuous breaks reminder.", |
85 | | - long_description=long_description, |
86 | | - long_description_content_type="text/markdown", |
87 | | - author="Gobinath Loganathan", |
88 | | - |
89 | | - url="https://github.com/slgobinath/SafeEyes", |
90 | | - download_url="https://github.com/slgobinath/SafeEyes/archive/v2.2.3.tar.gz", |
91 | | - packages=setuptools.find_packages(), |
92 | | - package_data={'safeeyes': __package_data()}, |
93 | | - data_files=__data_files(), |
94 | | - install_requires=requires, |
95 | | - entry_points={'console_scripts': ['safeeyes = safeeyes.__main__:main']}, |
96 | | - keywords='linux utility health eye-strain safe-eyes', |
97 | | - classifiers=[ |
98 | | - "Operating System :: POSIX :: Linux", |
99 | | - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", |
100 | | - "Development Status :: 5 - Production/Stable", |
101 | | - "Environment :: X11 Applications :: GTK", |
102 | | - "Intended Audience :: End Users/Desktop", |
103 | | - "Topic :: Utilities"] + [('Programming Language :: Python :: %s' % x) for x in '3 3.5 3.6 3.7 3.8 3.9'.split()] |
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +import os |
| 4 | + |
| 5 | +from pathlib import Path |
| 6 | +from setuptools import Command, setup |
| 7 | +from setuptools.command.build import build as OriginalBuildCommand |
| 8 | + |
| 9 | +class BuildCommand(OriginalBuildCommand): |
| 10 | + sub_commands = [('build_mo', None), *OriginalBuildCommand.sub_commands] |
| 11 | + |
| 12 | + |
| 13 | +class BuildMoSubCommand(Command): |
| 14 | + description = 'Compile .po files into .mo files' |
| 15 | + |
| 16 | + files = None |
| 17 | + |
| 18 | + def initialize_options(self): |
| 19 | + self.files = None |
| 20 | + self.editable_mode = False |
| 21 | + self.build_lib = None |
| 22 | + |
| 23 | + def finalize_options(self): |
| 24 | + self.set_undefined_options("build_py", ("build_lib", "build_lib")) |
| 25 | + |
| 26 | + def run(self): |
| 27 | + files = self._get_files() |
| 28 | + |
| 29 | + for build_file, source_file in files.items(): |
| 30 | + if not self.editable_mode: |
| 31 | + # Parent directory required for msgfmt to work correctly |
| 32 | + Path(build_file).parent.mkdir(parents=True, exist_ok=True) |
| 33 | + self.spawn(['msgfmt', source_file, '-o', build_file]) |
| 34 | + |
| 35 | + def _get_files(self): |
| 36 | + if self.files is not None: |
| 37 | + return self.files |
| 38 | + |
| 39 | + files = {} |
| 40 | + |
| 41 | + localedir = Path('safeeyes/config/locale') |
| 42 | + po_dirs = [l.joinpath('LC_MESSAGES') for l in localedir.iterdir() if l.is_dir()] |
| 43 | + for po_dir in po_dirs: |
| 44 | + po_files = [f |
| 45 | + for f in po_dir.iterdir() |
| 46 | + if f.is_file() and f.suffix == '.po'] |
| 47 | + for po_file in po_files: |
| 48 | + mo_file = po_file.with_suffix(".mo") |
| 49 | + |
| 50 | + source_file = po_file |
| 51 | + build_file = mo_file |
| 52 | + |
| 53 | + if not self.editable_mode: |
| 54 | + build_file = Path(self.build_lib).joinpath(build_file) |
| 55 | + |
| 56 | + files[str(build_file)] = str(source_file) |
| 57 | + |
| 58 | + self.files = files |
| 59 | + return files |
| 60 | + |
| 61 | + def get_output_mapping(self): |
| 62 | + return self._get_files() |
| 63 | + |
| 64 | + def get_outputs(self): |
| 65 | + return self._get_files().keys() |
| 66 | + |
| 67 | + def get_source_files(self): |
| 68 | + return self._get_files().values() |
| 69 | + |
| 70 | + |
| 71 | +setup( |
| 72 | + cmdclass={'build': BuildCommand, 'build_mo': BuildMoSubCommand} |
104 | 73 | ) |
0 commit comments