Skip to content

Commit

Permalink
Added support for other pre/post events
Browse files Browse the repository at this point in the history
  • Loading branch information
fireundubh committed Jul 3, 2022
1 parent 81e4b4f commit 8b306be
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 3 deletions.
30 changes: 29 additions & 1 deletion pyro/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
import sys

from pyro.Enums.Event import (BuildEvent,
ImportEvent)
ImportEvent,
CompileEvent,
AnonymizeEvent,
PackageEvent,
ZipEvent)
from pyro.BuildFacade import BuildFacade
from pyro.Comparators import startswith
from pyro.PapyrusProject import PapyrusProject
Expand Down Expand Up @@ -145,11 +149,23 @@ def run(self) -> int:
ppj.try_run_event(BuildEvent.PRE)

if build.scripts_count > 0:
if ppj.use_pre_compile_event:
ppj.try_run_event(CompileEvent.PRE)

build.try_compile()

if ppj.use_post_compile_event:
ppj.try_run_event(CompileEvent.POST)

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

build.try_anonymize()

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)
Expand All @@ -158,7 +174,13 @@ def run(self) -> int:

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

build.try_pack()

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)
Expand All @@ -167,7 +189,13 @@ def run(self) -> int:

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

build.try_zip()

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)
Expand Down
8 changes: 8 additions & 0 deletions pyro/Constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ class XmlTagName(Constant):
PAPYRUS_PROJECT: str = 'PapyrusProject'
POST_BUILD_EVENT: str = 'PostBuildEvent'
POST_IMPORT_EVENT: str = 'PostImportEvent'
POST_COMPILE_EVENT: str = 'PostCompileEvent'
POST_ANONYMIZE_EVENT: str = 'PostAnonymizeEvent'
POST_PACKAGE_EVENT: str = 'PostPackageEvent'
POST_ZIP_EVENT: str = 'PostZipEvent'
PRE_BUILD_EVENT: str = 'PreBuildEvent'
PRE_IMPORT_EVENT: str = 'PreImportEvent'
PRE_COMPILE_EVENT: str = 'PreCompileEvent'
PRE_ANONYMIZE_EVENT: str = 'PreAnonymizeEvent'
PRE_PACKAGE_EVENT: str = 'PrePackageEvent'
PRE_ZIP_EVENT: str = 'PreZipEvent'
SCRIPTS: str = 'Scripts'
VARIABLES: str = 'Variables'
ZIP_FILE: str = 'ZipFile'
Expand Down
22 changes: 21 additions & 1 deletion pyro/Enums/Event.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,24 @@ class ImportEvent(Enum):
POST = 1


Event = Union[BuildEvent, ImportEvent]
class CompileEvent(Enum):
PRE = 0
POST = 1


class AnonymizeEvent(Enum):
PRE = 0
POST = 1


class PackageEvent(Enum):
PRE = 0
POST = 1


class ZipEvent(Enum):
PRE = 0
POST = 1


Event = Union[BuildEvent, ImportEvent, CompileEvent, AnonymizeEvent, PackageEvent, ZipEvent]
56 changes: 55 additions & 1 deletion pyro/PapyrusProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@

from pyro.Enums.Event import (Event,
BuildEvent,
ImportEvent)
ImportEvent,
CompileEvent,
AnonymizeEvent,
PackageEvent,
ZipEvent)
from pyro.CommandArguments import CommandArguments
from pyro.Comparators import (endswith,
is_folder_node,
Expand Down Expand Up @@ -45,6 +49,16 @@ class PapyrusProject(ProjectBase):
zip_files_node: etree.ElementBase = None
pre_build_node: etree.ElementBase = None
post_build_node: etree.ElementBase = None
pre_import_node: etree.ElementBase = None
post_import_node: etree.ElementBase = None
pre_compile_node: etree.ElementBase = None
post_compile_node: etree.ElementBase = None
pre_anonymize_node: etree.ElementBase = None
post_anonymize_node: etree.ElementBase = None
pre_package_node: etree.ElementBase = None
post_package_node: etree.ElementBase = None
pre_zip_node: etree.ElementBase = None
post_zip_node: etree.ElementBase = None

remote: RemoteBase = None
remote_schemas: tuple = ('https:', 'http:')
Expand Down Expand Up @@ -132,6 +146,30 @@ def bool_attr(element: etree.Element, attr_name: str) -> bool:
self.post_import_node = self.ppj_root.find(XmlTagName.POST_IMPORT_EVENT)
self.use_post_import_event = bool_attr(self.post_import_node, XmlAttributeName.USE_IN_BUILD)

self.pre_compile_node = self.ppj_root.find(XmlTagName.PRE_COMPILE_EVENT)
self.use_pre_compile_event = bool_attr(self.pre_compile_node, XmlAttributeName.USE_IN_BUILD)

self.post_compile_node = self.ppj_root.find(XmlTagName.POST_COMPILE_EVENT)
self.use_post_compile_event = bool_attr(self.post_compile_node, XmlAttributeName.USE_IN_BUILD)

self.pre_anonymize_node = self.ppj_root.find(XmlTagName.PRE_ANONYMIZE_EVENT)
self.use_pre_anonymize_event = bool_attr(self.pre_anonymize_node, XmlAttributeName.USE_IN_BUILD)

self.post_anonymize_node = self.ppj_root.find(XmlTagName.POST_ANONYMIZE_EVENT)
self.use_post_anonymize_event = bool_attr(self.post_anonymize_node, XmlAttributeName.USE_IN_BUILD)

self.pre_package_node = self.ppj_root.find(XmlTagName.PRE_PACKAGE_EVENT)
self.use_pre_package_event = bool_attr(self.pre_package_node, XmlAttributeName.USE_IN_BUILD)

self.post_package_node = self.ppj_root.find(XmlTagName.POST_PACKAGE_EVENT)
self.use_post_package_event = bool_attr(self.post_package_node, XmlAttributeName.USE_IN_BUILD)

self.pre_zip_node = self.ppj_root.find(XmlTagName.PRE_ZIP_EVENT)
self.use_pre_zip_event = bool_attr(self.pre_zip_node, XmlAttributeName.USE_IN_BUILD)

self.post_zip_node = self.ppj_root.find(XmlTagName.POST_ZIP_EVENT)
self.use_post_zip_event = bool_attr(self.post_zip_node, XmlAttributeName.USE_IN_BUILD)

if self.options.package and self.packages_node is not None:
if not self.options.package_path:
self.options.package_path = self.packages_node.get(XmlAttributeName.OUTPUT)
Expand Down Expand Up @@ -758,5 +796,21 @@ def try_run_event(self, event: Event) -> None:
ProcessManager.run_event(self.pre_build_node, self.project_path)
elif event == BuildEvent.POST:
ProcessManager.run_event(self.post_build_node, self.project_path)
elif event == CompileEvent.PRE:
ProcessManager.run_event(self.pre_compile_node, self.project_path)
elif event == CompileEvent.POST:
ProcessManager.run_event(self.post_compile_node, self.project_path)
elif event == AnonymizeEvent.PRE:
ProcessManager.run_event(self.pre_anonymize_node, self.project_path)
elif event == AnonymizeEvent.POST:
ProcessManager.run_event(self.post_anonymize_node, self.project_path)
elif event == PackageEvent.PRE:
ProcessManager.run_event(self.pre_package_node, self.project_path)
elif event == PackageEvent.POST:
ProcessManager.run_event(self.post_package_node, self.project_path)
elif event == ZipEvent.PRE:
ProcessManager.run_event(self.pre_zip_node, self.project_path)
elif event == ZipEvent.POST:
ProcessManager.run_event(self.post_zip_node, self.project_path)
else:
raise NotImplementedError
8 changes: 8 additions & 0 deletions pyro/PapyrusProject.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@
<xs:element minOccurs="0" name="PostBuildEvent" type="pyro:commandList"/>
<xs:element minOccurs="0" name="PreImportEvent" type="pyro:commandList"/>
<xs:element minOccurs="0" name="PostImportEvent" type="pyro:commandList"/>
<xs:element minOccurs="0" name="PreCompileEvent" type="pyro:commandList"/>
<xs:element minOccurs="0" name="PostCompileEvent" type="pyro:commandList"/>
<xs:element minOccurs="0" name="PreAnonymizeEvent" type="pyro:commandList"/>
<xs:element minOccurs="0" name="PostAnonymizeEvent" type="pyro:commandList"/>
<xs:element minOccurs="0" name="PrePackageEvent" type="pyro:commandList"/>
<xs:element minOccurs="0" name="PostPackageEvent" type="pyro:commandList"/>
<xs:element minOccurs="0" name="PreZipEvent" type="pyro:commandList"/>
<xs:element minOccurs="0" name="PostZipEvent" type="pyro:commandList"/>
</xs:choice>
</xs:sequence>
<xs:attribute name="Game" type="pyro:gameType"/>
Expand Down

0 comments on commit 8b306be

Please sign in to comment.