Skip to content

Commit 3a54c84

Browse files
committed
black format writer
Signed-off-by: Zen <[email protected]>
1 parent 2fcbb09 commit 3a54c84

File tree

2 files changed

+26
-16
lines changed

2 files changed

+26
-16
lines changed

src/pycpio/writer/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from .writer import CPIOWriter
22

3-
__all__ = ['CPIOWriter']
3+
__all__ = ["CPIOWriter"]

src/pycpio/writer/writer.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
from zenlib.logging import loggify
2-
from pycpio.header import CPIOHeader, HEADER_NEW
3-
4-
from pathlib import Path
5-
from os import fsync
61
from lzma import CHECK_CRC32
2+
from os import fsync
3+
from pathlib import Path
4+
5+
from pycpio.header import HEADER_NEW, CPIOHeader
6+
from zenlib.logging import loggify
77

88

99
@loggify
@@ -12,7 +12,17 @@ class CPIOWriter:
1212
Takes a list of CPIOData objects, gets their bytes representation, then appends a trailer before writing them to a file.
1313
Compresses the data if compression is specified.
1414
"""
15-
def __init__(self, cpio_entries: list, output_file: Path, structure=None, compression=False, xz_crc=CHECK_CRC32, *args, **kwargs):
15+
16+
def __init__(
17+
self,
18+
cpio_entries: list,
19+
output_file: Path,
20+
structure=None,
21+
compression=False,
22+
xz_crc=CHECK_CRC32,
23+
*args,
24+
**kwargs,
25+
):
1626
self.cpio_entries = cpio_entries
1727
self.output_file = Path(output_file)
1828

@@ -21,34 +31,35 @@ def __init__(self, cpio_entries: list, output_file: Path, structure=None, compre
2131
self.compression = compression or False
2232
if isinstance(compression, str):
2333
compression = compression.lower()
24-
if compression == 'true':
34+
if compression == "true":
2535
compression = True
26-
elif compression == 'false':
36+
elif compression == "false":
2737
compression = False
2838
self.compression = compression
2939

3040
self.xz_crc = xz_crc
3141

3242
def __bytes__(self):
33-
""" Creates a bytes representation of the CPIOData objects. """
43+
"""Creates a bytes representation of the CPIOData objects."""
3444
cpio_bytes = bytes(self.cpio_entries)
3545
trailer = CPIOHeader(structure=self.structure, name="TRAILER!!!", logger=self.logger)
3646
self.logger.debug("Building trailer: %s" % trailer)
3747
cpio_bytes += bytes(trailer)
3848
return cpio_bytes
3949

4050
def compress(self, data):
41-
""" Attempts to compress the data using the specified compression type. """
42-
if self.compression == 'xz' or self.compression is True:
51+
"""Attempts to compress the data using the specified compression type."""
52+
if self.compression == "xz" or self.compression is True:
4353
import lzma
44-
self.logger.info("XZ compressing the CPIO data, original size: %.2f MiB" % (len(data) / (2 ** 20)))
54+
55+
self.logger.info("XZ compressing the CPIO data, original size: %.2f MiB" % (len(data) / (2**20)))
4556
data = lzma.compress(data, check=self.xz_crc)
4657
elif self.compression is not False:
4758
raise NotImplementedError("Compression type not supported: %s" % self.compression)
4859
return data
4960

5061
def write(self, safe_write=True):
51-
""" Writes the CPIOData objects to the output file. """
62+
"""Writes the CPIOData objects to the output file."""
5263
self.logger.debug("Writing to: %s" % self.output_file)
5364
data = self.compress(bytes(self))
5465
with open(self.output_file, "wb") as f:
@@ -60,5 +71,4 @@ def write(self, safe_write=True):
6071
else:
6172
self.logger.warning("File not fsynced, data may not be written to disk: %s" % self.output_file)
6273

63-
self.logger.info("Wrote %.2f MiB to: %s" % (len(data) / (2 ** 20), self.output_file))
64-
74+
self.logger.info("Wrote %.2f MiB to: %s" % (len(data) / (2**20), self.output_file))

0 commit comments

Comments
 (0)