Skip to content

Commit

Permalink
improve printing, stabilize at 1.0
Browse files Browse the repository at this point in the history
Signed-off-by: Zen <z@pyl.onl>
  • Loading branch information
desultory committed Apr 19, 2024
1 parent c7a3900 commit c30e249
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "pycpio"
version = "0.9.2"
version = "1.0.0"
authors = [
{ name="Desultory", email="dev@pyl.onl" },
]
Expand All @@ -16,7 +16,7 @@ classifiers = [
"License :: OSI Approved :: GNU General Public License v2 (GPLv2)",
"Operating System :: OS Independent",
]
dependencies = ["zenlib >= 1.7.3"]
dependencies = ["zenlib >= 2.0.0"]

[project.scripts]
pycpio = "pycpio.main:main"
Expand Down
4 changes: 3 additions & 1 deletion src/pycpio/cpio/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ def __init__(self, data: bytes, header, *args, **kwargs):
self.data = data if data is not None else b''

def __str__(self):
return f"\n{self.header}\nSHA256: {self.hash}\n{self.__class__.__name__}"
out_str = f"{self.__class__.__name__} {self.header}"
out_str += f"\nSHA256: {self.hash} " if self.hash else " "
return out_str

def __bytes__(self):
""" Convert the data to bytes """
Expand Down
16 changes: 11 additions & 5 deletions src/pycpio/header/cpioheader.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,19 +176,25 @@ def __str__(self):
out_str += "Header:\n" if not hasattr(self, 'name') else f"{self.name}:\n"

for attr in self.structure:
if attr in ['ino', 'mode', 'devmajor', 'devminor',
if attr in ['ino', 'mode', 'devmajor', 'devminor', 'uid', 'gid',
'rdevmajor', 'rdevminor', 'namesize', 'filesize', 'check']:
continue
elif attr == 'nlink':
if int(self.nlink, 16) > 1:
out_str += f" {attr}: {int(self.nlink, 16)}\n"
elif attr == 'magic':
out_str += f" {attr}: {self.magic}\n"
if self.logger.level < 20:
out_str += f" {attr}: {self.magic}\n"
else:
continue
elif attr == 'mtime':
out_str += f" {attr}: {datetime.fromtimestamp(int(self.mtime, 16))}\n"
if self.logger.level < 20:
out_str += f" {attr}: {datetime.fromtimestamp(int(self.mtime, 16))}\n"
else:
continue
else:
out_str += f" {attr}: {int(getattr(self, attr), 16)}\n"
out_str += f" {attr}: {int(getattr(self, attr), 16)}"

out_str += f" Permissions: {print_permissions(self.permissions)}\n"
out_str += f" Permissions: {print_permissions(self.permissions)} {int(self.uid)} {int(self.gid)}"
return out_str

2 changes: 1 addition & 1 deletion src/pycpio/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def main():
{'flags': ['-l', '--list'], 'action': 'store_true', 'help': 'list CPIO contents'},
{'flags': ['-p', '--print'], 'action': 'store_true', 'help': 'print CPIO contents'}]

args, logger = get_args_n_logger(package=__package__, description='PyCPIO', arguments=arguments)
args, logger = get_args_n_logger(package=__package__, description='PyCPIO', arguments=arguments, drop_default=True)
kwargs = get_kwargs_from_args(args, logger=logger)

c = PyCPIO(**kwargs)
Expand Down
2 changes: 1 addition & 1 deletion src/pycpio/masks/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def print_permissions(passed_perms: set, extended=False) -> str:
out += "-"

if permission.name[0].lower() == 'x':
out += " "
out += "-"

return out.rstrip()

0 comments on commit c30e249

Please sign in to comment.