From: David Shea dshea@redhat.com
os.makedirs added a parameter that takes care of this. --- anaconda | 2 +- pyanaconda/iutil.py | 21 +------------------ pyanaconda/network.py | 3 +-- pyanaconda/packaging/__init__.py | 4 ++-- pyanaconda/users.py | 2 +- tests/pyanaconda_tests/iutil_test.py | 40 ------------------------------------ 6 files changed, 6 insertions(+), 66 deletions(-)
diff --git a/anaconda b/anaconda index 203281c..2f904eb 100755 --- a/anaconda +++ b/anaconda @@ -922,7 +922,7 @@ if __name__ == "__main__": setupEnvironment()
# make sure we have /var/log soon, some programs fail to start without it - iutil.mkdirChain("/var/log") + os.makedirs("/var/log", exist_ok=True)
# Share these with the exit handler, installed later pidfile_path = '/var/run/anaconda.pid' diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py index 7a261a1..e946074 100644 --- a/pyanaconda/iutil.py +++ b/pyanaconda/iutil.py @@ -24,7 +24,6 @@ import os import stat import os.path -import errno import subprocess import unicodedata # Used for ascii_lowercase, ascii_uppercase constants @@ -662,24 +661,6 @@ def getSubdirSize(directory): return dsize return getSubdirSize(directory) // 1024
-## Create a directory path. Don't fail if the directory already exists. -def mkdirChain(directory): - """ - :param dir: The directory path to create - - """ - - try: - os.makedirs(directory, 0o755) - except OSError as e: - try: - if e.errno == errno.EEXIST and stat.S_ISDIR(os.stat(directory).st_mode): - return - except OSError: - pass - - log.error("could not create directory %s: %s", dir, e.strerror) - def get_active_console(dev="console"): '''Find the active console device.
@@ -794,7 +775,7 @@ def dracut_eject(device):
try: if not os.path.exists(DRACUT_SHUTDOWN_EJECT): - mkdirChain(os.path.dirname(DRACUT_SHUTDOWN_EJECT)) + os.makedirs(os.path.dirname(DRACUT_SHUTDOWN_EJECT), exist_ok=True) f = open_with_perm(DRACUT_SHUTDOWN_EJECT, "w", 0o755) f.write("#!/bin/sh\n") f.write("# Created by Anaconda\n") diff --git a/pyanaconda/network.py b/pyanaconda/network.py index 001a15c..fac1bc2 100644 --- a/pyanaconda/network.py +++ b/pyanaconda/network.py @@ -936,8 +936,7 @@ def copyFileToPath(fileName, destPath='', overwrite=False): destfile = os.path.join(destPath, fileName.lstrip('/')) if (os.path.isfile(destfile) and not overwrite): return False - if not os.path.isdir(os.path.dirname(destfile)): - iutil.mkdirChain(os.path.dirname(destfile)) + os.makedirs(os.path.dirname(destfile), exist_ok=True) shutil.copy(fileName, destfile) return True
diff --git a/pyanaconda/packaging/__init__.py b/pyanaconda/packaging/__init__.py index 870d289..0805d37 100644 --- a/pyanaconda/packaging/__init__.py +++ b/pyanaconda/packaging/__init__.py @@ -474,7 +474,7 @@ def _setupNFS(mountpoint, server, path, options): ### def preInstall(self, packages=None, groups=None): """ Perform pre-installation tasks. """ - iutil.mkdirChain(iutil.getSysroot() + "/root") + os.makedirs(iutil.getSysroot() + "/root", exist_ok=True)
self._writeModuleBlacklist()
@@ -490,7 +490,7 @@ def _writeModuleBlacklist(self): if "modprobe.blacklist" not in flags.cmdline: return
- iutil.mkdirChain(iutil.getSysroot() + "/etc/modprobe.d") + os.makedirs(iutil.getSysroot() + "/etc/modprobe.d", exist_ok=True) with open(iutil.getSysroot() + "/etc/modprobe.d/anaconda-blacklist.conf", "w") as f: f.write("# Module blacklists written by anaconda\n") for module in flags.cmdline["modprobe.blacklist"].split(): diff --git a/pyanaconda/users.py b/pyanaconda/users.py index 5eee4fc..2cd876a 100644 --- a/pyanaconda/users.py +++ b/pyanaconda/users.py @@ -315,7 +315,7 @@ def createUser(self, user_name, *args, **kwargs): # libuser expects the parent directory tree to exist. parent_dir = iutil.parent_dir(homedir) if parent_dir: - iutil.mkdirChain(parent_dir) + os.makedirs(parent_dir, exist_ok=True) userEnt.set(libuser.HOMEDIRECTORY, homedir)
if kwargs.get("shell", False): diff --git a/tests/pyanaconda_tests/iutil_test.py b/tests/pyanaconda_tests/iutil_test.py index 9f19455..f7706ac 100644 --- a/tests/pyanaconda_tests/iutil_test.py +++ b/tests/pyanaconda_tests/iutil_test.py @@ -460,46 +460,6 @@ def get_dir_size_test(self): # TODO: mock some dirs and check if their size is # computed correctly
- def mkdir_chain_test(self): - """Test mkdirChain.""" - - # don't fail if directory path already exists - iutil.mkdirChain('/dev/null') - iutil.mkdirChain('/') - iutil.mkdirChain('/tmp') - - # create a path and test it exists - test_folder = "test_mkdir_chain" - test_paths = [ - "foo", - "foo/bar/baz", - u"foo/bar/baz", - "", - "čřščščřščř", - u"čřščščřščř", - "asdasd asdasd", - "! spam" - ] - - # join with the toplevel test folder and the folder for this - # test - test_paths = [os.path.join(ANACONDA_TEST_DIR, test_folder, p) - for p in test_paths] - - def create_return(path): - iutil.mkdirChain(path) - return path - - # create the folders and check that they exist - for p in test_paths: - self.assertTrue(os.path.exists(create_return(p))) - - # try to create them again - all the paths should already exist - # and the mkdirChain function needs to handle that - # without a traceback - for p in test_paths: - iutil.mkdirChain(p) - def get_active_console_test(self): """Test get_active_console."""
From: David Shea dshea@redhat.com
This was only used by anaconda-yum to retry downloads, and package downloads are no longer our job. --- pyanaconda/iutil.py | 14 -------------- 1 file changed, 14 deletions(-)
diff --git a/pyanaconda/iutil.py b/pyanaconda/iutil.py index e946074..a0b41af 100644 --- a/pyanaconda/iutil.py +++ b/pyanaconda/iutil.py @@ -1209,20 +1209,6 @@ def __setattr__(self, attr, value): def copy(self): return DataHolder(**dict.copy(self))
-def xprogressive_delay(): - """ A delay generator, the delay starts short and gets longer - as the internal counter increases. - For example for 10 retries, the delay will increases from - 0.5 to 256 seconds. - - :param int retry_number: retry counter - :returns float: time to wait in seconds - """ - counter = 1 - while True: - yield 0.25*(2**counter) - counter += 1 - def get_platform_groupid(): """ Return a platform group id string
From: David Shea dshea@redhat.com
We haven't cared about this since Fedora 16. --- pyanaconda/bootloader.py | 34 ---------------------------------- 1 file changed, 34 deletions(-)
diff --git a/pyanaconda/bootloader.py b/pyanaconda/bootloader.py index 2aac710..3a0fcf7 100644 --- a/pyanaconda/bootloader.py +++ b/pyanaconda/bootloader.py @@ -24,7 +24,6 @@ import collections import os import re -import struct import blivet from parted import PARTITION_BIOS_GRUB from glob import glob @@ -35,7 +34,6 @@ from blivet.devicelibs import raid from pyanaconda.product import productName from pyanaconda.flags import flags, can_touch_runtime_system -from blivet.errors import StorageError from blivet.fcoe import fcoe import pyanaconda.network from pyanaconda.errors import errorHandler, ERROR_RAISE, ZIPLError @@ -49,38 +47,6 @@ import logging log = logging.getLogger("anaconda")
-def get_boot_block(device, seek_blocks=0): - status = device.status - if not status: - try: - device.setup() - except StorageError: - return "" - block_size = device.partedDevice.sectorSize - fd = iutil.eintr_retry_call(os.open, device.path, os.O_RDONLY) - if seek_blocks: - os.lseek(fd, seek_blocks * block_size, 0) - block = iutil.eintr_retry_call(os.read, fd, 512) - iutil.eintr_ignore(os.close, fd) - if not status: - try: - device.teardown(recursive=True) - except StorageError: - pass - - return block - -def is_windows_boot_block(block): - try: - windows = (len(block) >= 512 and - struct.unpack("H", block[0x1fe: 0x200]) == (0xaa55,)) - except struct.error: - windows = False - return windows - -def has_windows_boot_block(device): - return is_windows_boot_block(get_boot_block(device)) - class serial_opts(object): def __init__(self): self.speed = None
From: David Shea dshea@redhat.com
--- pyanaconda/image.py | 64 ++--------------------------------------------------- 1 file changed, 2 insertions(+), 62 deletions(-)
diff --git a/pyanaconda/image.py b/pyanaconda/image.py index ed65101..05aac1f 100644 --- a/pyanaconda/image.py +++ b/pyanaconda/image.py @@ -19,14 +19,13 @@
from pyanaconda import isys import os, os.path, stat, tempfile -from pyanaconda.constants import ISO_DIR from pyanaconda.iutil import open # pylint: disable=redefined-builtin
-from pyanaconda.errors import errorHandler, ERROR_RAISE, InvalidImageSizeError, MediaMountError, MissingImageError +from pyanaconda.errors import errorHandler, ERROR_RAISE, InvalidImageSizeError, MissingImageError
import blivet.util import blivet.arch -from blivet.errors import FSError, StorageError +from blivet.errors import FSError
import logging log = logging.getLogger("anaconda") @@ -103,61 +102,6 @@ def findFirstIsoImage(path):
return None
-def getMediaId(path): - if os.access("%s/.discinfo" % path, os.R_OK): - f = open("%s/.discinfo" % path) - newStamp = f.readline().strip() - f.close() - - return newStamp - else: - return None - -# This mounts the directory containing the iso images on ISO_DIR. -def mountImageDirectory(method, storage): - # No need to mount it again. - if os.path.ismount(ISO_DIR): - return - - if method.method == "harddrive": - if method.biospart: - log.warning("biospart support is not implemented") - devspec = method.biospart - else: - devspec = method.partition - - # FIXME: teach DeviceTree.resolveDevice about biospart - device = storage.devicetree.resolveDevice(devspec) - - while True: - try: - device.setup() - device.format.setup(mountpoint=ISO_DIR) - except StorageError as e: - log.error("couldn't mount ISO source directory: %s", e) - exn = MediaMountError(str(e), device) - if errorHandler.cb(exn) == ERROR_RAISE: - raise exn - elif method.method.startswith("nfsiso:"): - # XXX what if we mount it on ISO_DIR and then create a symlink - # if there are no isos instead of the remount? - - # mount the specified directory - path = method.dir - if method.dir.endswith(".iso"): - path = os.path.dirname(method.dir) - - url = "%s:%s" % (method.server, path) - - while True: - try: - blivet.util.mount(url, ISO_DIR, fstype="nfs", options=method.options) - except OSError as e: - log.error("couldn't mount ISO source directory: %s", e) - exn = MediaMountError(str(e), device) - if errorHandler.cb(exn) == ERROR_RAISE: - raise exn - def mountImage(isodir, tree): while True: if os.path.isfile(isodir): @@ -227,10 +171,6 @@ def opticalInstallMedia(devicetree): def potentialHdisoSources(devicetree): return filter(lambda d: d.format.exists and d.format.mountable, devicetree.getDevicesByType("partition"))
-def umountImage(tree): - if os.path.ismount(tree): - blivet.util.umount(tree) - def verifyMedia(tree, timestamp=None): if os.access("%s/.discinfo" % tree, os.R_OK): f = open("%s/.discinfo" % tree)
Looks good to me for *master*. Otherwise we need to keep in mind addons that are advised to use our utility functions instead of writing their own.
Added label: ACK.
Added label: master.
Maybe leave mkdirChain but just implement it as a os.makedirs call?
Maybe leave mkdirChain but just implement it as a os.makedirs call?
Sounds good to me.
Closed.
Modified and pushed.
anaconda-patches@lists.fedorahosted.org