Make external source builder fetch strategy configurable.

This commit is contained in:
Devan Goodwin 2014-01-13 16:29:38 -04:00
parent a52a2458c4
commit a73c90cbf5
5 changed files with 31 additions and 27 deletions

View file

@ -8,3 +8,4 @@ disttag = el5
[tag2] [tag2]
disttag = el5 disttag = el5

View file

@ -18,7 +18,8 @@ import shutil
from tito.builder.main import BuilderBase from tito.builder.main import BuilderBase
from tito.config_object import ConfigObject 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): class ExternalSourceBuilder(ConfigObject, BuilderBase):
""" """
@ -44,6 +45,10 @@ class ExternalSourceBuilder(ConfigObject, BuilderBase):
error_out("ExternalSourceBuilder does not support building " error_out("ExternalSourceBuilder does not support building "
"specific tags.") "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, self.build_tag = '%s-%s' % (self.project_name,
get_spec_version_and_release(self.start_dir, get_spec_version_and_release(self.start_dir,
'%s.spec' % self.project_name)) '%s.spec' % self.project_name))
@ -53,26 +58,13 @@ class ExternalSourceBuilder(ConfigObject, BuilderBase):
self._create_build_dirs() self._create_build_dirs()
print("Fetching sources...") 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() source_strat.fetch()
self.sources = source_strat.sources self.sources = source_strat.sources
self.spec_file = source_strat.spec_file 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): def _get_rpmbuild_dir_options(self):
return ('--define "_sourcedir %s" --define "_builddir %s" ' return ('--define "_sourcedir %s" --define "_builddir %s" '
'--define "_srcrpmdir %s" --define "_rpmdir %s" ' % ( '--define "_srcrpmdir %s" --define "_rpmdir %s" ' % (

View file

@ -54,6 +54,7 @@ class BuilderBase(object):
self.user_config = user_config self.user_config = user_config
self.args = args self.args = args
self.kwargs = kwargs self.kwargs = kwargs
self.pkg_config = pkg_config
# Optional keyword arguments: # Optional keyword arguments:
self.dist = self._get_optional_arg(kwargs, 'dist', None) self.dist = self._get_optional_arg(kwargs, 'dist', None)

View file

@ -17,6 +17,7 @@ Functional Tests for the ExternalSource builder.
import os import os
import tempfile import tempfile
import ConfigParser
from tito.common import run_command from tito.common import run_command
from fixture import TitoGitTestFixture, tito from fixture import TitoGitTestFixture, tito
@ -29,9 +30,19 @@ class ExternalSourceBuilderTests(TitoGitTestFixture):
TitoGitTestFixture.setUp(self) TitoGitTestFixture.setUp(self)
self.pkg_dir = os.path.join(self.repo_dir, EXT_SRC_PKG) self.pkg_dir = os.path.join(self.repo_dir, EXT_SRC_PKG)
spec = os.path.join(os.path.dirname(__file__), "specs/extsrc.spec") 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, # Setup test config:
builder='tito.builder.ExternalSourceBuilder') 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' self.source_filename = 'extsrc-0.0.2.tar.gz'
os.chdir(self.pkg_dir) os.chdir(self.pkg_dir)

View file

@ -138,8 +138,8 @@ class TitoGitTestFixture(unittest.TestCase):
out_f.write(contents) out_f.write(contents)
out_f.close() out_f.close()
def create_project_from_spec(self, pkg_name, pkg_dir='', spec=None, def create_project_from_spec(self, pkg_name, config,
builder=None): pkg_dir='', spec=None):
""" """
Create a sample tito project and copy the given test spec file over. 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))) shutil.copyfile(spec, os.path.join(full_pkg_dir, os.path.basename(spec)))
if builder: # Write the config object we were given out to the project repo:
tito_props_f = open(os.path.join(full_pkg_dir, 'tito.props'), 'w') with open(os.path.join(full_pkg_dir, 'tito.props'), 'w') \
tito_props_f.write('[buildconfig]\n') as configfile:
tito_props_f.write('builder = %s' % builder) config.write(configfile)
tito_props_f.close()
def create_project(self, pkg_name, pkg_dir=''): def create_project(self, pkg_name, pkg_dir=''):
""" """