def update_fallback(config: CommonConfig): if not is_windows(): return try: # 到这里一般是无法访问github,这时候试试gitee的方案 latest_version = get_version_from_gitee() ui = UpdateInfo() ui.latest_version = latest_version ui.netdisk_link = config.netdisk_link ui.netdisk_passcode = "fzls" ui.update_message = "当前无法访问github,暂时无法获取更新内容,若欲知更新内容,请浏览gitee主页进行查看哦~\n\nhttps://gitee.com/fzls/djc_helper/blob/master/CHANGELOG.MD" try_manaual_update(ui) except Exception as err: logger.error( f"手动检查版本更新失败(这个跟自动更新没有任何关系),大概率是访问不了github和gitee导致的,可自行前往网盘查看是否有更新, 错误为{err}" + color("bold_green") + f"\n(无法理解上面这段话的话,就当没看见这段话,对正常功能没有任何影响)") # 如果一直连不上github,则尝试判断距离上次更新的时间是否已经很长 time_since_last_update = datetime.now() - datetime.strptime( ver_time, "%Y.%m.%d") if time_since_last_update.days >= 7: msg = f"无法访问github确认是否有新版本,而当前版本更新于{ver_time},距今已有{time_since_last_update},很可能已经有新的版本,建议打开目录中的[网盘链接]看看是否有新版本,或者购买自动更新DLC省去手动更新的操作\n\n(如果已购买自动更新DLC,就无视这句话)" logger.info(color("bold_green") + msg) if is_first_run( f"notify_manual_update_if_can_not_connect_github_v{now_version}" ): win32api.MessageBox(0, msg, "更新提示", win32con.MB_ICONINFORMATION) webbrowser.open(config.netdisk_link)
def bigtest(): print "BUILD DATE:", datetime.date.today() sys.stdout.flush() # Build everything: # - using clang and g++ # - release and debug modes for b in ['unstable']: for d in [True, False]: for c in [True, False]: util.buildz3(branch=b, everything=True, clean=True, debug=d, java=True, static=True, jobs=config.NUMJOBS, clang=c) util.testz3py(branch=b, debug=d, clang=c) util.testjavaex(branch=b, debug=d, clang=c) util.testz3ex('cpp_example', branch=b, debug=d, clang=c) util.testz3ex('c_example', branch=b, debug=d, clang=c) util.test_benchmarks_using_latest('regressions/smt2', branch=b, debug=d, clang=c) if d: util.test_benchmarks_using_latest('regressions/smt2-debug', branch=b, debug=d, clang=c) util.test_benchmarks_using_latest('regressions/smt2-extra', branch=b, debug=d, clang=c) util.test_pyscripts_using_latest('regressions/python', branch=b, debug=d, clang=c) if util.is_windows(): util.test_cs_using_latest('regressions/cs', branch=b, debug=d, clang=False) util.buildz3(branch='mcsat', everything=True, clean=True, debug=True, java=False, static=False, jobs=config.NUMJOBS, clang=False) # util.buildz3(branch='tptp', everything=True, clean=True, debug=True, java=False, static=False, jobs=config.NUMJOBS, clang=False) util.test_pyscripts_using_latest('regressions/mcsat', branch='mcsat', debug=True, clang=False) util.test_benchmarks_using_latest('regressions/mcsat_smt2', branch='mcsat', debug=True, clang=False)
def get_host_id(): if not util.does_host_exec_exists(): return None if util.is_windows(): phost_exec = util.WIN_PHOST_EXEC elif util.is_linux(): phost_exec = util.LINUX_PHOST_EXEC else: return None cmd_output = check_output([phost_exec, "print-config"], stderr=subprocess.STDOUT) cmd_output = iter(cmd_output.splitlines()) for line in cmd_output: line = line.decode('UTF-8') m = re.search("source_id: \"([a-fA-F0-9-]+)\"", line) if m != None: return m.group(1) return None
def name_lm_source(api_key, cid, source_id, name): global API_BASE_URL err_msg = "Error naming log source." if util.is_windows(): api_endpoint = "/api/lm/v1/%s/sources/eventlog/%s" % (cid, source_id) post_data = '{"eventlog": { "name": "%s" }}' % (name) elif util.is_linux(): api_endpoint = "/api/lm/v1/%s/sources/syslog/%s" % (cid, source_id) post_data = '{"syslog": { "name": "%s" }}' % (name) url = API_BASE_URL + api_endpoint headers = { "Content-Type": "application/json", "Accept": "application/json", "Authorization": "Basic %s" % (api_key) } result = requests.post(url, data=post_data, headers=headers) if result.status_code != 200: print(err_msg, file=sys.stderr) print(url) raise Exception(err_msg)
def bigtest(): print("BUILD DATE: %s" % datetime.date.today()) sys.stdout.flush() # Build everything: # - using clang and g++ # - release and debug modes os.environ['CXXFLAGS'] = os.getenv('CXXFLAGS', '') + ' -DNO_Z3_DEBUGGER' for b in ['master']: for d in [True, False]: for c in [True, False]: util.buildz3(branch=b, everything=True, clean=True, debug=d, dotnet=True, java=True, static=True, jobs=config.NUMJOBS, clang=c) util.testz3py(branch=b, debug=d, clang=c) util.testjavaex(branch=b, debug=d, clang=c) util.testz3ex('cpp_example', branch=b, debug=d, clang=c) util.testz3ex('c_example', branch=b, debug=d, clang=c) util.test_benchmarks_using_latest('regressions/smt2', branch=b, debug=d, clang=c) if d: util.test_benchmarks_using_latest('regressions/smt2-debug', branch=b, debug=d, clang=c) util.test_benchmarks_using_latest('regressions/smt2-extra', branch=b, debug=d, clang=c) util.test_pyscripts_using_latest('regressions/python', branch=b, debug=d, clang=c) if util.is_windows(): util.test_cs_using_latest('regressions/cs', branch=b, debug=d, clang=False) util.buildz3(branch='mcsat', everything=True, clean=True, debug=True, dotnet=False, java=False, static=False, jobs=config.NUMJOBS, clang=False) # util.buildz3(branch='tptp', everything=True, clean=True, debug=True, java=False, static=False, jobs=config.NUMJOBS, clang=False) util.test_pyscripts_using_latest('regressions/mcsat', branch='mcsat', debug=True, clang=False) util.test_benchmarks_using_latest('regressions/mcsat_smt2', branch='mcsat', debug=True, clang=False)
def get_previewer(): WINDOWS = util.is_windows() previewer = None if False: #WINDOWS: try: import com_oo_preview previewer = com_oo_preview.get_previewer() except ImportError: previewer = None if not previewer: try: import uno_oo_preview previewer = uno_oo_preview.get_previewer() except ImportError: previewer = None def make_preview(filename): try: return previewer.get_preview(filename) except KeyError: return None return make_preview
def __init__(self, logfile): if is_windows(): logfile = unix_to_nt(logfile) folder = os.path.abspath(os.path.join(logfile, os.pardir)) if not os.path.exists(folder): os.mkdir(folder) self.f = open(logfile, 'w+') self.date = datetime.datetime.now()
def smalltest(b="master"): print("BUILD DATE: %s" % datetime.date.today()) sys.stdout.flush() # Build debug and release modes for d in [True, False]: util.buildz3(branch=b, everything=False, clean=True, debug=d, java=False, static=False, jobs=config.NUMJOBS, clang=False) util.testz3py(branch=b, debug=d, clang=False) if d: util.test_benchmarks_using_latest('regressions/smt2-debug', branch=b, debug=d, clang=False) util.test_benchmarks_using_latest('regressions/smt2', branch=b, debug=d, clang=False) util.test_pyscripts_using_latest('regressions/python', branch=b, debug=d, clang=False) # util.test_benchmarks_using_latest('regressions/parameters', branch=b, debug=d, clang=False) # util.test_pyscripts_using_latest('regressions/parameters', branch=b, debug=d, clang=False) if util.is_windows(): util.test_cs_using_latest('regressions/cs', branch=b, debug=d, clang=False)
def main(): print('-' * 40) print('SIMULADOR DE GUERRA MISG 2018') print('-' * 40) file_name = input('Arquivo para ser lido (battle_info/battle_info.json):') if file_name == '': file_name = 'battle_info/battle_info.json' if is_windows(): file_name = unix_to_nt(file_name) try: luck_factor = float(input('Fator de sorte (0): ')) except ValueError: luck_factor = 0 a_units, b_units, game_scenario = parse_battle_info(file_name, luck_factor) gameloop(a_units, b_units, game_scenario)
def fixup_ooo_environ(): """On windows using uno is tricky since it really expects to be run using the version of python shipped with Ooo. Calling this should fix things, but note that you still need to be binary compatible (probably exactly the same version of python). If you want to use a different version of python you will need to rebuild the pyuno module. """ if util.is_windows(): os.environ['PATH'] = os.environ['PATH'] + settings.ooo_environment_PATH url = copy.copy(settings.ooo_environment_URE_BOOTSTRAP) url = url.replace(' ', '%20') url = 'file:///' + url os.environ['URE_BOOTSTRAP'] = url
def smalltest(b="unstable"): print "BUILD DATE:", datetime.date.today() sys.stdout.flush() # Build debug and release modes for d in [True, False]: util.buildz3(branch=b, everything=False, clean=True, debug=d, java=False, static=False, jobs=config.NUMJOBS, clang=False) util.testz3py(branch=b, debug=d, clang=False) if d: util.test_benchmarks_using_latest('regressions/smt2-debug', branch=b, debug=d, clang=False) util.test_benchmarks_using_latest('regressions/smt2', branch=b, debug=d, clang=False) util.test_pyscripts_using_latest('regressions/python', branch=b, debug=d, clang=False) # util.test_benchmarks_using_latest('regressions/parameters', branch=b, debug=d, clang=False) # util.test_pyscripts_using_latest('regressions/parameters', branch=b, debug=d, clang=False) if util.is_windows(): util.test_cs_using_latest('regressions/cs', branch=b, debug=d, clang=False)
def smalltest(b="master"): print("BUILD DATE: %s" % datetime.date.today()) sys.stdout.flush() os.environ['CXXFLAGS'] = os.getenv('CXXFLAGS', '') + ' -DNO_Z3_DEBUGGER' # Build debug and release modes for d in [True, False]: util.buildz3(branch=b, everything=False, clean=True, debug=d, dotnet=False, java=False, static=False, jobs=config.NUMJOBS, clang=False) util.testz3py(branch=b, debug=d, clang=False) if d: util.test_benchmarks_using_latest('regressions/smt2-debug', branch=b, debug=d, clang=False) util.test_benchmarks_using_latest('regressions/smt2', branch=b, debug=d, clang=False) util.test_pyscripts_using_latest('regressions/python', branch=b, debug=d, clang=False) # util.test_benchmarks_using_latest('regressions/parameters', branch=b, debug=d, clang=False) # util.test_pyscripts_using_latest('regressions/parameters', branch=b, debug=d, clang=False) if util.is_windows(): util.test_cs_using_latest('regressions/cs', branch=b, debug=d, clang=False)
def try_manaual_update(ui: UpdateInfo) -> bool: if not is_windows(): logger.info("当前不是在windows下运行,不尝试检查更新") return False if need_update(now_version, ui.latest_version): logger.info( f"当前版本为{now_version},已有最新版本{ui.latest_version},更新内容为{ui.update_message}" ) ask_update = True if platform.system() == "Windows": message = ( f"当前版本为{now_version},已有最新版本{ui.latest_version}. 你需要更新吗?\n" f"{ui.update_message}") res = win32api.MessageBox(0, message, "更新", win32con.MB_OKCANCEL) if res == win32con.IDOK: ask_update = True else: ask_update = False else: # 非windows系统默认更新 ask_update = True if ask_update: if not is_shared_content_blocked(ui.netdisk_link): webbrowser.open(ui.netdisk_link) win32api.MessageBox(0, f"蓝奏云网盘提取码为: {ui.netdisk_passcode}", "蓝奏云网盘提取码", win32con.MB_ICONINFORMATION) else: # 如果分享的网盘链接被系统屏蔽了,写日志并弹窗提示 logger.warning(f"网盘链接={ui.netdisk_link}又被系统干掉了=-=") webbrowser.open("https://github.com/fzls/djc_helper/releases") message = ("分享的网盘地址好像又被系统给抽掉了呢=。=先暂时使用github的release页面下载吧0-0\n" "请稍作等待~ 风之凌殇看到这个报错后会尽快更新网盘链接的呢\n" "届时再启动程序将自动获取到最新的网盘地址呢~") win32api.MessageBox(0, message, "不好啦", win32con.MB_ICONERROR) else: message = "如果想停留在当前版本,不想每次启动都弹出前面这个提醒更新的框框,可以打开配置工具,在【公共配置】/【更新】中取消检查更新即可。" win32api.MessageBox(0, message, "取消启动时自动检查更新方法", win32con.MB_ICONINFORMATION) else: logger.info(f"当前版本{now_version}已是最新版本,无需更新") has_new_version = need_update(now_version, ui.latest_version) return has_new_version
def update_fallback(config: CommonConfig): if not is_windows(): return try: # 到这里一般是无法访问github,这时候试试gitee的方案 latest_version = get_version_from_gitee() ui = UpdateInfo() ui.latest_version = latest_version ui.netdisk_link = config.netdisk_link ui.netdisk_passcode = "fzls" ui.update_message = "当前无法访问github,暂时无法获取更新内容,若欲知更新内容,请浏览gitee主页进行查看哦~\n\nhttps://gitee.com/fzls/djc_helper/blob/master/CHANGELOG.MD" try_manaual_update(ui) except Exception as err: logger.error( f"手动检查版本更新失败(这个跟自动更新没有任何关系),大概率是访问不了github和gitee导致的,可自行前往网盘查看是否有更新, 错误为{err}" + color("bold_green") + "\n(无法理解上面这段话的话,就当没看见这段话,对正常功能没有任何影响)" )
def _build_aar(args): build_settings = _parse_build_settings(args) build_dir = os.path.abspath(args.build_dir) # Setup temp environment for building temp_env = os.environ.copy() temp_env['ANDROID_HOME'] = os.path.abspath(args.android_sdk_path) temp_env['ANDROID_NDK_HOME'] = os.path.abspath(args.android_ndk_path) # Temp dirs to hold building results intermediates_dir = os.path.join(build_dir, 'intermediates') build_config = args.config aar_dir = os.path.join(intermediates_dir, 'aar', build_config) jnilibs_dir = os.path.join(intermediates_dir, 'jnilibs', build_config) base_build_command = [ sys.executable, BUILD_PY, '--config=' + build_config ] + build_settings['build_params'] header_files_path = '' # Build binary for each ABI, one by one for abi in build_settings['build_abis']: abi_build_dir = os.path.join(intermediates_dir, abi) abi_build_command = base_build_command + [ '--android_abi=' + abi, '--build_dir=' + abi_build_dir ] if args.include_ops_by_config is not None: abi_build_command += [ '--include_ops_by_config=' + args.include_ops_by_config ] subprocess.run(abi_build_command, env=temp_env, shell=False, check=True, cwd=REPO_DIR) # create symbolic links for libonnxruntime.so and libonnxruntime4j_jni.so # to jnilibs/[abi] for later compiling the aar package abi_jnilibs_dir = os.path.join(jnilibs_dir, abi) os.makedirs(abi_jnilibs_dir, exist_ok=True) for lib_name in ['libonnxruntime.so', 'libonnxruntime4j_jni.so']: target_lib_name = os.path.join(abi_jnilibs_dir, lib_name) # If the symbolic already exists, delete it first # For some reason, os.path.exists will return false for a symbolic link in Linux, # add double check with os.path.islink if os.path.exists(target_lib_name) or os.path.islink( target_lib_name): os.remove(target_lib_name) os.symlink(os.path.join(abi_build_dir, build_config, lib_name), target_lib_name) # we only need to define the header files path once if not header_files_path: header_files_path = os.path.join(abi_build_dir, build_config, 'android', 'headers') # The directory to publish final AAR aar_publish_dir = os.path.join(build_dir, 'aar_out', build_config) os.makedirs(aar_publish_dir, exist_ok=True) # get the common gradle command args gradle_command = [ 'gradle', '--no-daemon', '-b=build-android.gradle', '-c=settings-android.gradle', '-DjniLibsDir=' + jnilibs_dir, '-DbuildDir=' + aar_dir, '-DheadersDir=' + header_files_path, '-DpublishDir=' + aar_publish_dir, '-DminSdkVer=' + str(build_settings['android_min_sdk_version']), '-DtargetSdkVer=' + str(build_settings['android_target_sdk_version']) ] # If not using shell on Window, will not be able to find gradle in path use_shell = True if is_windows() else False # clean, build, and publish to a local directory subprocess.run(gradle_command + ['clean'], env=temp_env, shell=use_shell, check=True, cwd=JAVA_ROOT) subprocess.run(gradle_command + ['build'], env=temp_env, shell=use_shell, check=True, cwd=JAVA_ROOT) subprocess.run(gradle_command + ['publish'], env=temp_env, shell=use_shell, check=True, cwd=JAVA_ROOT)
def main(): if util.is_mac(): from setuptools import setup setup( app=[WINDOW_APP], options={'py2app': {'dist_dir': util.get_launch_name(), 'iconfile': 'icon.icns'}}, setup_requires=['py2app'], ) elif util.is_windows(): # Windows from setuptools import setup from setuptools.command.install import install import py2exe import py2exe.distutils_buildexe try: import appdirs except ImportError: raise Exception(( "You must have appdirs installed to build the launchers on windows." "Try pip installing them with 'pip install appdirs'")) if '3.5' in sys.version: raise Exception(( "You cannot build the launcher on windows with Python 3.5." "py2exe only supports up to python 3.4. Please install python 3.4 and " "run this script using that installation")) class InstallCommand(py2exe.distutils_buildexe.py2exe): user_options = install.user_options + [ ('variant=', None, 'Specify the variant of the launcher to create'), ] def initialize_options(self): super().initialize_options() self.variant = 'window' def finalize_options(self): super().finalize_options() assert self.variant in ('console', 'window'), "You must specify either window or console as the variant" def run(self): if self.variant == 'window': self.distribution.windows = self.distribution.windows elif self.variant == 'console': self.distribution.console = self.distribution.windows self.distribution.console[0]['script'] = CONSOLE_APP self.distribution.windows = [] else: raise Exception("Unrecognized variant {}".format(self.variant)) super().run() setup( cmdclass={ 'py2exe': InstallCommand, }, windows=[{ "icon_resources": [(1, "icon32x32.ico")], "script" : WINDOW_APP, }], options={'py2exe' : {'dist_dir': util.get_launch_name()}}, zipfile=None, ) else: raise NotImplementedError
def _build_aar(args): build_settings = _parse_build_settings(args) build_dir = os.path.abspath(args.build_dir) # Setup temp environment for building _env = os.environ.copy() _env['ANDROID_HOME'] = os.path.abspath(args.android_sdk_path) _env['ANDROID_NDK_HOME'] = os.path.abspath(args.android_ndk_path) # Temp dirs to hold building results _intermediates_dir = os.path.join(build_dir, 'intermediates') _build_flavor = build_settings['build_flavor'] _aar_dir = os.path.join(_intermediates_dir, 'aar', _build_flavor) _jnilibs_dir = os.path.join(_intermediates_dir, 'jnilibs', _build_flavor) _base_build_command = ['python3', BUILD_PY, '--config=' + _build_flavor ] + build_settings['build_params'] # Build binary for each ABI, one by one for abi in build_settings['build_abis']: _build_dir = os.path.join(_intermediates_dir, abi) _build_command = _base_build_command + [ '--android_abi=' + abi, '--build_dir=' + _build_dir ] if args.include_ops_by_config is not None: _build_command += [ '--include_ops_by_config=' + args.include_ops_by_config ] subprocess.run(_build_command, env=_env, shell=False, check=True, cwd=REPO_DIR) # create symbolic links for libonnxruntime.so and libonnxruntime4j_jni.so # to jnilibs/[abi] for later compiling the aar package _jnilibs_abi_dir = os.path.join(_jnilibs_dir, abi) os.makedirs(_jnilibs_abi_dir, exist_ok=True) for lib_name in ['libonnxruntime.so', 'libonnxruntime4j_jni.so']: _target_lib_name = os.path.join(_jnilibs_abi_dir, lib_name) # If the symbolic already exists, delete it first # For some reason, os.path.exists will return false for a symbolic link in Linux, # add double check with os.path.islink if os.path.exists(_target_lib_name) or os.path.islink( _target_lib_name): os.remove(_target_lib_name) os.symlink(os.path.join(_build_dir, _build_flavor, lib_name), _target_lib_name) # The directory to publish final AAR _aar_publish_dir = os.path.join(build_dir, 'aar_out', _build_flavor) os.makedirs(_aar_publish_dir, exist_ok=True) # get the common gradle command args _gradle_command = [ 'gradle', '--no-daemon', '-b=build-android.gradle', '-c=settings-android.gradle', '-DjniLibsDir=' + _jnilibs_dir, '-DbuildDir=' + _aar_dir, '-DpublishDir=' + _aar_publish_dir, '-DminSdkVer=' + str(build_settings['android_min_sdk_version']), '-DtargetSdkVer=' + str(build_settings['android_target_sdk_version']) ] # If not using shell on Window, will not be able to find gradle in path _shell = True if is_windows() else False # clean, build, and publish to a local directory subprocess.run(_gradle_command + ['clean'], env=_env, shell=_shell, check=True, cwd=JAVA_ROOT) subprocess.run(_gradle_command + ['build'], env=_env, shell=_shell, check=True, cwd=JAVA_ROOT) subprocess.run(_gradle_command + ['publish'], env=_env, shell=_shell, check=True, cwd=JAVA_ROOT)
import webbrowser from datetime import datetime from typing import List, Tuple import requests from config import CommonConfig from dao import UpdateInfo from first_run import is_first_run from log import color, logger from upload_lanzouyun import Uploader from util import (async_message_box, bypass_proxy, is_run_in_github_action, is_windows, try_except, use_proxy) from version import now_version, ver_time if is_windows(): import win32api import win32con def get_update_desc(config: CommonConfig): try: uploader = Uploader() latest_version = uploader.latest_version() if not need_update(now_version, latest_version): return "" return f"最新版本为v{latest_version},请及时更新~" except Exception as e: logger.debug("get_update_desc error", exc_info=e)
import util ooo_base_path = 'c:/Program Files/OpenOffice.org 3/' ooo_python_paths = ['c:/Program Files/OpenOffice.org 3/Basis/program'] ooo_environment_PATH = (';' + ooo_base_path + 'URE/bin;' + ooo_base_path + 'Basis/Program') ooo_environment_URE_BOOTSTRAP = ooo_base_path + 'program/fundamental.ini' ooo_connection_string = ( "uno:socket,host=localhost,port=8100;urp;StarOffice.ComponentContext") lib_wand = ('c:/Program Files/ImageMagick-6.5.5-Q16/CORE_RL_wand.dll' if util.is_windows() else '/usr/lib/libWand.so.10') try: from local_settings import * except ImportError: pass
def setup_sys_path(): #assume that linux distributions get it right. if util.is_windows(): sys.path = sys.path + settings.ooo_python_paths
def run(args, cwd): from util import is_windows, run if is_windows(): args = ["cmd", "/c"] + args run(*args, cwd=cwd)
def parse_battle_info(file_name='battle_info/battle_info.json', luck_factor=0): import json if is_windows(): file_name = unix_to_nt(file_name) a_units = [] b_units = [] team_quantities = [0, 0] game_scenario = GameScenario(luck=luck_factor) army_file = 'troop_info/army.json' navy_file = 'troop_info/navy.json' af_file = 'troop_info/air_force.json' if is_windows(): army_file = unix_to_nt(army_file) navy_file = unix_to_nt(navy_file) af_file = unix_to_nt(af_file) with open(file_name, 'r') as f: data = json.load(f) with open(army_file) as f: army_data = json.load(f) with open(navy_file) as f: navy_data = json.load(f) with open(af_file) as f: air_force_data = json.load(f) if len(data) > 2: raise Exception('Esse programa foi feito para rodar em apenas dois times.') for team_number, item in enumerate(data): team = item['team'] if team == 1: v = a_units else: v = b_units # PARSE ARMY for idx, army_item in enumerate(item['army']): if army_item.get('unit_type') is None: raise Exception('army - classe número ' + str(idx+1) + ' não tem unit_type!') if army_item.get('quantity') is None: raise Exception('army - classe número ' + str(idx+1) + ' não tem quantity!') team_quantities[team_number] += army_item['quantity'] army_type = army_item['unit_type'] if army_data['classes'].get(army_type) is None: raise Exception('Não existe uma classe de exército chamada ' + str(army_type) + '!') batch_size = army_data['classes'][army_type]['batch_size'] batches = army_item['quantity'] // batch_size remaining_batch = army_item['quantity'] % batch_size for i in range(batches): v.append(Unit( team=team, type=army_type, hp=army_data['classes'][army_type]['hp'], ATK=army_data['classes'][army_type]['ATK'], DEF=army_data['classes'][army_type]['DEF'], cannot_attack=set(army_data['classes'][army_type]['cannot_attack']), advantage_against=set(army_data['classes'][army_type]['advantage_against']), game_scenario=game_scenario, prob_hit=army_data['classes'][army_type]['prob_hit'], multiple=batch_size )) if remaining_batch > 0: v.append(Unit( team=team, type=army_type, hp=army_data['classes'][army_type]['hp'], ATK=army_data['classes'][army_type]['ATK'], DEF=army_data['classes'][army_type]['DEF'], cannot_attack=set(army_data['classes'][army_type]['cannot_attack']), advantage_against=set(army_data['classes'][army_type]['advantage_against']), game_scenario=game_scenario, prob_hit=army_data['classes'][army_type]['prob_hit'], multiple=remaining_batch )) # PARSE NAVY for idx, navy_item in enumerate(item['navy']): if navy_item.get('unit_type') is None: raise Exception('navy - classe número ' + str(idx+1) + ' não tem unit_type!') if navy_item.get('quantity') is None: raise Exception('navy - classe número ' + str(idx+1) + ' não tem quantity!') team_quantities[team_number] += navy_item['quantity'] navy_type = navy_item['unit_type'] if navy_data['classes'].get(navy_type) is None: raise Exception('Não existe uma classe de exército chamada ' + str(navy_type) + '!') batch_size = navy_data['classes'][navy_type]['batch_size'] batches = navy_item['quantity'] // batch_size remaining_batch = navy_item['quantity'] % batch_size for i in range(batches): v.append(Unit( team=team, type=navy_type, hp=navy_data['classes'][navy_type]['hp'], ATK=navy_data['classes'][navy_type]['ATK'], DEF=navy_data['classes'][navy_type]['DEF'], cannot_attack=set(navy_data['classes'][navy_type]['cannot_attack']), advantage_against=set(navy_data['classes'][navy_type]['advantage_against']), game_scenario=game_scenario, spot=navy_data['classes'][navy_type]['stealth'], prob_hit=navy_data['classes'][navy_type]['prob_hit'], multiple=batch_size )) if remaining_batch > 0: v.append(Unit( team=team, type=navy_type, hp=navy_data['classes'][navy_type]['hp'], ATK=navy_data['classes'][navy_type]['ATK'], DEF=navy_data['classes'][navy_type]['DEF'], cannot_attack=set(navy_data['classes'][navy_type]['cannot_attack']), advantage_against=set(navy_data['classes'][navy_type]['advantage_against']), game_scenario=game_scenario, spot=navy_data['classes'][navy_type]['stealth'], prob_hit=navy_data['classes'][navy_type]['prob_hit'], multiple=remaining_batch )) # PARSE AIR FORCE for idx, af_item in enumerate(item['air_force']): if af_item.get('unit_type') is None: raise Exception('air_force - classe número ' + str(idx+1) + ' não tem unit_type!') if af_item.get('quantity') is None: raise Exception('air_force - classe número ' + str(idx+1) + ' não tem quantity!') team_quantities[team_number] += af_item['quantity'] af_type = af_item['unit_type'] if air_force_data['classes'].get(af_type) is None: raise Exception('Não existe uma classe de exército chamada ' + str(af_type) + '!') batch_size = air_force_data['classes'][af_type]['batch_size'] batches = af_item['quantity'] // batch_size remaining_batch = af_item['quantity'] % batch_size for i in range(batches): v.append(Unit( team=team, type=af_type, hp=air_force_data['classes'][af_type]['hp'], ATK=air_force_data['classes'][af_type]['ATK'], DEF=air_force_data['classes'][af_type]['DEF'], cannot_attack=set(air_force_data['classes'][af_type]['cannot_attack']), advantage_against=set(air_force_data['classes'][af_type]['advantage_against']), game_scenario=game_scenario, prob_hit=air_force_data['classes'][af_type]['prob_hit'], condition_to_hit=air_force_condition, multiple=batch_size )) if remaining_batch > 0: v.append(Unit( team=team, type=af_type, hp=navy_data['classes'][af_type]['hp'], ATK=navy_data['classes'][af_type]['ATK'], DEF=navy_data['classes'][af_type]['DEF'], cannot_attack=set(air_force_data['classes'][af_type]['cannot_attack']), advantage_against=set(air_force_data['classes'][af_type]['advantage_against']), game_scenario=game_scenario, prob_hit=navy_data['classes'][af_type]['prob_hit'], condition_to_hit=air_force_condition(af_type), multiple=remaining_batch )) game_scenario.set_new_army_size(*team_quantities) return a_units, b_units, game_scenario
def main(): if util.is_mac(): from setuptools import setup setup( app=[WINDOW_APP], options={ 'py2app': { 'dist_dir': util.get_launch_name(), 'iconfile': 'icon.icns' } }, setup_requires=['py2app'], ) elif util.is_windows(): # Windows from setuptools import setup from setuptools.command.install import install import py2exe import py2exe.distutils_buildexe try: import appdirs except ImportError: raise Exception(( "You must have appdirs installed to build the launchers on windows." "Try pip installing them with 'pip install appdirs'")) if '3.5' in sys.version: raise Exception(( "You cannot build the launcher on windows with Python 3.5." "py2exe only supports up to python 3.4. Please install python 3.4 and " "run this script using that installation")) class InstallCommand(py2exe.distutils_buildexe.py2exe): user_options = install.user_options + [ ('variant=', None, 'Specify the variant of the launcher to create'), ] def initialize_options(self): super().initialize_options() self.variant = 'window' def finalize_options(self): super().finalize_options() assert self.variant in ( 'console', 'window' ), "You must specify either window or console as the variant" def run(self): if self.variant == 'window': self.distribution.windows = self.distribution.windows elif self.variant == 'console': self.distribution.console = self.distribution.windows self.distribution.console[0]['script'] = CONSOLE_APP self.distribution.windows = [] else: raise Exception("Unrecognized variant {}".format( self.variant)) super().run() setup( cmdclass={ 'py2exe': InstallCommand, }, windows=[{ "icon_resources": [(1, "icon32x32.ico")], "script": WINDOW_APP, }], options={'py2exe': { 'dist_dir': util.get_launch_name() }}, zipfile=None, ) else: raise NotImplementedError