Normalize imports

This commit is contained in:
2023-10-22 16:12:06 +02:00
parent b9fdd1d2a0
commit 0d529baa8b

26
ulha
View File

@@ -18,16 +18,16 @@ Version: 1.3
Licence: BSD Licence: BSD
""" """
import os import os
import sys
import re import re
import shutil import shutil
from subprocess import call, check_call, CalledProcessError import subprocess
from tempfile import mkdtemp, mkstemp import sys
import tempfile
from extfslib import Archive, parse_args import extfslib
class ULha(Archive): class ULha(extfslib.Archive):
"""Archive handle. Provides interface to MC's extfs subsystem""" """Archive handle. Provides interface to MC's extfs subsystem"""
LINE_PAT = re.compile(b"^((?P<perms>[d-][rswx-]{9})|(\[generic\])|" LINE_PAT = re.compile(b"^((?P<perms>[d-][rswx-]{9})|(\[generic\])|"
@@ -116,7 +116,7 @@ class ULha(Archive):
def run(self, dst): def run(self, dst):
"""Execute file out of archive""" """Execute file out of archive"""
fdesc, tmp_file = mkstemp() fdesc, tmp_file = tempfile.mkstemp()
os.close(fdesc) os.close(fdesc)
result = 0 result = 0
@@ -126,7 +126,7 @@ class ULha(Archive):
os.chmod(tmp_file, int("700", 8)) os.chmod(tmp_file, int("700", 8))
try: try:
result = call([tmp_file]) result = subprocess.call([tmp_file])
finally: finally:
try: try:
os.unlink(tmp_file) os.unlink(tmp_file)
@@ -144,7 +144,7 @@ class ULha(Archive):
If src is empty, create empty directory with dst name.""" If src is empty, create empty directory with dst name."""
current_dir = os.path.abspath(os.curdir) current_dir = os.path.abspath(os.curdir)
tmpdir = mkdtemp() tmpdir = tempfile.mkdtemp()
arch_abspath = os.path.realpath(self._arch) arch_abspath = os.path.realpath(self._arch)
os.chdir(tmpdir) os.chdir(tmpdir)
if src: if src:
@@ -154,10 +154,10 @@ class ULha(Archive):
os.makedirs(dst) os.makedirs(dst)
try: try:
result = check_call([self.ARCHIVER.decode('utf-8'), result = subprocess.check_call([self.ARCHIVER.decode('utf-8'),
self.CMDS["write"].decode('utf-8'), self.CMDS["write"].decode('utf-8'),
arch_abspath, dst]) arch_abspath, dst])
except CalledProcessError: except subprocess.CalledProcessError:
return 1 return 1
finally: finally:
os.chdir(current_dir) os.chdir(current_dir)
@@ -169,9 +169,9 @@ class ULha(Archive):
src = self._get_real_name(src) src = self._get_real_name(src)
fobj = open(dst, "wb") fobj = open(dst, "wb")
try: try:
result = check_call([self.ARCHIVER, self.CMDS['read'], self._arch, result = subprocess.check_call([self.ARCHIVER, self.CMDS['read'], self._arch,
src], stdout=fobj) src], stdout=fobj)
except CalledProcessError: except subprocess.CalledProcessError:
return 1 return 1
finally: finally:
fobj.close() fobj.close()
@@ -179,4 +179,4 @@ class ULha(Archive):
if __name__ == "__main__": if __name__ == "__main__":
sys.exit(parse_args(ULha)) sys.exit(extfslib.parse_args(ULha))