Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
fireundubh committed Oct 5, 2023
2 parents 794be8e + 39e9617 commit 8cf9bc6
Show file tree
Hide file tree
Showing 14 changed files with 658 additions and 265 deletions.
391 changes: 373 additions & 18 deletions LICENSE

Large diffs are not rendered by default.

31 changes: 19 additions & 12 deletions pyro/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,13 @@ def __init__(self, parser: argparse.ArgumentParser) -> None:
self.parser.print_help()
sys.exit(1)

# set up log levels
log_level_argv = self.args.log_level.upper()
log_level = getattr(logging, log_level_argv, logging.DEBUG)
self.log.setLevel(log_level)

Application.log.debug(f'Set log level to: {log_level_argv}')

self.args.input_path = self._try_fix_input_path(self.args.input_path or self.args.input_path_deprecated)

if not self.args.create_project and not os.path.isfile(self.args.input_path):
Expand Down Expand Up @@ -158,7 +165,7 @@ def run(self) -> int:
ppj.try_run_event(CompileEvent.POST)

if ppj.options.anonymize:
if build.compile_data.failed_count == 0 or ppj.options.ignore_errors:
if build.get_compile_data().failed_count == 0 or ppj.options.ignore_errors:
if ppj.use_pre_anonymize_event:
ppj.try_run_event(AnonymizeEvent.PRE)

Expand All @@ -167,13 +174,13 @@ def run(self) -> int:
if ppj.use_post_anonymize_event:
ppj.try_run_event(AnonymizeEvent.POST)
else:
Application.log.error(f'Cannot anonymize scripts because {build.compile_data.failed_count} scripts failed to compile')
sys.exit(build.compile_data.failed_count)
Application.log.error(f'Cannot anonymize scripts because {build.get_compile_data().failed_count} scripts failed to compile')
sys.exit(build.get_compile_data().failed_count)
else:
Application.log.info('Cannot anonymize scripts because Anonymize is disabled in project')

if ppj.options.package:
if build.compile_data.failed_count == 0 or ppj.options.ignore_errors:
if build.get_compile_data().failed_count == 0 or ppj.options.ignore_errors:
if ppj.use_pre_package_event:
ppj.try_run_event(PackageEvent.PRE)

Expand All @@ -182,13 +189,13 @@ def run(self) -> int:
if ppj.use_post_package_event:
ppj.try_run_event(PackageEvent.POST)
else:
Application.log.error(f'Cannot create Packages because {build.compile_data.failed_count} scripts failed to compile')
sys.exit(build.compile_data.failed_count)
Application.log.error(f'Cannot create Packages because {build.get_compile_data().failed_count} scripts failed to compile')
sys.exit(build.get_compile_data().failed_count)
elif ppj.packages_node is not None:
Application.log.info('Cannot create Packages because Package is disabled in project')

if ppj.options.zip:
if build.compile_data.failed_count == 0 or ppj.options.ignore_errors:
if build.get_compile_data().failed_count == 0 or ppj.options.ignore_errors:
if ppj.use_pre_zip_event:
ppj.try_run_event(ZipEvent.PRE)

Expand All @@ -197,13 +204,13 @@ def run(self) -> int:
if ppj.use_post_zip_event:
ppj.try_run_event(ZipEvent.POST)
else:
Application.log.error(f'Cannot create ZipFile because {build.compile_data.failed_count} scripts failed to compile')
sys.exit(build.compile_data.failed_count)
Application.log.error(f'Cannot create ZipFile because {build.get_compile_data().failed_count} scripts failed to compile')
sys.exit(build.get_compile_data().failed_count)
elif ppj.zip_files_node is not None:
Application.log.info('Cannot create ZipFile because Zip is disabled in project')

if build.scripts_count > 0:
Application.log.info(build.compile_data.to_string() if build.compile_data.success_count > 0 else 'No scripts were compiled.')
Application.log.info(build.get_compile_data().to_string() if build.get_compile_data().success_count > 0 else 'No scripts were compiled.')

if ppj.packages_node is not None:
Application.log.info(build.package_data.to_string() if build.package_data.file_count > 0 else 'No files were packaged.')
Expand All @@ -213,7 +220,7 @@ def run(self) -> int:

Application.log.info('DONE!')

if ppj.use_post_build_event and build.compile_data.failed_count == 0:
if ppj.use_post_build_event and build.get_compile_data().failed_count == 0:
ppj.try_run_event(BuildEvent.POST)

return build.compile_data.failed_count
return build.get_compile_data().failed_count
36 changes: 26 additions & 10 deletions pyro/BuildFacade.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import sys
import time
from typing import Union
from copy import deepcopy

import psutil
Expand All @@ -11,7 +12,8 @@
from pyro.PackageManager import PackageManager
from pyro.PapyrusProject import PapyrusProject
from pyro.PathHelper import PathHelper
from pyro.Performance.CompileData import CompileData
from pyro.Performance.CompileData import (CompileData,
CompileDataCaprica)
from pyro.Performance.PackageData import PackageData
from pyro.Performance.ZippingData import ZippingData
from pyro.PexReader import PexReader
Expand All @@ -28,6 +30,7 @@ class BuildFacade:
ppj: PapyrusProject = None

compile_data: CompileData = CompileData()
compile_data_caprica: CompileData = CompileDataCaprica()
package_data: PackageData = PackageData()
zipping_data: ZippingData = ZippingData()

Expand Down Expand Up @@ -84,30 +87,43 @@ def _limit_priority() -> None:
process = psutil.Process(os.getpid())
process.nice(psutil.BELOW_NORMAL_PRIORITY_CLASS if sys.platform == 'win32' else 19)

def get_compile_data(self) -> Union[CompileData, CompileDataCaprica]:
using_caprica = endswith(self.ppj.get_compiler_path(), 'Caprica.exe', ignorecase=True)
return self.compile_data_caprica if using_caprica else self.compile_data

def try_compile(self) -> None:
"""Builds and passes commands to Papyrus Compiler"""
commands: list = self.ppj.build_commands()
using_caprica = endswith(self.ppj.get_compiler_path(), 'Caprica.exe', ignorecase=True)

compile_data = self.get_compile_data()

self.compile_data.command_count = len(commands)
compile_data.command_count, commands = self.ppj.build_commands()

self.compile_data.time.start_time = time.time()
compile_data.time.start_time = time.time()

if self.ppj.options.no_parallel or self.compile_data.command_count == 1:
if using_caprica or self.ppj.options.no_parallel or compile_data.command_count == 1:
for command in commands:
BuildFacade.log.debug(f'Command: {command}')
if ProcessManager.run_compiler(command) == ProcessState.SUCCESS:
self.compile_data.success_count += 1
elif self.compile_data.command_count > 0:
compile_data.success_count += 1

elif compile_data.command_count > 0:
multiprocessing.freeze_support()
worker_limit = min(self.compile_data.command_count, self.ppj.options.worker_limit)
worker_limit = min(compile_data.command_count, self.ppj.options.worker_limit)
with multiprocessing.Pool(processes=worker_limit,
initializer=BuildFacade._limit_priority) as pool:
for state in pool.imap(ProcessManager.run_compiler, commands):
if state == ProcessState.SUCCESS:
self.compile_data.success_count += 1
compile_data.success_count += 1
pool.close()
pool.join()

self.compile_data.time.end_time = time.time()
compile_data.time.end_time = time.time()

# caprica success = all files compiled
if using_caprica and compile_data.success_count > 0:
compile_data.scripts_count = compile_data.command_count
compile_data.success_count = compile_data.success_count

def try_anonymize(self) -> None:
"""Obfuscates identifying metadata in compiled scripts"""
Expand Down
3 changes: 3 additions & 0 deletions pyro/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@

class FlagsName(Constant):
FO4: str = 'Institute_Papyrus_Flags.flg'
SF1: str = 'Starfield_Papyrus_Flags.flg'
SSE: str = 'TESV_Papyrus_Flags.flg'
TES5: str = 'TESV_Papyrus_Flags.flg'


class GameName(Constant):
FO4: str = 'Fallout 4'
SF1: str = 'Starfield'
SSE: str = 'Skyrim Special Edition'
TES5: str = 'Skyrim'


class GameType(Constant):
FO4: str = 'fo4'
SF1: str = 'sf1'
SSE: str = 'sse'
TES5: str = 'tes5'

Expand Down
6 changes: 3 additions & 3 deletions pyro/PackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def build_commands(self, containing_folder: str, output_path: str) -> str:

flags = wcmatch.RECURSIVE | wcmatch.IGNORECASE

if self.options.game_type == GameType.FO4:
if self.options.game_type == GameType.FO4 or self.options.game_type == GameType.SF1:
for _ in wcmatch.WcMatch(containing_folder, '!*.dds', flags=flags).imatch():
arguments.append('-fo4')
break
Expand Down Expand Up @@ -281,7 +281,7 @@ def create_packages(self) -> None:

adj_relpath = os.path.normpath(os.path.join(attr_path, relpath))

PackageManager.log.info(f'+ "{adj_relpath.casefold()}"')
PackageManager.log.debug(f'+ "{adj_relpath.casefold()}"')

target_path: str = os.path.join(self.options.temp_path, adj_relpath)

Expand Down Expand Up @@ -353,7 +353,7 @@ def create_zip(self) -> None:
_, attr_file_name = os.path.split(include_path)
arcname = attr_file_name if attr_path == os.curdir else os.path.join(attr_path, attr_file_name)

PackageManager.log.info('+ "{}"'.format(arcname))
PackageManager.log.debug('+ "{}"'.format(arcname))
z.write(include_path, arcname, compress_type=compress_type)

self.includes += 1
Expand Down
Loading

0 comments on commit 8cf9bc6

Please sign in to comment.