-'''Setuptools' configuration file
-e.g. python setup.py models --cores=1
-e.g. python setup.py bdist_apps --nowin=1'''
+'''e.g. python setup.py bdist_apps --cores=1 --nowindows=1'''
from ya2.utils.log import LogMgrBase
from multiprocessing import cpu_count
from direct.dist.commands import bdist_apps
from ya2.build.build import _branch, files, _version
-#from ya2.build.docs import bld_docs
from ya2.build.models import ModelsBuilder
-from ya2.build.images import bld_images
-from ya2.build.screenshots import bld_screenshots
+from ya2.build.images import build_images
+from ya2.build.screenshots import build_screenshots
from ya2.build.lang import LanguageBuilder
from p3d_appimage import AppImageBuilder
-#from p3d_flatpak import FlatpakBuilder
from pmachines.app import Pmachines
-msg = '''NOTE: please be sure that you've already created the assets with:
+message = '''NOTE: please be sure that you've already created the assets with:
* python setup.py images models lang'''
-class DevelopPyCmd(develop):
- '''Command for setting up the development.'''
+class SetupDevelopmentCommand(develop):
def run(self):
- '''Prepare the development environment.'''
develop.run(self)
Popen([executable, __file__, 'lang']).communicate()
Popen([executable, __file__, 'models']).communicate()
-class AbsCmd(Command):
- '''Common functionalities for commands.'''
+class AbstractCommand(Command):
user_options = [('cores=', None, '#cores')]
cores = cpu_count()
def initialize_options(self):
- for arg in argv[:]:
- if arg.startswith('--cores='):
- AbsCmd.cores = int(arg.split('=')[1])
+ for a in argv[:]: self.__process_argument(a)
+
+ def __process_argument(self, argument):
+ if argument.startswith('--cores='):
+ AbstractCommand.cores = int(argument.split('=')[1])
def finalize_options(self): # must override
pass
-#class DocsCmd(AbsCmd):
-# '''Command for building the docs.'''
-
-# def run(self):
-# '''Builds the docs.'''
-# bld_docs()
-
-
-class ModelsCmd(AbsCmd):
- '''Command for building the models.'''
+class ModelsCommand(AbstractCommand):
def run(self):
- '''Builds the models.'''
- ModelsBuilder().build('assets/models', int(AbsCmd.cores))
+ ModelsBuilder().build('assets/models', int(AbstractCommand.cores))
-class ImagesCmd(AbsCmd):
- '''Command for building the models.'''
+class ImagesCommand(AbstractCommand):
def run(self):
- '''Builds the images.'''
- bld_screenshots(Pmachines.scenes)
- bld_images(
- files(['jpg', 'png'], ['models', 'gltf', 'bam'], ['_png.png']), int(AbsCmd.cores))
+ build_screenshots(Pmachines.scenes)
+ images = files(['jpg', 'png'], ['models', 'gltf', 'bam'], ['_png.png'])
+ build_images(images, int(AbstractCommand.cores))
-class LangCmd(AbsCmd):
- '''Command for building po, pot and mo files.'''
+class L10nCommand(AbstractCommand):
- lang_path = 'assets/locale/'
-
- def _process_lang(self, lang_code):
- '''Processes a single language.'''
- # poname = 'assets/locale/po/%s.po' % lang_code
- LanguageBuilder.merge(lang_code, 'assets/locale/po/', self.lang_path, appname)
- mo_tmpl = '%s%s/LC_MESSAGES/%s.mo'
- moname = mo_tmpl % (self.lang_path, lang_code, appname)
- LanguageBuilder.mo(moname, self.lang_path, appname)
+ l10n_path = 'assets/locale/'
def run(self):
- '''Builds the language files.'''
- LanguageBuilder.pot(appname, 'assets/locale/po/')
- list(map(self._process_lang, ['it_IT']))
+ LanguageBuilder.build_pot(appname, 'assets/locale/po/')
+ list(map(self.__process_language, ['it_IT']))
+
+ def __process_language(self, lang_code):
+ LanguageBuilder.merge(lang_code, 'assets/locale/po/', self.l10n_path, appname)
+ mo_template = '%s%s/LC_MESSAGES/%s.mo'
+ mo_name = mo_template % (self.l10n_path, lang_code, appname)
+ LanguageBuilder.build_mo(mo_name, self.l10n_path, appname)
-class BDistAppsCmd(bdist_apps):
- '''Customization of BDistApps.'''
+class BDistAppsCommand(bdist_apps):
user_options = bdist_apps.user_options + [
('cores', None, '#cores'),
- ('nowin=', None, "don't build for windows"),
+ ('nowindows=', None, "don't build for windows"),
('nolinux=', None, "don't build for linux")]
def initialize_options(self):
- '''Default values.'''
bdist_apps.initialize_options(self)
- self.nowin, self.nolinux = None, None
-
- #def finalize_options(self): # must override
- # bdist_apps.finalize_options(self)
+ self.nowindows, self.nolinux = None, None
def run(self):
- '''Our bdist_apps' customization.'''
- print(msg)
- cmd = 'patch --forward ' + \
+ print(message)
+ self.__patch_commands_py()
+ bdist_apps.run(self)
+ self.__eventually_build_appimage()
+
+ def __patch_commands_py(self):
+ command = 'patch --forward ' + \
'../venv/lib/python3.7/site-packages/direct/dist/commands.py' + \
' ya2/build/commands.patch'
- system(cmd)
- bdist_apps.run(self)
+ system(command)
+
+ def __eventually_build_appimage(self):
if not self.nolinux:
hbranch = {'master': 'alpha', 'rc': 'rc', 'stable': ''}[_branch()]
AppImageBuilder(self).build(longname, hbranch,
'https://www.ya2.it/downloads/')
- # fbranch = {'master': 'alpha', 'rc': 'rc', 'stable': 'stable'}[_branch()]
- # bld = FlatpakBuilder(
- # self,
- # 'it.ya2.Pmachines',
- # '/home/flavio/builders/pmachines_builder/flatpak',
- # 'D43B6D401912B520B6805FCC8E019E6340E3BAB5',
- # '/home/flavio/builders/pmachines_builder/gpg',
- # 'https://www.ya2.it/flatpak',
- # ['options*.ini'],
- # fbranch,
- # ['assets'])
- # bld.build()
+
+
+def platform_list():
+ platforms = []
+ if all('--nowindows' not in a for a in argv):
+ platforms += ['win_amd64']
+ if all('--nolinux' not in a for a in argv):
+ platforms += ['manylinux2010_x86_64']
+ return platforms
+
+
+def installers_dictionary():
+ installers = {}
+ if all('--nowindows' not in a for a in argv):
+ installers['win_amd64'] = ['nsis']
+ if all('--nolinux' not in a for a in argv):
+ installers['manylinux2010_x86_64'] = []
+ return installers
if __name__ == '__main__':
- platform_lst, installers_dct = [], {}
- if all('--nowin' not in arg for arg in argv):
- platform_lst += ['win_amd64']
- installers_dct['win_amd64'] = ['nsis']
- if all('--nolinux' not in arg for arg in argv):
- platform_lst += ['manylinux2010_x86_64']
- installers_dct['manylinux2010_x86_64'] = []
- log_path = '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log'
- package_data_dirs = {'simplepbr': [('simplepbr/shaders*', '', {})]}
setup(
name=appname,
version=_version(),
cmdclass={
- 'develop': DevelopPyCmd,
- # 'docs': DocsCmd,
- 'models': ModelsCmd,
- 'images': ImagesCmd,
- 'lang': LangCmd,
- 'bdist_apps': BDistAppsCmd},
+ 'develop': SetupDevelopmentCommand,
+ 'models': ModelsCommand,
+ 'images': ImagesCommand,
+ 'lang': L10nCommand,
+ 'bdist_apps': BDistAppsCommand},
install_requires=['panda3d'],
options={
'build_apps': {
'assets/models/**/models/*.png',
'assets/models/**/models/*.jpg'],
'log_filename_strftime': True,
- 'log_filename': log_path,
+ 'log_filename': '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log',
'plugins': ['pandagl', 'p3openal_audio', 'pandadx9'],
'gui_apps': {appname: 'main.py'},
- 'package_data_dirs': package_data_dirs,
- # 'icons': {
- # appname: [
- # 'assets/images/icon/icon256_png.png',
- # 'assets/images/icon/icon128_png.png',
- # 'assets/images/icon/icon48_png.png',
- # 'assets/images/icon/icon32_png.png',
- # 'assets/images/icon/icon16_png.png']},
+ 'package_data_dirs': {'simplepbr': [('simplepbr/shaders*', '', {})]},
'icons': {
appname: [
'assets/images/icon/icon256.png',
'**/*.ogg',
'**/*.wav',
'**/*.mo'],
- 'platforms': platform_lst,
+ 'platforms': platform_list(),
'include_modules': {'*': ['encodings.hex_codec']}},
- 'bdist_apps': {'installers': installers_dct}})
+ 'bdist_apps': {'installers': installers_dictionary()}})