From a73c90cbf5ba27f264f9af9718b74b414014fd1c Mon Sep 17 00:00:00 2001 From: Devan Goodwin Date: Mon, 13 Jan 2014 16:29:38 -0400 Subject: [PATCH] Make external source builder fetch strategy configurable. --- rel-eng/tito.props | 1 + src/tito/builder/externalsrc.py | 26 +++++++++----------------- src/tito/builder/main.py | 1 + test/functional/externalsrc_tests.py | 17 ++++++++++++++--- test/functional/fixture.py | 13 ++++++------- 5 files changed, 31 insertions(+), 27 deletions(-) diff --git a/rel-eng/tito.props b/rel-eng/tito.props index a0aa754..2c3dea2 100644 --- a/rel-eng/tito.props +++ b/rel-eng/tito.props @@ -8,3 +8,4 @@ disttag = el5 [tag2] disttag = el5 + diff --git a/src/tito/builder/externalsrc.py b/src/tito/builder/externalsrc.py index 78ffd3e..8e31221 100644 --- a/src/tito/builder/externalsrc.py +++ b/src/tito/builder/externalsrc.py @@ -18,7 +18,8 @@ import shutil from tito.builder.main import BuilderBase from tito.config_object import ConfigObject -from tito.common import error_out, debug, get_spec_version_and_release +from tito.common import error_out, debug, get_spec_version_and_release, \ + get_class_by_name class ExternalSourceBuilder(ConfigObject, BuilderBase): """ @@ -44,6 +45,10 @@ class ExternalSourceBuilder(ConfigObject, BuilderBase): error_out("ExternalSourceBuilder does not support building " "specific tags.") + if not pkg_config.has_option("externalsourcebuilder", + "source_strategy"): + error_out("ExternalSourceBuilder requires [externalsourcebuilder] source_strategy in tito.props.") + self.build_tag = '%s-%s' % (self.project_name, get_spec_version_and_release(self.start_dir, '%s.spec' % self.project_name)) @@ -53,26 +58,13 @@ class ExternalSourceBuilder(ConfigObject, BuilderBase): self._create_build_dirs() print("Fetching sources...") - source_strat = KeywordArgSourceStrategy(self) + source_strat_class = get_class_by_name(self.pkg_config.get( + 'externalsourcebuilder', 'source_strategy')) + source_strat = source_strat_class(self) source_strat.fetch() self.sources = source_strat.sources self.spec_file = source_strat.spec_file - # Copy every normal file in the directory we ran tito from. This - # will pick up any sources that were sitting around locally. - # TODO: how to copy only sources? - #files_in_src_dir = [f for f in os.listdir(self.start_dir) \ - # if os.path.isfile(os.path.join(self.start_dir, f)) ] - #print files_in_src_dir - #for f in files_in_src_dir: - # shutil.copyfile(os.path.join(self.start_dir, f), - # os.path.join(self.rpmbuild_sourcedir, f)) - # TODO: extract version/release from filename? - # TODO: what filename? - #cmd = "/usr/bin/spectool --list-files '%s' | awk '{print $2}' |xargs -l1 --no-run-if-empty basename " % self.spec_file - #result = run_command(cmd) - #self.sources = map(lambda x: os.path.join(self.rpmbuild_sourcedir, x), result.split("\n")) - def _get_rpmbuild_dir_options(self): return ('--define "_sourcedir %s" --define "_builddir %s" ' '--define "_srcrpmdir %s" --define "_rpmdir %s" ' % ( diff --git a/src/tito/builder/main.py b/src/tito/builder/main.py index 4f462b0..68f6e1e 100644 --- a/src/tito/builder/main.py +++ b/src/tito/builder/main.py @@ -54,6 +54,7 @@ class BuilderBase(object): self.user_config = user_config self.args = args self.kwargs = kwargs + self.pkg_config = pkg_config # Optional keyword arguments: self.dist = self._get_optional_arg(kwargs, 'dist', None) diff --git a/test/functional/externalsrc_tests.py b/test/functional/externalsrc_tests.py index ee38716..25b0682 100644 --- a/test/functional/externalsrc_tests.py +++ b/test/functional/externalsrc_tests.py @@ -17,6 +17,7 @@ Functional Tests for the ExternalSource builder. import os import tempfile +import ConfigParser from tito.common import run_command from fixture import TitoGitTestFixture, tito @@ -29,9 +30,19 @@ class ExternalSourceBuilderTests(TitoGitTestFixture): TitoGitTestFixture.setUp(self) self.pkg_dir = os.path.join(self.repo_dir, EXT_SRC_PKG) spec = os.path.join(os.path.dirname(__file__), "specs/extsrc.spec") - self.create_project_from_spec(EXT_SRC_PKG, pkg_dir=self.pkg_dir, - spec=spec, - builder='tito.builder.ExternalSourceBuilder') + + # Setup test config: + self.config = ConfigParser.RawConfigParser() + self.config.add_section("buildconfig") + self.config.set("buildconfig", "builder", + "tito.builder.ExternalSourceBuilder") + + self.config.add_section('externalsourcebuilder') + self.config.set('externalsourcebuilder', 'source_strategy', + 'tito.builder.externalsrc.KeywordArgSourceStrategy') + + self.create_project_from_spec(EXT_SRC_PKG, self.config, + pkg_dir=self.pkg_dir, spec=spec) self.source_filename = 'extsrc-0.0.2.tar.gz' os.chdir(self.pkg_dir) diff --git a/test/functional/fixture.py b/test/functional/fixture.py index b54b9f3..2137cdc 100644 --- a/test/functional/fixture.py +++ b/test/functional/fixture.py @@ -138,8 +138,8 @@ class TitoGitTestFixture(unittest.TestCase): out_f.write(contents) out_f.close() - def create_project_from_spec(self, pkg_name, pkg_dir='', spec=None, - builder=None): + def create_project_from_spec(self, pkg_name, config, + pkg_dir='', spec=None): """ Create a sample tito project and copy the given test spec file over. """ @@ -149,11 +149,10 @@ class TitoGitTestFixture(unittest.TestCase): shutil.copyfile(spec, os.path.join(full_pkg_dir, os.path.basename(spec))) - if builder: - tito_props_f = open(os.path.join(full_pkg_dir, 'tito.props'), 'w') - tito_props_f.write('[buildconfig]\n') - tito_props_f.write('builder = %s' % builder) - tito_props_f.close() + # Write the config object we were given out to the project repo: + with open(os.path.join(full_pkg_dir, 'tito.props'), 'w') \ + as configfile: + config.write(configfile) def create_project(self, pkg_name, pkg_dir=''): """