Ejemplo n.º 1
0
 def prepare(self, context):
     if self.enabled:
         installers = Installers()
         for candidate in WorkingSet(context.interpretor, no_activate=False):
             if self.enabled is not None and candidate.name in self.enabled:
                 installers.add(NullInstaller(context, candidate))
         if installers:
             return Query(context, installers)
     return None
Ejemplo n.º 2
0
 def prepare(self, context):
     if len(self.requirements):
         installers = Installers()
         for requirement in self.requirements:
             installers.add(FakeInstaller(
                     context,
                     requirement))
         return Query(context, installers)
     return None
Ejemplo n.º 3
0
    def prepare(self, context):
        __status__ = u"Analysing local software source %s." % (
            context.path)
        installers = Installers()

        def build_installer(informations):
            return self.installer_factory(context, **informations)

        installers.extend(map(build_installer,
                              self.get_information(context.path)))
        if installers:
            return Query(context, installers)
        return None
Ejemplo n.º 4
0
 def __init__(self, source, interpretor, path, priority, trust=0):
     super(RemoteContext, self).__init__(source, interpretor, path, priority, trust)
     self.find_links = source.find_links
     self.disallow_urls = source.disallow_urls
     self.allow_urls = source.allow_urls
     self.max_depth = source.max_depth
     self.broken_links = set([])  # List of links that doesn't works.
     self.links = {}
     self.downloading_links = {}
     self.lock = threading.Lock()
     self.cache = Installers()
     self.downloader = DownloadManager(source.get_download_directory())
Ejemplo n.º 5
0
 def prepare(self, context):
     __status__ = u"Preparing extensions sources."
     installers = Installers()
     for name, package in working_set.iter_all_entry_points(
         'setup_extensions'):
         if self.enabled is not None and name not in self.enabled:
             continue
         if not hasattr(package, '__path__'):
             raise InstallationError(u"Invalid extension entry point", name)
         directory = package.__path__[0]
         for name in os.listdir(directory):
             path = os.path.join(directory, name)
             if os.path.isdir(path):
                 if name in installers:
                     raise InstallationError(
                         u'Duplicate extension source',
                         path,
                         installers[name])
                 installers.add(ExtractedPackageInstaller(
                         context, name=name, path=path))
     if installers:
         return Query(context, installers)
     return None
Ejemplo n.º 6
0
class RemoteContext(QueryContext):

    def __init__(self, source, interpretor, path, priority, trust=0):
        super(RemoteContext, self).__init__(source, interpretor, path, priority, trust)
        self.find_links = source.find_links
        self.disallow_urls = source.disallow_urls
        self.allow_urls = source.allow_urls
        self.max_depth = source.max_depth
        self.broken_links = set([])  # List of links that doesn't works.
        self.links = {}
        self.downloading_links = {}
        self.lock = threading.Lock()
        self.cache = Installers()
        self.downloader = DownloadManager(source.get_download_directory())

    def search(self, requirement):
        """Search if there is a match for a requirement in the cache.
        """
        return self.cache.get_installers_for(
            requirement, self.pyversion, self.platform)

    def mark_as_broken(self, installer):
        """Mark an installer as broken so it won't be found again.
        """
        self.broken_links.add(installer.url)
        self.cache.remove(installer)

    def follow_link(self, url):
        """Load links from the given URL if needed. Return True upon
        success.
        """
        if self.is_disabled_link(url):
            return False
        if url in self.links:
            return True
        self.lock.acquire()
        if url in self.downloading_links:
            self.lock.release()
            # We are looking at this page, just wait.
            self.downloading_links[url].wait()
            return url in self.links
        # Add a Event and download
        self.downloading_links[url] = threading.Event()
        self.lock.release()

        try:
            try:
                links, informations = url.follow(self)
            except NetworkError:
                logger.warn("URL '%s' inaccessible, mark as broken.", url)
                self.broken_links.add(url)
            else:
                # Add found links and installers
                self.links[url] = links
                for detail in informations:
                    self.cache.add(UndownloadedPackageInstaller(self, **detail))
        finally:
            self.downloading_links[url].set()
        return url in self.links

    def is_disabled_link(self, url, verify_allow=False):
        """Return true if the given URL should not be followed,
        testing for broken links, allowed and disallowed URLs.
        """
        if url in self.broken_links:
            logger.warn("Ignoring broken URL '%s'.", url)
            return True
        if verify_allow:
            test_url = str(url).startswith
            if self.disallow_urls:
                for disallowed_url in self.disallow_urls:
                    if test_url(disallowed_url):
                        logger.warn("Ignoring disallowed URL '%s'.", url)
                        return True
            if self.allow_urls:
                for allowed_url in self.allow_urls:
                    if not test_url(allowed_url):
                        logger.warn("Ignoring not allowed URL '%s'.", url)
                        return True
        return False