示例#1
0
 def unpack_if_needed(self):
     meta = pkg_resources.EggMetadata(
         zipimport.zipimporter(self.distribution.location))
     if meta.has_metadata('not-zip-safe'):
         unpack_zipfile(self.distribution.location,
                        self.distribution.location + "-tmp")
         os.remove(self.distribution.location)
         os.rename(self.distribution.location + "-tmp",
                   self.distribution.location)
示例#2
0
    def _get_dist(self, requirement, ws, always_unzip):
        """The only difference between this and the standard implementation is that it doesn't copy
        eggs from the egg cache but links to them in place."""

        __doing__ = 'Getting distribution for %r.', str(requirement)

        # Maybe an existing dist is already the best dist that satisfies the
        # requirement
        dist, avail = self._satisfied(requirement)

        if dist is None:
            if self._dest is not None:
                easy_install.logger.info(*__doing__)

            # Retrieve the dist:
            if avail is None:
                raise easy_install.MissingDistribution(requirement, ws)

            # We may overwrite distributions, so clear importer
            # cache.
            sys.path_importer_cache.clear()

            tmp = self._download_cache
            if tmp is None:
                tmp = easy_install.tempfile.mkdtemp('get_dist')

            try:
                dist = self._fetch(avail, tmp, self._download_cache)

                if dist is None:
                    raise easy_install.zc.buildout.UserError(
                        "Couldn't download distribution %s." % avail)

                if dist.precedence == pkg_resources.EGG_DIST:
                    # It's already an egg, just fetch it into the dest

                    newloc = os.path.join(self._dest,
                                          os.path.basename(dist.location))

                    # The next 2 lines are new, this is the only bit that is different from the standard
                    if egg_cache.is_from_egg_cache(dist.location):
                        newloc = dist.location
                    elif os.path.isdir(dist.location):
                        # we got a directory. It must have been
                        # obtained locally.  Just copy it.
                        shutil.copytree(dist.location, newloc)
                    else:

                        if self._always_unzip:
                            should_unzip = True
                        else:
                            metadata = pkg_resources.EggMetadata(
                                zipimport.zipimporter(dist.location))
                            should_unzip = (
                                metadata.has_metadata('not-zip-safe')
                                or not metadata.has_metadata('zip-safe'))

                        if should_unzip:
                            easy_install.setuptools.archive_util.unpack_archive(
                                dist.location, newloc)
                        else:
                            shutil.copyfile(dist.location, newloc)

                    easy_install.redo_pyc(newloc)

                    # Getting the dist from the environment causes the
                    # distribution meta data to be read.  Cloning isn't
                    # good enough.
                    dists = pkg_resources.Environment(
                        [newloc],
                        python=easy_install._get_version(self._executable),
                    )[dist.project_name]
                else:
                    # It's some other kind of dist.  We'll let easy_install
                    # deal with it:
                    dists = self._call_easy_install(dist.location, ws,
                                                    self._dest, dist)
                    for dist in dists:
                        easy_install.redo_pyc(dist.location)

            finally:
                if tmp != self._download_cache:
                    shutil.rmtree(tmp)

            self._env.scan([self._dest])
            dist = self._env.best_match(requirement, ws)
            easy_install.logger.info("Got %s.", dist)

        else:
            dists = [dist]

        for dist in dists:
            if (dist.has_metadata('dependency_links.txt')
                    and not self._install_from_cache
                    and self._use_dependency_links):
                for link in dist.get_metadata_lines('dependency_links.txt'):
                    link = link.strip()
                    if link not in self._links:
                        easy_install.logger.debug(
                            'Adding find link %r from %s', link, dist)
                        self._links.append(link)
                        self._index = easy_install._get_index(
                            self._executable, self._index_url, self._links,
                            self._allow_hosts, self._path)

        for dist in dists:
            # Check whether we picked a version and, if we did, report it:
            if not (dist.precedence == pkg_resources.DEVELOP_DIST or
                    (len(requirement.specs) == 1
                     and requirement.specs[0][0] == '==')):
                easy_install.logger.debug('Picked: %s = %s', dist.project_name,
                                          dist.version)
                if not self._allow_picked_versions:
                    raise easy_install.zc.buildout.UserError(
                        'Picked: %s = %s' % (dist.project_name, dist.version))

        return dists
示例#3
0
    def install_plugin(self, name, rev, new=False):
        """Install a plugin into the envrionment's plugin directory."""
        plugins_dir = os.path.join(self.env.path,'plugins')
        installed_dists = []
        
        # Use easy_install to build the egg
        temp_file = tempfile.NamedTemporaryFile(suffix='.txt',prefix='hackinstall-record',dir=self.builddir,mode='r')
        command = "easy_install -m --install-dir=%s --record=%s %s/svn/%s/%s" % (plugins_dir, temp_file.name, self.url, name.lower(), self.version)
        self.env.log.info('Running os.system(%s)'%command)
        rv = os.system(command)
        if rv != 0:
            self.env.log.warning("easy_install failed with a return code of %s. Please look in your webserver's error log for the output"%rv)
            return (False, None)
        
        # Retrieve the installed files
        installed = temp_file.readlines()
        temp_file.close()

        # Process each installed file
        for old_file in installed:
            old_file = old_file.strip() # Remove newlines
            self.env.log.debug("Processing file '%s'" % old_file)
            if old_file.endswith('.egg'):
                dist = pkg_resources.Distribution.from_filename(old_file,pkg_resources.EggMetadata(zipimport.zipimporter(old_file)))
                # Find and disable entry points (only on new installs)
                if new:
                    if dist.has_metadata('trac_plugin.txt'):
                        self.env.log.debug('trac_plugin.txt file detected')
                        for line in dist.get_metadata_lines('trac_plugin.txt'):
                            self.env.config.set('components',line.strip()+'.*','disabled')
                    else:
                        self.env.log.debug('Entry point plugin detected')
                        for entry_name in dist.get_entry_map('trac.plugins'):
                            self.env.log.debug("Processing entry name '%s'"%entry_name)
                            entry_point = dist.get_entry_info('trac.plugins', entry_name)
                            self.env.log.debug("Module name is '%s'"%entry_point.module_name)
                            self.env.config.set('components',entry_point.module_name+'.*','disabled')
                    self.env.config.save()

                old_name = os.path.basename(old_file)
                new_name = None
                # Rename a plugin from Foo-0.5-py2.4.egg to Foo-0.5-rREV-py2.4.egg
                md = re.match('([^-]+-)([^-]+)(-py\d\.\d+\.egg)',old_name)
                if md:
                    md2 = re.search('(r\d+)',md.group(2))
                    if md2:
                        new_name = re.sub('(.*)(r\d+)(.*)','\1r%s\3'%rev,old_name)
                    else:
                        new_name = '%s%s_r%s%s' % (md.group(1),md.group(2),rev,md.group(3))
                    new_file = os.path.join(plugins_dir, new_name)
                    self.env.log.debug('Renaming %s to %s' % (old_file, new_file))
                    os.rename(old_file, new_file)
                    
                # Remove all old versions
                md = re.match('([^-]+)-',new_name)
                if md:
                    for plugin_name in os.listdir(plugins_dir):
                        md2 = re.match('([^-]+)-',plugin_name)
                        self.env.log.debug("Removal scan: new_name='%s' plugin_name='%s'" % (new_name,plugin_name))
                        if md2 and new_name != plugin_name and md.group(1) == md2.group(1):
                            plugin_file = os.path.join(plugins_dir,plugin_name)
                            self.env.log.debug('Removing '+plugin_file)
                            os.remove(plugin_file)
                            
                installed_dists.append(dist.project_name)
        return (len(installed_dists)>0, installed_dists)
示例#4
0
 def unpack_if_needed(self):
     meta = pkg_resources.EggMetadata(zipimport.zipimporter(self.path))
     if meta.has_metadata('not-zip-safe'):
         unpack_zipfile(self.path, self.path + "-tmp")
         os.remove(self.path)
         os.rename(self.path + "-tmp", self.path)