Refactor disk tools and fs tools
Signed-off-by: Katarzyna Treder <katarzyna.treder@h-partners.com>
This commit is contained in:
@@ -3,8 +3,6 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
#
|
||||
|
||||
import os
|
||||
|
||||
from test_utils.filesystem.file import File
|
||||
|
||||
|
||||
|
@@ -8,7 +8,7 @@ from string import Template
|
||||
from pathlib import Path
|
||||
|
||||
from test_tools.systemctl import enable_service, reload_daemon, systemd_service_directory
|
||||
from test_tools.fs_utils import (
|
||||
from test_tools.fs_tools import (
|
||||
create_file,
|
||||
write_file,
|
||||
remove,
|
||||
|
@@ -3,8 +3,8 @@
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
#
|
||||
from core.test_run import TestRun
|
||||
from test_tools import fs_utils
|
||||
from test_tools.fs_utils import check_if_directory_exists
|
||||
from test_tools import fs_tools
|
||||
from test_tools.fs_tools import check_if_directory_exists
|
||||
from test_utils.filesystem.fs_item import FsItem
|
||||
|
||||
|
||||
@@ -13,14 +13,14 @@ class Directory(FsItem):
|
||||
FsItem.__init__(self, full_path)
|
||||
|
||||
def ls(self):
|
||||
output = fs_utils.ls(f"{self.full_path}")
|
||||
return fs_utils.parse_ls_output(output, self.full_path)
|
||||
output = fs_tools.ls(f"{self.full_path}")
|
||||
return fs_tools.parse_ls_output(output, self.full_path)
|
||||
|
||||
@staticmethod
|
||||
def create_directory(path: str, parents: bool = False):
|
||||
fs_utils.create_directory(path, parents)
|
||||
output = fs_utils.ls_item(path)
|
||||
return fs_utils.parse_ls_output(output)[0]
|
||||
fs_tools.create_directory(path, parents)
|
||||
output = fs_tools.ls_item(path)
|
||||
return fs_tools.parse_ls_output(output)[0]
|
||||
|
||||
@staticmethod
|
||||
def create_temp_directory(parent_dir_path: str = "/tmp"):
|
||||
|
@@ -5,7 +5,7 @@
|
||||
#
|
||||
from datetime import timedelta
|
||||
|
||||
from test_tools import fs_utils
|
||||
from test_tools import fs_tools
|
||||
from test_tools.dd import Dd
|
||||
from test_utils.filesystem.fs_item import FsItem
|
||||
from type_def.size import Size
|
||||
@@ -16,22 +16,22 @@ class File(FsItem):
|
||||
FsItem.__init__(self, full_path)
|
||||
|
||||
def compare(self, other_file, timeout: timedelta = timedelta(minutes=30)):
|
||||
return fs_utils.compare(str(self), str(other_file), timeout)
|
||||
return fs_tools.compare(str(self), str(other_file), timeout)
|
||||
|
||||
def diff(self, other_file, timeout: timedelta = timedelta(minutes=30)):
|
||||
return fs_utils.diff(str(self), str(other_file), timeout)
|
||||
return fs_tools.diff(str(self), str(other_file), timeout)
|
||||
|
||||
def md5sum(self, binary=True, timeout: timedelta = timedelta(minutes=30)):
|
||||
return fs_utils.md5sum(str(self), binary, timeout)
|
||||
return fs_tools.md5sum(str(self), binary, timeout)
|
||||
|
||||
def crc32sum(self, timeout: timedelta = timedelta(minutes=30)):
|
||||
return fs_utils.crc32sum(str(self), timeout)
|
||||
return fs_tools.crc32sum(str(self), timeout)
|
||||
|
||||
def read(self):
|
||||
return fs_utils.read_file(str(self))
|
||||
return fs_tools.read_file(str(self))
|
||||
|
||||
def write(self, content, overwrite: bool = True):
|
||||
fs_utils.write_file(str(self), content, overwrite)
|
||||
fs_tools.write_file(str(self), content, overwrite)
|
||||
self.refresh_item()
|
||||
|
||||
def get_properties(self):
|
||||
@@ -39,9 +39,9 @@ class File(FsItem):
|
||||
|
||||
@staticmethod
|
||||
def create_file(path: str):
|
||||
fs_utils.create_file(path)
|
||||
output = fs_utils.ls_item(path)
|
||||
return fs_utils.parse_ls_output(output)[0]
|
||||
fs_tools.create_file(path)
|
||||
output = fs_tools.ls_item(path)
|
||||
return fs_tools.parse_ls_output(output)[0]
|
||||
|
||||
def padding(self, size: Size):
|
||||
dd = Dd().input("/dev/zero").output(self).count(1).block_size(size)
|
||||
@@ -49,7 +49,7 @@ class File(FsItem):
|
||||
self.refresh_item()
|
||||
|
||||
def remove(self, force: bool = False, ignore_errors: bool = False):
|
||||
fs_utils.remove(str(self), force=force, ignore_errors=ignore_errors)
|
||||
fs_tools.remove(str(self), force=force, ignore_errors=ignore_errors)
|
||||
|
||||
def copy(self,
|
||||
destination,
|
||||
@@ -57,18 +57,18 @@ class File(FsItem):
|
||||
recursive: bool = False,
|
||||
dereference: bool = False,
|
||||
timeout: timedelta = timedelta(minutes=30)):
|
||||
fs_utils.copy(str(self), destination, force, recursive, dereference, timeout)
|
||||
if fs_utils.check_if_directory_exists(destination):
|
||||
fs_tools.copy(str(self), destination, force, recursive, dereference, timeout)
|
||||
if fs_tools.check_if_directory_exists(destination):
|
||||
path = f"{destination}{'/' if destination[-1] != '/' else ''}{self.name}"
|
||||
else:
|
||||
path = destination
|
||||
output = fs_utils.ls_item(path)
|
||||
return fs_utils.parse_ls_output(output)[0]
|
||||
output = fs_tools.ls_item(path)
|
||||
return fs_tools.parse_ls_output(output)[0]
|
||||
|
||||
|
||||
class FileProperties:
|
||||
def __init__(self, file):
|
||||
file = fs_utils.parse_ls_output(fs_utils.ls_item(file.full_path))[0]
|
||||
file = fs_tools.parse_ls_output(fs_tools.ls_item(file.full_path))[0]
|
||||
self.full_path = file.full_path
|
||||
self.parent_dir = FsItem.get_parent_dir(self.full_path)
|
||||
self.name = FsItem.get_name(self.full_path)
|
||||
|
@@ -5,7 +5,7 @@
|
||||
|
||||
import posixpath
|
||||
|
||||
from test_tools import fs_utils
|
||||
from test_tools import fs_tools
|
||||
|
||||
|
||||
class FsItem:
|
||||
@@ -38,19 +38,19 @@ class FsItem:
|
||||
return self.full_path
|
||||
|
||||
def chmod_numerical(self, permissions: int, recursive: bool = False):
|
||||
fs_utils.chmod_numerical(self.full_path, permissions, recursive)
|
||||
fs_tools.chmod_numerical(self.full_path, permissions, recursive)
|
||||
self.refresh_item()
|
||||
|
||||
def chmod(self,
|
||||
permissions: fs_utils.Permissions,
|
||||
users: fs_utils.PermissionsUsers,
|
||||
sign: fs_utils.PermissionSign = fs_utils.PermissionSign.set,
|
||||
permissions: fs_tools.Permissions,
|
||||
users: fs_tools.PermissionsUsers,
|
||||
sign: fs_tools.PermissionSign = fs_tools.PermissionSign.set,
|
||||
recursive: bool = False):
|
||||
fs_utils.chmod(self.full_path, permissions, users, sign=sign, recursive=recursive)
|
||||
fs_tools.chmod(self.full_path, permissions, users, sign=sign, recursive=recursive)
|
||||
self.refresh_item()
|
||||
|
||||
def chown(self, owner, group, recursive: bool = False):
|
||||
fs_utils.chown(self.full_path, owner, group, recursive)
|
||||
fs_tools.chown(self.full_path, owner, group, recursive)
|
||||
self.refresh_item()
|
||||
|
||||
def copy(self,
|
||||
@@ -58,20 +58,20 @@ class FsItem:
|
||||
force: bool = False,
|
||||
recursive: bool = False,
|
||||
dereference: bool = False):
|
||||
target_dir_exists = fs_utils.check_if_directory_exists(destination)
|
||||
fs_utils.copy(str(self), destination, force, recursive, dereference)
|
||||
target_dir_exists = fs_tools.check_if_directory_exists(destination)
|
||||
fs_tools.copy(str(self), destination, force, recursive, dereference)
|
||||
if target_dir_exists:
|
||||
path = f"{destination}{'/' if destination[-1] != '/' else ''}{self.name}"
|
||||
else:
|
||||
path = destination
|
||||
output = fs_utils.ls_item(f"{path}")
|
||||
return fs_utils.parse_ls_output(output)[0]
|
||||
output = fs_tools.ls_item(f"{path}")
|
||||
return fs_tools.parse_ls_output(output)[0]
|
||||
|
||||
def move(self,
|
||||
destination,
|
||||
force: bool = False):
|
||||
target_dir_exists = fs_utils.check_if_directory_exists(destination)
|
||||
fs_utils.move(str(self), destination, force)
|
||||
target_dir_exists = fs_tools.check_if_directory_exists(destination)
|
||||
fs_tools.move(str(self), destination, force)
|
||||
if target_dir_exists:
|
||||
self.full_path = f"{destination}{'/' if destination[-1] != '/' else ''}{self.name}"
|
||||
else:
|
||||
@@ -80,7 +80,7 @@ class FsItem:
|
||||
return self
|
||||
|
||||
def refresh_item(self):
|
||||
updated_file = fs_utils.parse_ls_output(fs_utils.ls_item(self.full_path))[0]
|
||||
updated_file = fs_tools.parse_ls_output(fs_tools.ls_item(self.full_path))[0]
|
||||
# keep order the same as in __init__()
|
||||
self.parent_dir = updated_file.parent_dir
|
||||
self.name = updated_file.name
|
||||
|
@@ -5,7 +5,7 @@
|
||||
#
|
||||
|
||||
from core.test_run import TestRun
|
||||
from test_tools.fs_utils import (
|
||||
from test_tools.fs_tools import (
|
||||
readlink,
|
||||
create_directory,
|
||||
check_if_symlink_exists,
|
||||
|
Reference in New Issue
Block a user