Skip to content

Commit

Permalink
Added prefix to XML attribute variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
fireundubh committed Jun 13, 2021
1 parent ac5f509 commit 5f031e6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 32 deletions.
44 changes: 22 additions & 22 deletions pyro/PackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,27 +201,27 @@ def create_packages(self) -> None:
file_names = CaseInsensitiveList()

for i, package_node in enumerate(filter(is_package_node, self.ppj.packages_node)):
file_name: str = package_node.get(XmlAttributeName.NAME)
attr_file_name: str = package_node.get(XmlAttributeName.NAME)

# noinspection PyProtectedMember
root_dir = self.ppj._get_path(package_node.get(XmlAttributeName.ROOT_DIR),
relative_root_path=self.ppj.project_path,
fallback_path=[self.ppj.project_path, os.path.basename(file_name)])
fallback_path=[self.ppj.project_path, os.path.basename(attr_file_name)])

# prevent clobbering files previously created in this session
if file_name in file_names:
file_name = f'{self.ppj.project_name} ({i})'
if attr_file_name in file_names:
attr_file_name = f'{self.ppj.project_name} ({i})'

if file_name not in file_names:
file_names.append(file_name)
if attr_file_name not in file_names:
file_names.append(attr_file_name)

file_name = self._fix_package_extension(file_name)
attr_file_name = self._fix_package_extension(attr_file_name)

file_path: str = os.path.join(self.options.package_path, file_name)
file_path: str = os.path.join(self.options.package_path, attr_file_name)

self._check_write_permission(file_path)

PackageManager.log.info(f'Creating "{file_name}"...')
PackageManager.log.info(f'Creating "{attr_file_name}"...')

for source_path, _ in self._generate_include_paths(package_node, root_dir):
if os.path.isabs(source_path):
Expand Down Expand Up @@ -257,18 +257,18 @@ def create_zip(self) -> None:
file_names = CaseInsensitiveList()

for i, zip_node in enumerate(filter(is_zipfile_node, self.ppj.zip_files_node)):
file_name: str = zip_node.get(XmlAttributeName.NAME)
attr_file_name: str = zip_node.get(XmlAttributeName.NAME)

# prevent clobbering files previously created in this session
if file_name in file_names:
file_name = f'{file_name} ({i})'
if attr_file_name in file_names:
attr_file_name = f'{attr_file_name} ({i})'

if file_name not in file_names:
file_names.append(file_name)
if attr_file_name not in file_names:
file_names.append(attr_file_name)

file_name = self._fix_zip_extension(file_name)
attr_file_name = self._fix_zip_extension(attr_file_name)

file_path: str = os.path.join(self.options.zip_output_path, file_name)
file_path: str = os.path.join(self.options.zip_output_path, attr_file_name)

self._check_write_permission(file_path)

Expand All @@ -280,11 +280,11 @@ def create_zip(self) -> None:
except KeyError:
compress_type = ZipCompression.STORE

root_dir: str = zip_node.get(XmlAttributeName.ROOT_DIR)
zip_root_path: str = self._try_resolve_project_relative_path(root_dir)
attr_root_dir: str = zip_node.get(XmlAttributeName.ROOT_DIR)
zip_root_path: str = self._try_resolve_project_relative_path(attr_root_dir)

if zip_root_path:
PackageManager.log.info(f'Creating "{file_name}"...')
PackageManager.log.info(f'Creating "{attr_file_name}"...')

try:
with zipfile.ZipFile(file_path, mode='w', compression=compress_type.value) as z:
Expand All @@ -296,8 +296,8 @@ def create_zip(self) -> None:
# just add file to zip root
arcname = os.path.basename(include_path)
else:
_, file_name = os.path.split(include_path)
arcname = file_name if user_path == os.curdir else os.path.join(user_path, file_name)
_, attr_file_name = os.path.split(include_path)
arcname = attr_file_name if user_path == os.curdir else os.path.join(user_path, attr_file_name)

PackageManager.log.info('+ "{}"'.format(arcname))
z.write(include_path, arcname, compress_type=compress_type.value)
Expand All @@ -307,5 +307,5 @@ def create_zip(self) -> None:
PackageManager.log.error(f'Cannot open ZIP file for writing: "{file_path}"')
sys.exit(1)
else:
PackageManager.log.error(f'Cannot resolve RootDir path to existing folder: "{root_dir}"')
PackageManager.log.error(f'Cannot resolve RootDir path to existing folder: "{attr_root_dir}"')
sys.exit(1)
20 changes: 10 additions & 10 deletions pyro/PapyrusProject.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,11 @@ def try_set_game_type(self) -> None:
# we need to set the game type after imports are populated but before pex paths are populated
# allow xml to set game type but defer to passed argument
if self.options.game_type not in GameType.values():
game_type: str = self.ppj_root.get(XmlAttributeName.GAME, default='')
self.options.game_type = GameType.get(game_type)
attr_game_type: str = self.ppj_root.get(XmlAttributeName.GAME, default='')
self.options.game_type = GameType.get(attr_game_type)

if self.options.game_type:
PapyrusProject.log.info(f'Using game type: {GameName.get(game_type)} (determined from Papyrus Project)')
PapyrusProject.log.info(f'Using game type: {GameName.get(attr_game_type)} (determined from Papyrus Project)')

if not self.options.game_type:
self.options.game_type = self.get_game_type()
Expand Down Expand Up @@ -577,11 +577,11 @@ def _get_script_paths_from_folders_node(self) -> typing.Generator:
for folder_node in filter(is_folder_node, self.folders_node):
self.try_fix_namespace_path(folder_node)

no_recurse: bool = folder_node.get(XmlAttributeName.NO_RECURSE) == 'True'
attr_no_recurse: bool = folder_node.get(XmlAttributeName.NO_RECURSE) == 'True'

# try to add project path
if folder_node.text == os.curdir:
yield from PathHelper.find_script_paths_from_folder(self.project_path, no_recurse)
yield from PathHelper.find_script_paths_from_folder(self.project_path, attr_no_recurse)
continue

# handle . and .. in path
Expand All @@ -598,14 +598,14 @@ def _get_script_paths_from_folders_node(self) -> typing.Generator:
PapyrusProject.log.info(f'Adding import path from remote: "{local_path}"...')
self.import_paths.insert(0, local_path)
PapyrusProject.log.info(f'Adding folder path from remote: "{local_path}"...')
yield from PathHelper.find_script_paths_from_folder(local_path, no_recurse)
yield from PathHelper.find_script_paths_from_folder(local_path, attr_no_recurse)
continue

folder_path: str = os.path.normpath(folder_node.text)

# try to add absolute path
if os.path.isabs(folder_path) and os.path.isdir(folder_path):
yield from PathHelper.find_script_paths_from_folder(folder_path, no_recurse)
yield from PathHelper.find_script_paths_from_folder(folder_path, attr_no_recurse)
continue

# try to add project-relative folder path
Expand All @@ -615,21 +615,21 @@ def _get_script_paths_from_folders_node(self) -> typing.Generator:
# this can be a problem if that folder contains sources but user error is hard to fix
test_passed = False

user_flags = wcmatch.RECURSIVE if not no_recurse else 0x0
user_flags = wcmatch.RECURSIVE if not attr_no_recurse else 0x0
matcher = wcmatch.WcMatch(test_path, '*.psc', flags=wcmatch.IGNORECASE | user_flags)
for _ in matcher.imatch():
test_passed = True
break

if test_passed:
yield from PathHelper.find_script_paths_from_folder(test_path, no_recurse, matcher)
yield from PathHelper.find_script_paths_from_folder(test_path, attr_no_recurse, matcher)
continue

# try to add import-relative folder path
for import_path in self.import_paths:
test_path = os.path.join(import_path, folder_path)
if os.path.isdir(test_path):
yield from PathHelper.find_script_paths_from_folder(test_path, no_recurse)
yield from PathHelper.find_script_paths_from_folder(test_path, attr_no_recurse)

# noinspection DuplicatedCode
def _get_script_paths_from_scripts_node(self) -> typing.Generator:
Expand Down

0 comments on commit 5f031e6

Please sign in to comment.