Commit | Line | Data |
---|---|---|
288c0ffb | 1 | '''e.g. python setup.py bdist_apps --cores=1 --nowindows=1''' |
8ee66edd FC |
2 | |
3 | ||
c991401b FC |
4 | from ya2.utils.log import LogMgrBase |
5 | LogMgrBase.pre_init_logging() | |
6 | from os import system | |
8ee66edd | 7 | from sys import argv, executable |
8ee66edd | 8 | from subprocess import Popen |
5d67a04d | 9 | from setuptools import setup, Command |
8ee66edd | 10 | from setuptools.command.develop import develop |
a747111f | 11 | from multiprocessing import cpu_count |
8ee66edd | 12 | from direct.dist.commands import bdist_apps |
ea71df6e | 13 | from ya2.build.build import _branch, files, _version |
53ddf3c3 | 14 | from ya2.build.models import ModelsBuilder |
288c0ffb FC |
15 | from ya2.build.images import build_images |
16 | from ya2.build.screenshots import build_screenshots | |
53ddf3c3 | 17 | from ya2.build.lang import LanguageBuilder |
8ee66edd | 18 | from p3d_appimage import AppImageBuilder |
aad6ced2 | 19 | from pmachines.app import Pmachines |
8ee66edd FC |
20 | |
21 | ||
22 | appname = longname = 'pmachines' | |
23 | ||
24 | ||
25 | ||
288c0ffb | 26 | message = '''NOTE: please be sure that you've already created the assets with: |
8ee66edd FC |
27 | * python setup.py images models lang''' |
28 | ||
29 | ||
288c0ffb | 30 | class SetupDevelopmentCommand(develop): |
8ee66edd FC |
31 | |
32 | def run(self): | |
8ee66edd FC |
33 | develop.run(self) |
34 | Popen([executable, __file__, 'lang']).communicate() | |
35 | Popen([executable, __file__, 'models']).communicate() | |
36 | ||
37 | ||
288c0ffb | 38 | class AbstractCommand(Command): |
8ee66edd FC |
39 | |
40 | user_options = [('cores=', None, '#cores')] | |
a747111f | 41 | cores = cpu_count() |
8ee66edd FC |
42 | |
43 | def initialize_options(self): | |
288c0ffb FC |
44 | for a in argv[:]: self.__process_argument(a) |
45 | ||
46 | def __process_argument(self, argument): | |
47 | if argument.startswith('--cores='): | |
48 | AbstractCommand.cores = int(argument.split('=')[1]) | |
8ee66edd FC |
49 | |
50 | def finalize_options(self): # must override | |
51 | pass | |
52 | ||
53 | ||
288c0ffb | 54 | class ModelsCommand(AbstractCommand): |
8ee66edd FC |
55 | |
56 | def run(self): | |
288c0ffb | 57 | ModelsBuilder().build('assets/models', int(AbstractCommand.cores)) |
8ee66edd FC |
58 | |
59 | ||
288c0ffb | 60 | class ImagesCommand(AbstractCommand): |
8ee66edd FC |
61 | |
62 | def run(self): | |
288c0ffb FC |
63 | build_screenshots(Pmachines.scenes) |
64 | images = files(['jpg', 'png'], ['models', 'gltf', 'bam'], ['_png.png']) | |
65 | build_images(images, int(AbstractCommand.cores)) | |
8ee66edd FC |
66 | |
67 | ||
288c0ffb | 68 | class L10nCommand(AbstractCommand): |
8ee66edd | 69 | |
288c0ffb | 70 | l10n_path = 'assets/locale/' |
8ee66edd FC |
71 | |
72 | def run(self): | |
288c0ffb FC |
73 | LanguageBuilder.build_pot(appname, 'assets/locale/po/') |
74 | list(map(self.__process_language, ['it_IT'])) | |
75 | ||
76 | def __process_language(self, lang_code): | |
77 | LanguageBuilder.merge(lang_code, 'assets/locale/po/', self.l10n_path, appname) | |
78 | mo_template = '%s%s/LC_MESSAGES/%s.mo' | |
79 | mo_name = mo_template % (self.l10n_path, lang_code, appname) | |
80 | LanguageBuilder.build_mo(mo_name, self.l10n_path, appname) | |
8ee66edd FC |
81 | |
82 | ||
288c0ffb | 83 | class BDistAppsCommand(bdist_apps): |
8ee66edd FC |
84 | |
85 | user_options = bdist_apps.user_options + [ | |
86 | ('cores', None, '#cores'), | |
288c0ffb | 87 | ('nowindows=', None, "don't build for windows"), |
8ee66edd FC |
88 | ('nolinux=', None, "don't build for linux")] |
89 | ||
90 | def initialize_options(self): | |
8ee66edd | 91 | bdist_apps.initialize_options(self) |
288c0ffb | 92 | self.nowindows, self.nolinux = None, None |
8ee66edd FC |
93 | |
94 | def run(self): | |
288c0ffb FC |
95 | print(message) |
96 | self.__patch_commands_py() | |
97 | bdist_apps.run(self) | |
98 | self.__eventually_build_appimage() | |
99 | ||
100 | def __patch_commands_py(self): | |
101 | command = 'patch --forward ' + \ | |
8ee66edd | 102 | '../venv/lib/python3.7/site-packages/direct/dist/commands.py' + \ |
53ddf3c3 | 103 | ' ya2/build/commands.patch' |
288c0ffb FC |
104 | system(command) |
105 | ||
106 | def __eventually_build_appimage(self): | |
8ee66edd | 107 | if not self.nolinux: |
a7f2fc93 | 108 | hbranch = {'master': 'alpha', 'rc': 'rc', 'stable': ''}[_branch()] |
8ee66edd | 109 | AppImageBuilder(self).build(longname, hbranch, |
1ba5e7f0 | 110 | 'https://www.ya2.it/downloads/') |
288c0ffb FC |
111 | |
112 | ||
113 | def platform_list(): | |
114 | platforms = [] | |
115 | if all('--nowindows' not in a for a in argv): | |
116 | platforms += ['win_amd64'] | |
117 | if all('--nolinux' not in a for a in argv): | |
118 | platforms += ['manylinux2010_x86_64'] | |
119 | return platforms | |
120 | ||
121 | ||
122 | def installers_dictionary(): | |
123 | installers = {} | |
124 | if all('--nowindows' not in a for a in argv): | |
125 | installers['win_amd64'] = ['nsis'] | |
126 | if all('--nolinux' not in a for a in argv): | |
127 | installers['manylinux2010_x86_64'] = [] | |
128 | return installers | |
8ee66edd FC |
129 | |
130 | ||
131 | if __name__ == '__main__': | |
8ee66edd FC |
132 | setup( |
133 | name=appname, | |
ea71df6e | 134 | version=_version(), |
8ee66edd | 135 | cmdclass={ |
288c0ffb FC |
136 | 'develop': SetupDevelopmentCommand, |
137 | 'models': ModelsCommand, | |
138 | 'images': ImagesCommand, | |
139 | 'lang': L10nCommand, | |
140 | 'bdist_apps': BDistAppsCommand}, | |
8ee66edd FC |
141 | install_requires=['panda3d'], |
142 | options={ | |
143 | 'build_apps': { | |
144 | 'exclude_patterns': [ | |
145 | 'build/*', 'built/*', 'setup.py', 'requirements.txt', | |
146 | 'venv/*', '.git*', '*.pyc', 'options.ini', '__pycache__', | |
420ce99a | 147 | 'assets/models/gltf/*', 'assets/models/**/*.blend', |
8ee66edd FC |
148 | 'assets/models/**/models/*.png', |
149 | 'assets/models/**/models/*.jpg'], | |
150 | 'log_filename_strftime': True, | |
288c0ffb | 151 | 'log_filename': '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log', |
8ee66edd FC |
152 | 'plugins': ['pandagl', 'p3openal_audio', 'pandadx9'], |
153 | 'gui_apps': {appname: 'main.py'}, | |
288c0ffb | 154 | 'package_data_dirs': {'simplepbr': [('simplepbr/shaders*', '', {})]}, |
94a18c21 FC |
155 | 'icons': { |
156 | appname: [ | |
7e487769 FC |
157 | 'assets/images/icon/icon256.png', |
158 | 'assets/images/icon/icon128.png', | |
159 | 'assets/images/icon/icon48.png', | |
160 | 'assets/images/icon/icon32.png', | |
161 | 'assets/images/icon/icon16.png']}, | |
8ee66edd | 162 | 'include_patterns': [ |
53ddf3c3 | 163 | '**/ya2/licenses/*', |
8ee66edd FC |
164 | '**/licenses/*', |
165 | '**/*.bam', | |
166 | '**/*.dds', | |
167 | '**/*.bin', | |
168 | #'**/*.png', | |
169 | #'**/*.jpg', | |
170 | '**/*.ico', | |
171 | '**/*.json', | |
172 | '**/track_tr.py', | |
173 | '**/*.txt', | |
174 | '**/*.ttf', | |
175 | '**/*.vert', | |
176 | '**/*.frag', | |
177 | '**/*.ogg', | |
178 | '**/*.wav', | |
179 | '**/*.mo'], | |
288c0ffb | 180 | 'platforms': platform_list(), |
8ee66edd | 181 | 'include_modules': {'*': ['encodings.hex_codec']}}, |
288c0ffb | 182 | 'bdist_apps': {'installers': installers_dictionary()}}) |