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 Aug 31, 2021
2 parents d97b812 + 8dc3742 commit 8e04a70
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
15 changes: 9 additions & 6 deletions pyro/Application.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ def _try_fix_input_path(input_path: str) -> str:

@staticmethod
def _validate_project_file(ppj: PapyrusProject):
if ppj.imports_node is None:
if ppj.imports_node is None and \
(ppj.scripts_node is not None or ppj.folders_node is not None):
Application.log.error('Cannot proceed without imports defined in project')
sys.exit(1)

Expand Down Expand Up @@ -108,7 +109,7 @@ def run(self) -> int:

self._validate_project_file(ppj)

if ppj.scripts_node or ppj.folders_node or ppj.remote_paths:
if ppj.scripts_node is not None or ppj.folders_node is not None or ppj.remote_paths:
ppj.try_initialize_remotes()

if ppj.use_pre_import_event:
Expand Down Expand Up @@ -161,7 +162,7 @@ def run(self) -> int:
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)
else:
elif ppj.packages_node is not None:
Application.log.info('Cannot create Packages because Package is disabled in project')

if ppj.options.zip:
Expand All @@ -170,15 +171,17 @@ def run(self) -> int:
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)
else:
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.package_data.to_string() if build.package_data.file_count > 0 else 'No files were packaged.')
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.')

Application.log.info(build.zipping_data.to_string() if build.zipping_data.file_count > 0 else 'No files were zipped.')
if ppj.zip_files_node is not None:
Application.log.info(build.zipping_data.to_string() if build.zipping_data.file_count > 0 else 'No files were zipped.')

Application.log.info('DONE!')

Expand Down
14 changes: 6 additions & 8 deletions pyro/Enums/ZipCompression.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
from enum import Enum


class ZipCompression(Enum):
class ZipCompression:
STORE = 0
DEFLATE = 8
MAP = {'STORE': 0, 'DEFLATE': 8}

@classmethod
def _missing_(cls, value):
@staticmethod
def get(value: str) -> int:
try:
return cls[value.upper()]
return ZipCompression.MAP[value.upper()]
except KeyError:
pass

raise ValueError("%r is not a valid %s" % (value, cls.__name__))
raise ValueError("%s is not a valid key" % value.upper())
16 changes: 7 additions & 9 deletions pyro/PackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,11 @@ def create_zip(self) -> None:

self._check_write_permission(file_path)

try:
if self.options.zip_compression in ('store', 'deflate'):
compress_type = ZipCompression[self.options.zip_compression]
else:
compress_type = ZipCompression[zip_node.get(XmlAttributeName.COMPRESSION)]
except KeyError:
compress_type = ZipCompression.STORE
if self.options.zip_compression in ('store', 'deflate'):
compress_type = ZipCompression.get(self.options.zip_compression)
else:
compress_str = zip_node.get(XmlAttributeName.COMPRESSION)
compress_type = ZipCompression.get(compress_str)

root_dir: str = self.ppj._get_path(zip_node.get(XmlAttributeName.ROOT_DIR),
relative_root_path=self.ppj.project_path,
Expand All @@ -340,7 +338,7 @@ def create_zip(self) -> None:
PackageManager.log.info(f'Creating "{attr_file_name}"...')

try:
with zipfile.ZipFile(file_path, mode='w', compression=compress_type.value) as z:
with zipfile.ZipFile(file_path, mode='w', compression=compress_type) as z:
for include_path, attr_path in self._generate_include_paths(zip_node, root_dir, True):
if not attr_path:
if root_dir in include_path:
Expand All @@ -353,7 +351,7 @@ def create_zip(self) -> None:
arcname = attr_file_name if attr_path == os.curdir else os.path.join(attr_path, attr_file_name)

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

self.includes += 1

Expand Down

0 comments on commit 8e04a70

Please sign in to comment.