-'''e.g. python setup.py bdist_apps --cores=1 --nowindows=1'''
+'''e.g. python setup.py bdist_apps --cores=1 --no-windows=1'''
from ya2.utils.log import LogManagerBase
from setuptools import setup, Command
from setuptools.command.develop import develop
from multiprocessing import cpu_count
+from textwrap import dedent
from direct.dist.commands import bdist_apps
from p3d_appimage import AppImageBuilder
from ya2.build.build import _branch, find_file_names, _version, FindFileNamesInfo
app_name = long_name = 'pmachines'
-
-assets_creation_message = '''NOTE: please be sure that you've already created the assets with:
- * python setup.py images models lang'''
-
-
class SetupDevelopmentCommand(develop):
def run(self):
class L10nCommand(BaseCommand):
- l10n_path = 'assets/locale/'
-
def run(self):
self.__language_builder = LanguageBuilder(app_name, 'assets/locale/po/', 'assets/locale/')
- self.__language_builder.build_pot()
- for l in ['it_IT']: self.__process_language(l)
-
- def __process_language(self, language_code):
- self.__language_builder.merge(language_code)
- self.__language_builder.build_mo(language_code)
+ self.__language_builder.build()
class BDistAppsCommand(bdist_apps):
user_options = bdist_apps.user_options + [
('cores', None, '#cores'),
- ('nowindows=', None, "don't build for windows"),
- ('nolinux=', None, "don't build for linux")]
+ ('no_windows=', None, "don't build for windows"),
+ ('no_linux=', None, "don't build for linux")]
def initialize_options(self):
- bdist_apps.initialize_options(self)
- self.nowindows, self.nolinux = None, None
+ super().initialize_options()
+ self.no_windows, self.no_linux = None, None
def run(self):
+ assets_creation_message = dedent('''NOTE: please be sure that you've already created the assets with:
+ * python setup.py images models lang''')
print(assets_creation_message)
self.__patch_commands_py()
- bdist_apps.run(self)
+ super().run()
self.__eventually_build_appimage()
def __patch_commands_py(self):
system(command)
def __eventually_build_appimage(self):
- if not self.nolinux:
- hbranch = {'master': 'alpha', 'rc': 'rc', 'stable': ''}[_branch()]
- AppImageBuilder(self).build(long_name, hbranch,
- 'https://www.ya2.it/downloads/')
+ if not self.no_linux:
+ appimage_builder = AppImageBuilder(self)
+ filename_branch = {'master': 'alpha', 'rc': 'rc', 'stable': ''}
+ branch = filename_branch[_branch()]
+ appimage_builder.build(long_name, branch,
+ 'https://www.ya2.it/downloads/')
def platform_list():
platforms = []
- if all('--nowindows' not in a for a in argv):
+ if all('--no-windows' not in a for a in argv):
platforms += ['win_amd64']
- if all('--nolinux' not in a for a in argv):
+ if all('--no-linux' 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):
+ if all('--no-windows' not in a for a in argv):
installers['win_amd64'] = ['nsis']
- if all('--nolinux' not in a for a in argv):
+ if all('--no-linux' not in a for a in argv):
installers['manylinux2010_x86_64'] = []
return installers
'''Tools for l10n.'''
-from os import system, makedirs, remove
-from os.path import exists
+from os import system, makedirs, remove, listdir
+from os.path import exists, isfile, join
from shutil import move, copy
from ya2.build.build import find_file_names, FindFileNamesInfo
self.__po_path = po_path
self.__mo_path = mo_path
- def build_mo(self, language_code):
- '''Builds the mo file in the lng_dir_code directory.'''
- mo_template = '%s%s/LC_MESSAGES/%s.mo'
- mo_name = mo_template % (self.__mo_path, language_code, self.__app_name)
- lng_code = mo_name[len(self.__mo_path):].split('/')[0]
- lng_dir = self.__mo_path + lng_code + '/LC_MESSAGES/'
- cmd = 'msgfmt -o {lng_dir}{appname}.mo assets/locale/po/{lng_code}.po'
- system(cmd.format(lng_dir=lng_dir, appname=self.__app_name, lng_code=lng_code))
+ def build(self):
+ self.__build_pot()
+ po_files = [name for name in listdir(self.__po_path)
+ if isfile(join(self.__po_path, name)) and
+ name.endswith('.po')]
+ language_codes = [f.split('.')[0] for f in po_files]
+ for l in language_codes: self.__process_language(l)
- def build_pot(self):
+ def __build_pot(self):
'''Builds the pot file in the lng_dir_code directory.'''
find_info = FindFileNamesInfo(['py'])
src_files = ' '.join(find_file_names(find_info))
'-o {pot_path}{appname}.pot '
system(cmd_tmpl.format(appname=self.__app_name, pot_path=self.__po_path) + src_files)
- def merge(self, lng_code):
+ def __process_language(self, language_code):
+ self.__merge(language_code)
+ self.__build_mo(language_code)
+
+ def __build_mo(self, language_code):
+ '''Builds the mo file in the lng_dir_code directory.'''
+ mo_template = '%s%s/LC_MESSAGES/%s.mo'
+ mo_name = mo_template % (self.__mo_path, language_code, self.__app_name)
+ lng_code = mo_name[len(self.__mo_path):].split('/')[0]
+ lng_dir = self.__mo_path + lng_code + '/LC_MESSAGES/'
+ cmd = 'msgfmt -o {lng_dir}{appname}.mo assets/locale/po/{lng_code}.po'
+ system(cmd.format(lng_dir=lng_dir, appname=self.__app_name, lng_code=lng_code))
+
+ def __merge(self, lng_code):
'''Merges the new strings with the previous ones.'''
lng_base_dir = self.__prepare(lng_code)
- self.__merge(lng_base_dir, lng_code)
+ self.__do_merge(lng_base_dir, lng_code)
self.__postprocess(lng_code)
def __prepare(self, lng_code):
system(cmd_tmpl.format(line=line, lng_dir=lng_dir, appname=self.__app_name))
move(lng_dir + self.__app_name + 'tmp.po', lng_dir + self.__app_name + '.pot')
- def __merge(self, lng_dir, lng_code):
+ def __do_merge(self, lng_dir, lng_code):
'''Manages the msgmerge's invokation.'''
print('merge', lng_dir)
cmd = 'msgmerge -o {lng_dir}{appname}merge.po ' + \