From e4ac36fbe2a011ca889798eb22cc4842381403a7 Mon Sep 17 00:00:00 2001 From: Dimitris Zlatanidis Date: Tue, 21 Jun 2022 21:59:29 +0300 Subject: [PATCH] Move methods to utilities --- slpkg/slackbuild.py | 17 ++--------------- slpkg/utilities.py | 13 +++++++++++++ 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/slpkg/slackbuild.py b/slpkg/slackbuild.py index 983d9b59..75b4257c 100644 --- a/slpkg/slackbuild.py +++ b/slpkg/slackbuild.py @@ -2,7 +2,6 @@ # -*- coding: utf-8 -*- import os -import shutil import subprocess import multiprocessing @@ -95,8 +94,8 @@ class Slackbuilds: for sbo in self.install_order: file = f'{sbo}{self.tar_suffix}' - self.remove_file_if_exists(self.tmp_slpkg, file) - self.remove_folder_if_exists(self.build_path, sbo) + self.utils.remove_file_if_exists(self.tmp_slpkg, file) + self.utils.remove_folder_if_exists(self.build_path, sbo) location = SBoQueries(sbo).location() url = f'{self.sbo_url}/{location}/{file}' @@ -183,15 +182,3 @@ class Slackbuilds: wget.download(path, source) md5sum = Md5sum(self.flags) md5sum.check(source, checksum, name) - - def remove_file_if_exists(self, path: str, file: str): - ''' Clean the the old files. ''' - archive = f'{path}/{file}' - if os.path.isfile(archive): - os.remove(archive) - - def remove_folder_if_exists(self, path: str, folder: str): - ''' Clean the the old folders. ''' - directory = f'{path}/{folder}' - if os.path.isdir(directory): - shutil.rmtree(directory) diff --git a/slpkg/utilities.py b/slpkg/utilities.py index 6b1d70ab..43b8a8bb 100644 --- a/slpkg/utilities.py +++ b/slpkg/utilities.py @@ -4,6 +4,7 @@ import os import re +import shutil import tarfile from dataclasses import dataclass @@ -40,3 +41,15 @@ class Utilities: for pkg in os.listdir(self.log_packages): if package in pkg: return True + + def remove_file_if_exists(self, path: str, file: str): + ''' Clean the the old files. ''' + archive = f'{path}/{file}' + if os.path.isfile(archive): + os.remove(archive) + + def remove_folder_if_exists(self, path: str, folder: str): + ''' Clean the the old folders. ''' + directory = f'{path}/{folder}' + if os.path.isdir(directory): + shutil.rmtree(directory)