Commit 3f728307 authored by Kai Lautaportti's avatar Kai Lautaportti

Refactored the is_build_dir() helper to make it easier to customize.

parent ceaecd7f
...@@ -67,6 +67,11 @@ class Recipe(object): ...@@ -67,6 +67,11 @@ class Recipe(object):
log.error('Error executing command: %s' % cmd) log.error('Error executing command: %s' % cmd)
raise zc.buildout.UserError('System error') raise zc.buildout.UserError('System error')
def is_build_dir(self):
"""Returns True if the current directory contains files that we
consider buildable, False otherwise."""
return os.path.isfile('configure') or os.path.isfile('Makefile.PL')
def install(self): def install(self):
log = logging.getLogger(self.name) log = logging.getLogger(self.name)
parts = [] parts = []
...@@ -94,7 +99,7 @@ class Recipe(object): ...@@ -94,7 +99,7 @@ class Recipe(object):
if self.options['url']: if self.options['url']:
compile_dir = self.options['compile-directory'] compile_dir = self.options['compile-directory']
os.mkdir(compile_dir) os.mkdir(compile_dir)
try: try:
opt = self.options.copy() opt = self.options.copy()
opt['destination'] = compile_dir opt['destination'] = compile_dir
...@@ -109,22 +114,19 @@ class Recipe(object): ...@@ -109,22 +114,19 @@ class Recipe(object):
os.mkdir(self.options['location']) os.mkdir(self.options['location'])
os.chdir(compile_dir) os.chdir(compile_dir)
def is_build_dir():
return os.path.isfile('configure') or os.path.isfile('Makefile.PL')
try: try:
if not is_build_dir(): if not self.is_build_dir():
contents = os.listdir(compile_dir) contents = os.listdir(compile_dir)
if len(contents) == 1: if len(contents) == 1:
os.chdir(contents[0]) os.chdir(contents[0])
if not is_build_dir(): if not self.is_build_dir():
log.error('Unable to find the configure script') log.error('Unable to find the configure script')
raise zc.buildout.UserError('Invalid package contents') raise zc.buildout.UserError('Invalid package contents')
else: else:
log.error('Unable to find the configure script') log.error('Unable to find the configure script')
raise zc.buildout.UserError('Invalid package contents') raise zc.buildout.UserError('Invalid package contents')
if patches: if patches:
log.info('Applying patches') log.info('Applying patches')
for patch in patches: for patch in patches:
......
from zope.testing import doctest
from zope.testing import renormalizing
import os
import re
import shutil
import tempfile
import unittest import unittest
import zc.buildout.tests
import zc.buildout.testing import zc.buildout.testing
import re import zc.buildout.tests
from zope.testing import doctest, renormalizing
optionflags = (doctest.ELLIPSIS | optionflags = (doctest.ELLIPSIS |
doctest.NORMALIZE_WHITESPACE | doctest.NORMALIZE_WHITESPACE |
...@@ -14,6 +18,50 @@ def setUp(test): ...@@ -14,6 +18,50 @@ def setUp(test):
zc.buildout.testing.install('hexagonit.recipe.download', test) zc.buildout.testing.install('hexagonit.recipe.download', test)
zc.buildout.testing.install_develop('hexagonit.recipe.cmmi', test) zc.buildout.testing.install_develop('hexagonit.recipe.cmmi', test)
class NonInformativeTests(unittest.TestCase):
def setUp(self):
self.dir = tempfile.mkdtemp()
def tearDown(self):
shutil.rmtree(self.dir)
def write_file(self, filename, contents):
path = os.path.join(self.dir, filename)
fh = open(path, 'w')
fh.write(contents)
fh.close()
return path
def make_recipe(self, buildout, name, options):
from hexagonit.recipe.cmmi import Recipe
bo = {
'buildout' : {
'parts-directory' : '',
}
}
bo.update(buildout)
return Recipe(bo, name, options)
def test_is_build_dir__with_configure(self):
recipe = self.make_recipe({}, 'test', {'url' : 'http://no.where.com/'})
os.chdir(self.dir)
self.failIf(recipe.is_build_dir())
configure = self.write_file('configure', 'Dummy configure script')
self.failUnless(os.path.exists(configure))
self.failUnless(recipe.is_build_dir())
def test_is_build_dir__with_makefile_pl(self):
recipe = self.make_recipe({}, 'test', {'url' : 'http://no.where.com/'})
os.chdir(self.dir)
self.failIf(recipe.is_build_dir())
makefile = self.write_file('Makefile.PL', 'Dummy Makefile.PL script')
self.failUnless(os.path.exists(makefile))
self.failUnless(recipe.is_build_dir())
def test_suite(): def test_suite():
suite = unittest.TestSuite(( suite = unittest.TestSuite((
doctest.DocFileSuite( doctest.DocFileSuite(
...@@ -29,6 +77,7 @@ def test_suite(): ...@@ -29,6 +77,7 @@ def test_suite():
zc.buildout.testing.normalize_path, zc.buildout.testing.normalize_path,
]), ]),
), ),
unittest.makeSuite(NonInformativeTests),
)) ))
return suite return suite
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment