Exemple #1
0
 def _install_cassandra_home(self):
     self.cassandra_home = self.wdPath('cassandra_home')
     if os.path.exists(self.cassandra_home):
         return
     bo = self.wdPath('bo')
     if not os.path.exists(bo):
         os.mkdir(bo)
     dc = os.path.join(bo, 'download-cache')
     if not os.path.exists(dc):
         os.mkdir(dc)
     buildout = {'directory': bo,
                 'download-cache':'download-cache',
                 }
     import zc.buildout.download
     download = zc.buildout.download.Download(
         buildout,
         logger=logger)
     print >> sys.stderr, "Downloading %s" % URL
     fname, is_temp = download(URL)
     dest = self.wdPath('extract')
     print >> sys.stderr, "Extracting %s" % fname
     setuptools.archive_util.unpack_archive(fname, dest)
     root = os.path.join(dest, os.listdir(dest)[0])
     os.rename(root, self.cassandra_home)
     shutil.rmtree(dest)
Exemple #2
0
    def _download_install(self):
        url = self.options['sdk']

        filename = os.path.join('downloads', url.split('/')[-1])

        # download the sdk
        download = zc.buildout.download.Download(self.buildout['buildout'],
                                                 namespace=self.name,
                                                 hash_name=True,
                                                 logger=self.logger)
        filename, is_temp = download(url)

        # now unpack it
        self.logger.info('Unpacking and configuring')
        try:
            setuptools.archive_util.unpack_archive(filename, self.install_dir)
        finally:
            if is_temp:
                os.remove(filename)
Exemple #3
0
 def _install_cassandra_home(self):
     self.cassandra_home = self.wdPath('cassandra_home')
     if os.path.exists(self.cassandra_home):
         return
     bo = self.wdPath('bo')
     if not os.path.exists(bo):
         os.mkdir(bo)
     dc = os.path.join(bo, 'download-cache')
     if not os.path.exists(dc):
         os.mkdir(dc)
     buildout = {
         'directory': bo,
         'download-cache': 'download-cache',
     }
     import zc.buildout.download
     download = zc.buildout.download.Download(buildout, logger=logger)
     print >> sys.stderr, "Downloading %s" % URL
     fname, is_temp = download(URL)
     dest = self.wdPath('extract')
     print >> sys.stderr, "Extracting %s" % fname
     setuptools.archive_util.unpack_archive(fname, dest)
     root = os.path.join(dest, os.listdir(dest)[0])
     os.rename(root, self.cassandra_home)
     shutil.rmtree(dest)
Exemple #4
0
    def build(self):
        logger = logging.getLogger(self.name)
        download = zc.buildout.download.Download(
            self.buildout['buildout'], namespace='cmmi', hash_name=True,
            logger=logger)

        if self.shared:
            if os.path.isdir(self.shared):
                logger.info('using existing shared build')
                return self.shared

        fname, is_temp = download(self.url, md5sum=self.options.get('md5sum'))

        # now unpack and work as normal
        tmp = tempfile.mkdtemp('buildout-'+self.name)
        logger.info('Unpacking and configuring')
        try:
            setuptools.archive_util.unpack_archive(fname, tmp)
        finally:
            if is_temp:
                os.remove(fname)

        for key, value in sorted(self.environ.items()):
            logger.info('Updating environment: %s=%s' % (key, value))
        os.environ.update(self.environ)

        # XXX This is probably more complicated than it needs to be. I
        # retained the distinction between makedirs and mkdir when I moved
        # creation of the build dir after downloading the source since I
        # didn't understand the reason for the distinction. (tlotze)
        if self.shared and not os.path.isdir(self.shared):
            os.makedirs(self.shared)
        dest = self.options['location']
        if not os.path.exists(dest):
            os.mkdir(dest)

        try:
            here = os.getcwd()
            os.chdir(tmp)
            try:
                if not (os.path.exists(self.source_directory_contains) or
                        (self.autogen and os.path.exists(self.autogen))):
                    entries = os.listdir(tmp)
                    if len(entries) == 1:
                        os.chdir(entries[0])
                if self.patch != '':
                    # patch may be a filesystem path or url
                    # url patches can go through the cache
                    if self.patch != '':
                        try:
                            self.patch, is_temp = download(
                                self.patch,
                                md5sum=self.options.get('patch-md5sum'))
                        except:
                            # If download/checksum of the patch fails, leaving
                            # the tmp dir won't be helpful.
                            shutil.rmtree(tmp)
                            raise
                    try:
                        system("patch %s < %s"
                               % (self.patch_options, self.patch))
                    finally:
                        if is_temp:
                            os.remove(self.patch)
                if self.autogen != '':
                    logger.info('auto generating configure files')
                    system("./%s" % self.autogen)
                if not os.path.exists(self.source_directory_contains):
                    entries = os.listdir(tmp)
                    if len(entries) == 1:
                        os.chdir(entries[0])
                    else:
                        raise ValueError("Couldn't find configure")
                self.cmmi(dest)
                shutil.rmtree(tmp)
            finally:
                os.chdir(here)
        except:
            shutil.rmtree(dest)
            if os.path.exists(tmp):
                logger.error("cmmi failed: %s", tmp)
            raise
    def install(self):
        logger = logging.getLogger(self.name)
        dest = self.options['location']
        url = self.options['url']
        download = zc.buildout.download.Download(
            self.buildout['buildout'], namespace='cmmi', hash_name=True,
            logger=logger)

#        if self.shared:
#            if os.path.isdir(self.shared):
#                logger.info('using existing shared build')
#                return self.shared

        fname, is_temp = download(self.url, md5sum=self.options.get('md5sum'))

        tmp = tempfile.mkdtemp('buildout-'+self.name)
        logger.info('Unpacking and configuring')
        setuptools.archive_util.unpack_archive(fname, tmp)

        here = os.getcwd()
        if not os.path.exists(dest):
            os.mkdir(dest)

        try:
            os.chdir(tmp)
            try:
                if not os.path.exists('setup.py'):
                    entries = os.listdir(tmp)
                    if len(entries) == 1:
                        os.chdir(os.path.join(entries[0], 'python'))
                    else:
                        raise ValueError("Couldn't find setup.py")

                logger.info('Fixing setup.py')
                os.rename('setup.py', 'setup.py.orig')
                setup_orig = open('setup.py.orig')
                setup_new = []
                found_import = False
                inside_includes_dir = False
                done_includes_dir = False
                inside_libdirs = False
                done_libdirs = False
                #setup_orig = open("")
                for line in setup_orig.readlines():
                    if line.find('from distutils.core import setup') != -1:
                        if not found_import:
                            line = 'from setuptools import setup, Extension\n'
                            found_import = True

                    elif line.find('includes_dir = [') != -1:
                        inside_includes_dir = True
                    elif line.find('libdirs = [') != -1:
                        inside_libdirs = True
                    elif inside_includes_dir:
                        if not done_includes_dir:
                            setup_new.append(
                                ''.join(["'", self.options['libiconv-include-dir'], "'", ',']) + '\n')
                            setup_new.append(
                                ''.join(["'", self.options['libxml2-include-dir'], "'", ',']) + '\n')
                            setup_new.append(
                                ''.join(["'", self.options['libxslt-include-dir'], "'", ',']) + '\n')
                            done_includes_dir = True

                        else:
                            if line == ']\n' or line == '];\n':
                                inside_includes_dir = False
                                setup_new.append(']\n')
                        continue

                    elif inside_libdirs:
                        if not done_libdirs:
                            setup_new.append(
                                ''.join(["'", self.options['libiconv-lib-dir'], "'", ',']) + '\n')
                            setup_new.append(
                                ''.join(["'", self.options['libxml2-lib-dir'], "'", ',']) + '\n')
                            setup_new.append(
                                ''.join(["'", self.options['libxslt-lib-dir'], "'", ',']) + '\n')
                            done_libdirs = True

                        else:
                            if line == ']\n' or line == '];\n':
                                inside_libdirs = False
                                setup_new.append(']\n')
                        continue

                    setup_new.append(line)

                try:
                    f = open('setup.py', 'w')
                    f.writelines(setup_new)
                    f.close()
                except:
                    logger.info('Error fixing setup.py')
                    raise

                libxml2_version = os.listdir('../..')[0][8:]

                #os.system("python setup.py sdist")
                os.system("python setup.py bdist_egg")
                distr_name = os.listdir('dist')[0]
                if os.path.exists(os.path.join(here, distr_name)):
                    os.unlink(os.path.join(here, distr_name))

                os.rename(os.path.join('dist', os.listdir('dist')[0]), os.path.join(here, distr_name))
                #try:
                #    with tarfile.open(
                #        os.path.join(
                #            here,  distr_name), "w:gz") as tar:
                #        for name in os.listdir('.'):
                #            tar.add(name)
                #except:
                #    raise
                
                #os.system("python setup.py bdist_egg --dist-dir %s" % self.buildout['buildout']['eggs-directory'])
                #os.system("make install")
                #logger.info("Dir: %s", tmp)
                #logger.info("")
            finally:
                os.chdir(here)
        except:
            shutil.rmtree(dest)
            raise

        return dest