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 Jun 5, 2021
2 parents d074c1c + 254a631 commit 4f3779f
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
3 changes: 2 additions & 1 deletion build.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, args: argparse.Namespace) -> None:
'--assume-yes-for-downloads',
'--plugin-enable=multiprocessing',
'--show-progress',
'--file-reference-choice=runtime'
'--plugin-enable=pkg-resources'
]

def __setattr__(self, key: str, value: object) -> None:
Expand All @@ -58,6 +58,7 @@ def _clean_dist_folder(self) -> None:
'python38.dll',
'python39.dll',
'_elementpath.pyd',
'_hashlib.pyd',
'_multiprocessing.pyd',
'_psutil_windows.pyd',
'_queue.pyd',
Expand Down
42 changes: 23 additions & 19 deletions pyro/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,20 @@ def __init__(self, parser: argparse.ArgumentParser) -> None:
self.args = self.parser.parse_args()

if self.args.show_help:
self._print_help_and_exit()
self.parser.print_help()
sys.exit(1)

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

if not os.path.isfile(self.args.input_path):
Application.log.error(f'Cannot load nonexistent PPJ at given path: "{self.args.input_path}"')
self._print_help_and_exit()
sys.exit(1)

def _print_help_and_exit(self) -> None:
self.parser.print_help()
sys.exit(1)

def _try_fix_input_path(self, input_path: str) -> str:
@staticmethod
def _try_fix_input_path(input_path: str) -> str:
if not input_path:
Application.log.error('required argument missing: -i INPUT.ppj')
self._print_help_and_exit()
sys.exit(1)

if startswith(input_path, 'file:', ignorecase=True):
full_path = PathHelper.url2pathname(input_path)
Expand All @@ -56,36 +54,42 @@ def _try_fix_input_path(self, input_path: str) -> str:

return input_path

def _validate_project(self, ppj: PapyrusProject) -> None:
@staticmethod
def _validate_project(ppj: PapyrusProject) -> None:
compiler_path = ppj.get_compiler_path()
if not compiler_path or not os.path.exists(compiler_path):
if not compiler_path or not os.path.isfile(compiler_path):
Application.log.error('Cannot proceed without compiler path')
self._print_help_and_exit()
sys.exit(1)

flags_path = ppj.get_flags_path()
if not flags_path:
Application.log.error('Cannot proceed without flags path')
self._print_help_and_exit()
sys.exit(1)

if not ppj.options.game_type:
Application.log.error('Cannot determine game type from arguments or Papyrus Project')
self._print_help_and_exit()
sys.exit(1)

if not ppj.has_imports_node:
Application.log.error('Cannot proceed without imports defined in project')
self._print_help_and_exit()
sys.exit(1)

if not ppj.has_scripts_node and not ppj.has_folders_node:
Application.log.error('Cannot proceed without Scripts or Folders defined in project')
self._print_help_and_exit()
sys.exit(1)

if ppj.options.package and not ppj.has_packages_node:
Application.log.error('Cannot proceed with Package enabled without Packages defined in project')
self._print_help_and_exit()
sys.exit(1)

if ppj.options.zip and not ppj.has_zip_files_node:
Application.log.error('Cannot proceed with Zip enabled without ZipFile defined in project')
self._print_help_and_exit()
sys.exit(1)

if not os.path.isabs(flags_path) and \
not any([os.path.isfile(os.path.join(import_path, flags_path)) for import_path in ppj.import_paths]):
Application.log.error('Cannot proceed without flags file in any import folder')
sys.exit(1)

def run(self) -> int:
"""
Expand All @@ -99,7 +103,7 @@ def run(self) -> int:
sys.exit(0)
elif extension not in ('.ppj', '.pyroproject'):
Application.log.error('Cannot proceed without PPJ file path')
self._print_help_and_exit()
sys.exit(1)

options = ProjectOptions(self.args.__dict__)
ppj = PapyrusProject(options)
Expand Down Expand Up @@ -128,7 +132,7 @@ def run(self) -> int:
# bsarch path is not set until BuildFacade initializes
if ppj.options.package and not os.path.isfile(ppj.options.bsarch_path):
Application.log.error('Cannot proceed with Package enabled without valid BSArch path')
self._print_help_and_exit()
sys.exit(1)

ppj.try_build_event(BuildEvent.PRE)

Expand Down
2 changes: 1 addition & 1 deletion pyro/PapyrusProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ def _get_remote_path(self, node: etree.ElementBase) -> str:
url_hash = hashlib.sha1(node.text.encode()).hexdigest()[:8]
temp_path = os.path.join(self.options.remote_temp_path, url_hash)

if self.options.force_overwrite or not os.path.exists(temp_path):
if self.options.force_overwrite or not os.path.isdir(temp_path):
try:
for message in self.remote.fetch_contents(node.text, temp_path):
if message:
Expand Down
2 changes: 1 addition & 1 deletion pyro/ProcessManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def _format_time(hours: Decimal, minutes: Decimal, seconds: Decimal) -> str:
return f'{hours}h {minutes}m {seconds}s'

@staticmethod
def run_event(event_node: etree.ElementBase, project_path: str):
def run_event(event_node: etree.ElementBase, project_path: str) -> None:
ProcessManager.log.info(event_node.get(XmlAttributeName.DESCRIPTION))

ws: re.Pattern = re.compile('[ \t\n\r]+')
Expand Down
2 changes: 1 addition & 1 deletion pyro/ProjectBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def get_installed_path(self, game_type: str = '') -> str:
sys.exit(1)

# noinspection PyUnboundLocalVariable
if not os.path.exists(reg_value):
if not os.path.isdir(reg_value):
ProjectBase.log.error(f'Installed Path for {game_type} does not exist: {reg_value}')
sys.exit(1)

Expand Down
6 changes: 4 additions & 2 deletions pyro/Remotes/GitHubRemote.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ def download_file(file: tuple) -> Optional[str]:
with open(target_path, mode='wb') as f:
f.write(file_response.read())

return None

def fetch_contents(self, url: str, output_path: str) -> Generator:
"""
Downloads files from URL to output path
Expand Down Expand Up @@ -70,8 +72,8 @@ def fetch_contents(self, url: str, output_path: str) -> Generator:
yield from self.fetch_contents(payload_object['url'], output_path)
continue

# we only care about scripts
if payload_object['type'] != 'file' or (payload_object['type'] == 'file' and not endswith(payload_object['name'], '.psc', ignorecase=True)):
# we only care about scripts and flags files
if not (payload_object['type'] == 'file' and endswith(payload_object['name'], ('.flg', '.psc'), ignorecase=True)):
continue

scripts.append((download_url, target_path))
Expand Down
2 changes: 0 additions & 2 deletions pyro/Remotes/RemoteBase.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,5 +127,3 @@ def fetch_contents(self, url: str, output_path: str) -> Generator:
Downloads files from URL to output path
"""
pass


0 comments on commit 4f3779f

Please sign in to comment.