Merge pull request #18 from mmichal10/crc

Introduce crc32
This commit is contained in:
Robert Baldyga 2024-10-03 10:49:31 +02:00 committed by GitHub
commit 4fc85ee669
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 6 deletions

View File

@ -108,17 +108,18 @@ def copy(source: str,
destination: str, destination: str,
force: bool = False, force: bool = False,
recursive: bool = False, recursive: bool = False,
dereference: bool = False): dereference: bool = False,
timeout: timedelta = timedelta(minutes=30)):
cmd = f"cp{' --force' if force else ''}" \ cmd = f"cp{' --force' if force else ''}" \
f"{' --recursive' if recursive else ''}" \ f"{' --recursive' if recursive else ''}" \
f"{' --dereference' if dereference else ''} " \ f"{' --dereference' if dereference else ''} " \
f"{source} {destination}" f"{source} {destination}"
return TestRun.executor.run_expect_success(cmd) return TestRun.executor.run_expect_success(cmd, timeout)
def move(source, destination, force: bool = False): def move(source, destination, force: bool = False, timeout: timedelta = timedelta(minutes=30)):
cmd = f"mv{' --force' if force else ''} \"{source}\" \"{destination}\"" cmd = f"mv{' --force' if force else ''} \"{source}\" \"{destination}\""
return TestRun.executor.run_expect_success(cmd) return TestRun.executor.run_expect_success(cmd, timeout)
def remove(path: str, force: bool = False, recursive: bool = False, ignore_errors: bool = False): def remove(path: str, force: bool = False, recursive: bool = False, ignore_errors: bool = False):
@ -191,6 +192,13 @@ def md5sum(file, binary=True, timeout: timedelta = timedelta(minutes=30)):
return output.stdout.split()[0] return output.stdout.split()[0]
def crc32sum(file, timeout: timedelta = timedelta(minutes=30)):
output = TestRun.executor.run(f"crc32 {file}", timeout)
if output.exit_code != 0:
raise Exception(f"crc32 command execution failed! {output.stdout}\n{output.stderr}")
return output.stdout
# For some reason separators other than '/' don't work when using sed on system paths # For some reason separators other than '/' don't work when using sed on system paths
# This requires escaping '/' in pattern and target string # This requires escaping '/' in pattern and target string
def escape_sed_string(string: str, sed_replace: bool = False): def escape_sed_string(string: str, sed_replace: bool = False):

View File

@ -23,6 +23,9 @@ class File(FsItem):
def md5sum(self, binary=True, timeout: timedelta = timedelta(minutes=30)): def md5sum(self, binary=True, timeout: timedelta = timedelta(minutes=30)):
return fs_utils.md5sum(str(self), binary, timeout) return fs_utils.md5sum(str(self), binary, timeout)
def crc32sum(self, timeout: timedelta = timedelta(minutes=30)):
return fs_utils.crc32sum(str(self), timeout)
def read(self): def read(self):
return fs_utils.read_file(str(self)) return fs_utils.read_file(str(self))
@ -51,8 +54,9 @@ class File(FsItem):
destination, destination,
force: bool = False, force: bool = False,
recursive: bool = False, recursive: bool = False,
dereference: bool = False): dereference: bool = False,
fs_utils.copy(str(self), destination, force, recursive, dereference) timeout: timedelta = timedelta(minutes=30)):
fs_utils.copy(str(self), destination, force, recursive, dereference, timeout)
if fs_utils.check_if_directory_exists(destination): if fs_utils.check_if_directory_exists(destination):
path = f"{destination}{'/' if destination[-1] != '/' else ''}{self.name}" path = f"{destination}{'/' if destination[-1] != '/' else ''}{self.name}"
else: else: