'''e.g. python setup.py bdist_apps --cores=1 --nowindows=1'''
-from ya2.utils.log import LogMgrBase
-LogMgrBase.pre_init_logging()
+from ya2.utils.log import LogManagerBase
+LogManagerBase.pre_init_logging()
from os import system
from sys import argv, executable
from subprocess import Popen
from setuptools.command.develop import develop
from multiprocessing import cpu_count
from direct.dist.commands import bdist_apps
-from ya2.build.build import _branch, files, _version
+from p3d_appimage import AppImageBuilder
+from ya2.build.build import _branch, find_file_names, _version, FindFileNamesInfo
from ya2.build.models import ModelsBuilder
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 pmachines.app import Pmachines
-appname = longname = 'pmachines'
+app_name = long_name = 'pmachines'
-message = '''NOTE: please be sure that you've already created the assets with:
+assets_creation_message = '''NOTE: please be sure that you've already created the assets with:
* python setup.py images models lang'''
Popen([executable, __file__, 'models']).communicate()
-class AbstractCommand(Command):
+class BaseCommand(Command):
user_options = [('cores=', None, '#cores')]
cores = cpu_count()
def __process_argument(self, argument):
if argument.startswith('--cores='):
- AbstractCommand.cores = int(argument.split('=')[1])
+ BaseCommand.cores = int(argument.split('=')[1])
def finalize_options(self): # must override
pass
-class ModelsCommand(AbstractCommand):
+class ModelsCommand(BaseCommand):
def run(self):
- ModelsBuilder().build('assets/models', int(AbstractCommand.cores))
+ ModelsBuilder().build('assets/models', int(BaseCommand.cores))
-class ImagesCommand(AbstractCommand):
+class ImagesCommand(BaseCommand):
def run(self):
build_screenshots(Pmachines.scenes)
- images = files(['jpg', 'png'], ['models', 'gltf', 'bam'], ['_png.png'])
- build_images(images, int(AbstractCommand.cores))
+ find_info = FindFileNamesInfo(
+ ['jpg', 'png'],
+ ['models', 'gltf', 'bam'],
+ ['_png.png'])
+ images = find_file_names(find_info)
+ build_images(images, int(BaseCommand.cores))
-class L10nCommand(AbstractCommand):
+class L10nCommand(BaseCommand):
l10n_path = 'assets/locale/'
def run(self):
- LanguageBuilder.build_pot(appname, 'assets/locale/po/')
+ LanguageBuilder.build_pot(app_name, '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)
+ LanguageBuilder.merge(lang_code, 'assets/locale/po/', self.l10n_path, app_name)
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)
+ mo_name = mo_template % (self.l10n_path, lang_code, app_name)
+ LanguageBuilder.build_mo(mo_name, self.l10n_path, app_name)
class BDistAppsCommand(bdist_apps):
self.nowindows, self.nolinux = None, None
def run(self):
- print(message)
+ print(assets_creation_message)
self.__patch_commands_py()
bdist_apps.run(self)
self.__eventually_build_appimage()
def __eventually_build_appimage(self):
if not self.nolinux:
hbranch = {'master': 'alpha', 'rc': 'rc', 'stable': ''}[_branch()]
- AppImageBuilder(self).build(longname, hbranch,
+ AppImageBuilder(self).build(long_name, hbranch,
'https://www.ya2.it/downloads/')
if __name__ == '__main__':
setup(
- name=appname,
+ name=app_name,
version=_version(),
cmdclass={
'develop': SetupDevelopmentCommand,
'log_filename_strftime': True,
'log_filename': '$USER_APPDATA/pmachines/logs/%Y/%B/%d/%H_%M_%S.log',
'plugins': ['pandagl', 'p3openal_audio', 'pandadx9'],
- 'gui_apps': {appname: 'main.py'},
+ 'gui_apps': {app_name: 'main.py'},
'package_data_dirs': {'simplepbr': [('simplepbr/shaders*', '', {})]},
'icons': {
- appname: [
+ app_name: [
'assets/images/icon/icon256.png',
'assets/images/icon/icon128.png',
'assets/images/icon/icon48.png',
return ret_ver
-def files(_extensions, excl_dirs=None, excl_ends_with=None, root_path='.'):
- '''Retrieves filenames in root_path with _extensions, with filters.'''
+class FindFileNamesInfo:
+
+ def __init__(self, extensions, excluding_directories=None,
+ excluding_files_ending_with=None, root_path='.'):
+ self.extensions = extensions
+ self.excluding_directories = excluding_directories
+ self.excluding_files_ending_with = excluding_files_ending_with
+ self.root_path = root_path
+
+
+def find_file_names(find_info):
+ _extensions = find_info.extensions
+ excl_dirs = find_info.excluding_directories
+ excl_ends_with = find_info.excluding_files_ending_with
+ root_path = find_info.root_path
return [join(root, fname)
for root, _, fnames in walk(root_path)
for fname in __files_ext(fnames, _extensions)