From 89de1364a65072526f8681216bab7aa7169ecb7d Mon Sep 17 00:00:00 2001 From: Miroslav Suchý Date: May 28 2020 07:19:34 +0000 Subject: [PATCH 1/2] call buildArchs as named argument --- diff --git a/rpmfluff/rpmbuild.py b/rpmfluff/rpmbuild.py index 436a216..87d3130 100644 --- a/rpmfluff/rpmbuild.py +++ b/rpmfluff/rpmbuild.py @@ -169,7 +169,7 @@ class SimpleRpmBuild(RpmBuild): """A wrapper for rpmbuild that also provides a canned way of generating a specfile and the source files.""" def __init__(self, name, version, release, buildArchs=None): - RpmBuild.__init__(self, buildArchs) + RpmBuild.__init__(self, buildArchs=buildArchs) self.specfileEncoding = 'utf-8' From 111377735cf05e8472bc232825fc1c0720253bdf Mon Sep 17 00:00:00 2001 From: Miroslav Suchý Date: May 28 2020 08:04:20 +0000 Subject: [PATCH 2/2] make build directory in /tmp Resolves: #30 --- diff --git a/rpmfluff/rpmbuild.py b/rpmfluff/rpmbuild.py index 87d3130..2197f92 100644 --- a/rpmfluff/rpmbuild.py +++ b/rpmfluff/rpmbuild.py @@ -20,6 +20,7 @@ import random import re import shutil import subprocess +import tempfile from .check import CheckTrigger, CheckSourceFile, CheckPayloadFile from .samples import hello_world, simple_library_source, sample_man_page, \ @@ -49,13 +50,15 @@ class RpmBuild(Buildable): """ Wrapper for an invocation of rpmbuild """ - def __init__(self, buildArchs=None): + def __init__(self, buildArchs=None, tmpdir=True): """ buildArchs: if None, the build will happen on the current arch if non-None, should be a list of strings: the archs to build on """ self.buildArchs = buildArchs + self.tmpdir = tmpdir + self.tmpdir_location = None def is_up_to_date(self): # FIXME: crude check for now: does the build dir exist? @@ -69,6 +72,8 @@ class RpmBuild(Buildable): def clean(self): shutil.rmtree(self.get_base_dir(), ignore_errors=True) + if self.tmpdir and self.tmpdir_location: + shutil.rmtree(self.tmpdir_location, ignore_errors=True) def sanitize_string(self, name): """Strip what can be dangerous for filenames""" @@ -76,6 +81,8 @@ class RpmBuild(Buildable): def __create_directories(self): """Sets up the directory hierarchy for the build""" + if self.tmpdir and not (self.tmpdir_location and os.path.isdir(self.tmpdir_location)): + self.tmpdir_location = tempfile.mkdtemp(prefix="rpmfluff-") os.mkdir(self.get_base_dir()) # Make fake rpmbuild directories @@ -168,8 +175,8 @@ class RpmBuild(Buildable): class SimpleRpmBuild(RpmBuild): """A wrapper for rpmbuild that also provides a canned way of generating a specfile and the source files.""" - def __init__(self, name, version, release, buildArchs=None): - RpmBuild.__init__(self, buildArchs=buildArchs) + def __init__(self, name, version, release, buildArchs=None, tmpdir=True): + RpmBuild.__init__(self, buildArchs=buildArchs, tmpdir=tmpdir) self.specfileEncoding = 'utf-8' @@ -211,7 +218,11 @@ class SimpleRpmBuild(RpmBuild): self.specbasename = None def get_base_dir(self): - return "test-rpmbuild-%s-%s-%s" % (self.name, self.version, expand_macros(self.release)) + if self.tmpdir_location: + return "%s/test-rpmbuild-%s-%s-%s" % (self.tmpdir_location, self.name, self.version, + expand_macros(self.release)) + else: + return "test-rpmbuild-%s-%s-%s" % (self.name, self.version, expand_macros(self.release)) def get_subpackage_names(self): """ diff --git a/rpmfluff/test.py b/rpmfluff/test.py index b914f50..1dbfa03 100644 --- a/rpmfluff/test.py +++ b/rpmfluff/test.py @@ -96,7 +96,7 @@ class TestSimpleRpmBuild(unittest.TestCase): "build directory %s already exists" % self.rpmbuild.get_base_dir()) def tearDown(self): - shutil.rmtree(self.rpmbuild.get_base_dir(), ignore_errors=True) + self.rpmbuild.clean() def test_build(self): self.rpmbuild.make() @@ -804,7 +804,7 @@ class YumRepoBuildTests(unittest.TestCase): package.add_devel_subpackage() package.add_subpackage('python') repo = YumRepoBuild([package]) - self.addCleanup(shutil.rmtree, package.get_base_dir()) + self.addCleanup(package.clean) self.addCleanup(shutil.rmtree, repo.repoDir) repo.make(expectedArch) @@ -819,7 +819,7 @@ class YumRepoBuildTests(unittest.TestCase): def test_multiple_arches(self): package = SimpleRpmBuild('test-multilib-package', '0.1', '1', ['i386', 'x86_64']) repo = YumRepoBuild([package]) - self.addCleanup(shutil.rmtree, package.get_base_dir()) + self.addCleanup(package.clean) self.addCleanup(shutil.rmtree, repo.repoDir) repo.make('i386', 'x86_64') @@ -834,8 +834,8 @@ class YumRepoBuildTests(unittest.TestCase): archful_package = SimpleRpmBuild('test-package', '0.1', '1') noarch_package = SimpleRpmBuild('python-package', '0.1', '1', ['noarch']) repo = YumRepoBuild([archful_package, noarch_package]) - self.addCleanup(shutil.rmtree, archful_package.get_base_dir()) - self.addCleanup(shutil.rmtree, noarch_package.get_base_dir()) + self.addCleanup(archful_package.clean) + self.addCleanup(noarch_package.clean) self.addCleanup(shutil.rmtree, repo.repoDir) repo.make(expectedArch, 'noarch')