Skip to content

Commit

Permalink
os_utils.py: a few renames and cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
ilius committed Oct 21, 2023
1 parent 9f889a3 commit d0fc312
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions pyglossary/os_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ def __init__(
create: bool = False,
clear: bool = False,
) -> None:
self.oldpwd: "str | None" = None
self.old_pwd: "str | None" = None
self.dir = directory
self.create = create
self.clear = clear

def __enter__(self) -> None:
self.oldpwd = os.getcwd()
self.old_pwd = os.getcwd()
if os.path.exists(self.dir):
if self.clear:
shutil.rmtree(self.dir)
Expand All @@ -52,9 +52,9 @@ def __exit__(
exc_val: "Exception",
exc_tb: "types.TracebackType",
) -> None:
if self.oldpwd:
os.chdir(self.oldpwd)
self.oldpwd = None
if self.old_pwd:
os.chdir(self.old_pwd)
self.old_pwd = None


def _idzip(filename: Union[str, Path]) -> bool:
Expand All @@ -66,14 +66,15 @@ def _idzip(filename: Union[str, Path]) -> bool:
destination = filename.parent/(filename.name + ".dz")
try:
with open(filename, "rb") as inp_file, open(destination, "wb") as out_file:
inputinfo = os.fstat(inp_file.fileno())
inputInfo = os.fstat(inp_file.fileno())
log.debug("compressing %s to %s with idzip", filename, destination)
idzip.compressor.compress(
inp_file,
inputinfo.st_size,
inputInfo.st_size,
out_file,
filename.name,
int(inputinfo.st_mtime))
int(inputInfo.st_mtime),
)
filename.unlink()
except OSError as error:
log.error(str(error))
Expand Down

0 comments on commit d0fc312

Please sign in to comment.