[Checkins] SVN: zc.recipe.cmmi/trunk/zc/recipe/cmmi/ works for tar
balls on unix
Jim Fulton
jim at zope.com
Mon Aug 7 18:42:48 EDT 2006
Log message for revision 69371:
works for tar balls on unix
Changed:
U zc.recipe.cmmi/trunk/zc/recipe/cmmi/__init__.py
D zc.recipe.cmmi/trunk/zc/recipe/cmmi/tests.py
-=-
Modified: zc.recipe.cmmi/trunk/zc/recipe/cmmi/__init__.py
===================================================================
--- zc.recipe.cmmi/trunk/zc/recipe/cmmi/__init__.py 2006-08-07 21:02:51 UTC (rev 69370)
+++ zc.recipe.cmmi/trunk/zc/recipe/cmmi/__init__.py 2006-08-07 22:42:48 UTC (rev 69371)
@@ -1,34 +1,79 @@
-import logging, os
+import logging, os, shutil, tempfile, urllib2, urlparse
+def system(c):
+ if os.system(c):
+ raise SystemError("Failed", c)
+
class Recipe:
def __init__(self, buildout, name, options):
self.name, self.options = name, options
- path = options.get('path')
- if path is None:
- path = os.path.join(buildout['buildout']['parts-directory'],
- self.name, 'Data.fs')
- self.make_part = True
- else:
- path = os.path.join(buildout['buildout']['directory'], path)
- if not os.path.exists(path):
- logging.getLogger('zc.recipe.filestorage').error(
- "%s does not exixt", path)
- self.make_part = False
-
- options['path'] = path
- options['zconfig'] = template % path
+ options['dest'] = os.path.join(buildout['buildout']['parts-directory'],
+ self.name)
def install(self):
- if self.make_part:
- part = os.path.dirname(self.options['path'])
- if not os.path.exists(part):
- os.mkdir(part)
+ dest = self.options['dest']
+ if os.path.exists(dest):
+ return # already there
-template = """\
-<zodb>
- <filestorage>
- path %s
- </filestorage>
-</zodb>
-"""
+ url = self.options['url']
+ f = urllib2.urlopen(url)
+ _, _, urlpath, _, _, _ = urlparse.urlparse(url)
+ tmp = tempfile.mkdtemp('buildout-'+self.name)
+ try:
+ for suffix, handler in extractors.items():
+ if urlpath.endswith(suffix):
+ handler(f, tmp)
+ break
+ else:
+ raise ValueError("Don't know how to expand", urlpath)
+
+
+ os.mkdir(dest)
+ here = os.getcwd()
+ try:
+ os.chdir(tmp)
+ if not os.path.exists('configure'):
+ entries = os.listdir(tmp)
+ if len(entries) == 1:
+ os.chdir(entries[0])
+ else:
+ raise ValueError("Couldn't find configure")
+
+ system("./configure --prefix="+dest)
+ system("make")
+ system("make install")
+ except:
+ os.chdir(here)
+ os.rmdir(dest)
+ raise
+
+ finally:
+ shutil.rmtree(tmp)
+
+
+def tar(stream, path, mode='r|'):
+ import tarfile
+ t = tarfile.open(mode=mode, fileobj=stream)
+ while 1:
+ info = t.next()
+ if info is None:
+ t.close()
+ return
+ t.extract(info, path)
+
+def tgz(stream, path):
+ return tar(stream, path, 'r|gz')
+
+def tbz(stream, path):
+ return tar(stream, path, 'r|bz2')
+
+extractors = {
+ '.tar': tar,
+ '.tgz': tgz,
+ '.tar.gz': tgz,
+ '.tar.bz2': tbz,
+ #'.zip': zip,
+ }
+
+
Deleted: zc.recipe.cmmi/trunk/zc/recipe/cmmi/tests.py
===================================================================
--- zc.recipe.cmmi/trunk/zc/recipe/cmmi/tests.py 2006-08-07 21:02:51 UTC (rev 69370)
+++ zc.recipe.cmmi/trunk/zc/recipe/cmmi/tests.py 2006-08-07 22:42:48 UTC (rev 69371)
@@ -1,30 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2006 Zope Corporation and Contributors.
-# All Rights Reserved.
-#
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-#
-##############################################################################
-import os, re, unittest
-import pkg_resources
-from zope.testing import doctest, renormalizing
-
-def test_suite():
- global __test__
- req = pkg_resources.Requirement.parse('zc.recipe.filestorage')
- __test__ = dict(README=pkg_resources.resource_string(req, 'README.txt'))
- return doctest.DocTestSuite(
- checker=renormalizing.RENormalizing([
- (re.compile('\S+%(sep)s\w+%(sep)s\w+.fs'
- % dict(sep=os.path.sep)),
- r'/tmp/data/Data.fs'),
- (re.compile('\S+sample-(\w+)'), r'/sample-\1'),
- ]),
- )
-
More information about the Checkins
mailing list