util: Drop dead code

These functions were only used in the legacy pungi.gather module that
has since been removed.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
(cherry picked from commit 8a36744f02040108cbe7e6d590984b3cf8e53b40)
This commit is contained in:
Lubomír Sedlář 2024-11-29 10:42:53 +01:00 committed by Stepan Oksanichenko
parent ac7e1e515e
commit 6a293639cf

View File

@ -19,8 +19,6 @@ import subprocess
import os import os
import shutil import shutil
import string import string
import sys
import hashlib
import errno import errno
import re import re
import contextlib import contextlib
@ -45,132 +43,6 @@ DEBUG_PATTERN_RE = re.compile(
) )
def _doRunCommand(
command,
logger,
rundir="/tmp",
output=subprocess.PIPE,
error=subprocess.PIPE,
env=None,
):
"""Run a command and log the output. Error out if we get something on stderr"""
logger.info("Running %s" % subprocess.list2cmdline(command))
p1 = subprocess.Popen(
command,
cwd=rundir,
stdout=output,
stderr=error,
universal_newlines=True,
env=env,
close_fds=True,
)
(out, err) = p1.communicate()
if out:
logger.debug(out)
if p1.returncode != 0:
logger.error("Got an error from %s" % command[0])
logger.error(err)
raise OSError(
"Got an error (%d) from %s: %s" % (p1.returncode, command[0], err)
)
def _link(local, target, logger, force=False):
"""Simple function to link or copy a package, removing target optionally."""
if os.path.exists(target) and force:
os.remove(target)
# check for broken links
if force and os.path.islink(target):
if not os.path.exists(os.readlink(target)):
os.remove(target)
try:
os.link(local, target)
except OSError as e:
if e.errno != 18: # EXDEV
logger.error("Got an error linking from cache: %s" % e)
raise OSError(e)
# Can't hardlink cross file systems
shutil.copy2(local, target)
def _ensuredir(target, logger, force=False, clean=False):
"""Ensure that a directory exists, if it already exists, only continue
if force is set."""
# We have to check existence of a logger, as setting the logger could
# itself cause an issue.
def whoops(func, path, exc_info):
message = "Could not remove %s" % path
if logger:
logger.error(message)
else:
sys.stderr(message)
sys.exit(1)
if os.path.exists(target) and not os.path.isdir(target):
message = "%s exists but is not a directory." % target
if logger:
logger.error(message)
else:
sys.stderr(message)
sys.exit(1)
if not os.path.isdir(target):
os.makedirs(target)
elif force and clean:
shutil.rmtree(target, onerror=whoops)
os.makedirs(target)
elif force:
return
else:
message = "Directory %s already exists. Use --force to overwrite." % target
if logger:
logger.error(message)
else:
sys.stderr(message)
sys.exit(1)
def _doCheckSum(path, hash, logger):
"""Generate a checksum hash from a provided path.
Return a string of type:hash"""
# Try to figure out what hash we want to do
try:
sum = hashlib.new(hash)
except ValueError:
logger.error("Invalid hash type: %s" % hash)
return False
# Try to open the file, using binary flag.
try:
myfile = open(path, "rb")
except IOError as e:
logger.error("Could not open file %s: %s" % (path, e))
return False
# Loop through the file reading chunks at a time as to not
# put the entire file in memory. That would suck for DVDs
while True:
chunk = myfile.read(
8192
) # magic number! Taking suggestions for better blocksize
if not chunk:
break # we're done with the file
sum.update(chunk)
myfile.close()
return "%s:%s" % (hash, sum.hexdigest())
def makedirs(path, mode=0o775): def makedirs(path, mode=0o775):
try: try:
os.makedirs(path, mode=mode) os.makedirs(path, mode=mode)