def test_latest_vulndb(self):
        dists = Distributions()
        pkg = 'vulndb'
        found = None
        pypi = CheeseShop(False)
        all_dists = dists.get_distributions('all', pkg,
                                            dists.get_highest_installed(pkg))

        for dist, active in all_dists:
            project_name, versions = pypi.query_versions_pypi(
                dist.project_name)

            if versions:
                # PyPI returns them in chronological order,
                # but who knows if its guaranteed in the API?
                # Make sure we grab the highest version:
                newest = get_highest_version(versions)
                if newest != dist.version:

                    # We may have newer than what PyPI knows about

                    if pkg_resources.parse_version(dist.version) < \
                            pkg_resources.parse_version(newest):
                        found = True

        if found:
            self.assertTrue(False, MESSAGE)
Exemple #2
0
def get_fresh_updates(package_name="", version=""):
    userpath = expanduser("~")
    now = datetime.now()

    # Do we have a cache ?
    if isfile(userpath + "/.qyolk"):
        f = open(userpath + "/.qyolk", "r")
        cache = cPickle.load(f)
        check_time = now - timedelta(hours=24)
        if cache[0] > check_time:
            # fresh cache, use it
            return cache[1]

    # No cache, get updates and create the cache
    ret = []
    pypi = CheeseShop()
    dists = Distributions()
    for pkg in get_pkglist():
        for (dist, active) in dists.get_distributions(
                "all", pkg, dists.get_highest_installed(pkg)):
            (project_name,
             versions) = pypi.query_versions_pypi(dist.project_name)
            if versions:
                newest = get_highest_version(versions)
                if newest != dist.version:
                    if pkg_resources.parse_version(
                            dist.version) < pkg_resources.parse_version(
                                newest):
                        ret.append([project_name, dist.version, newest])

    f = open(userpath + "/.qyolk", "w")
    cPickle.dump([now, ret], f)

    return ret
Exemple #3
0
def get_fresh_updates(package_name="", version=""):
    userpath = expanduser("~")
    now = datetime.now()

    # Do we have a cache ?
    if isfile(userpath + "/.qyolk"):
        f = open(userpath + "/.qyolk", "r")
        cache = cPickle.load(f)
        check_time = now - timedelta(hours=24)
        if cache[0] > check_time:
            # fresh cache, use it
            return cache[1]

    # No cache, get updates and create the cache
    ret = []
    pypi = CheeseShop()
    dists = Distributions()
    for pkg in get_pkglist():
        for (dist, active) in dists.get_distributions("all", pkg, dists.get_highest_installed(pkg)):
            (project_name, versions) = pypi.query_versions_pypi(dist.project_name)
            if versions:
                newest = get_highest_version(versions)
                if newest != dist.version:
                    if pkg_resources.parse_version(dist.version) < pkg_resources.parse_version(newest):
                        ret.append([project_name, dist.version, newest])

    f = open(userpath + "/.qyolk", "w")
    cPickle.dump([now, ret], f)

    return ret
Exemple #4
0
def _updates(names, pypi, user_installs_only):
    """Return updates."""
    from multiprocessing.pool import ThreadPool

    exception = None

    def worker_function(pkg):
        dist = project_name = versions = None

        for (dist, active) in yolklib.get_distributions(
                'all', pkg, yolklib.get_highest_installed(pkg)):

            if exception:
                return

            width = terminal_width()
            if width:
                print(u'\rChecking package: {}…'.format(
                    dist.project_name).ljust(width),
                      end='',
                      file=sys.stderr)

            (project_name,
             versions) = pypi.query_versions_pypi(dist.project_name)

        return (pkg, dist, project_name, versions)

    import multiprocessing
    pool = ThreadPool(multiprocessing.cpu_count())

    try:
        results = pool.map(worker_function, names)
    except IOError as _exception:
        exception = _exception

    print('\r', end='', file=sys.stderr)

    if exception:
        raise YolkException(exception)

    for (pkg, dist, project_name, versions) in results:
        try:
            if (user_installs_only and
                    not dist.location.startswith(site.getusersitepackages())):
                continue
        except AttributeError:
            # Probably inside a virtualenv.
            pass

        if versions:
            # PyPI returns them in chronological order,
            # but who knows if its guaranteed in the API?
            # Make sure we grab the highest version:

            newest = yolklib.get_highest_version(versions)
            if newest != dist.version:
                # We may have newer than what PyPI knows about.
                if (pkg_resources.parse_version(dist.version) <
                        pkg_resources.parse_version(newest)):
                    yield (project_name, dist.version, newest)
    def test_latest_vulndb(self):
        dists = Distributions()
        pkg = 'vulndb'
        found = None
        pypi = CheeseShop(False)
        all_dists = dists.get_distributions('all', pkg,
                                            dists.get_highest_installed(pkg))

        for dist, active in all_dists:
            project_name, versions = pypi.query_versions_pypi(dist.project_name)

            if versions:
                # PyPI returns them in chronological order,
                # but who knows if its guaranteed in the API?
                # Make sure we grab the highest version:
                newest = get_highest_version(versions)
                if newest != dist.version:

                    #We may have newer than what PyPI knows about

                    if pkg_resources.parse_version(dist.version) < \
                    pkg_resources.parse_version(newest):
                        found = True

        if found:
            self.assertTrue(False, MESSAGE)
Exemple #6
0
    def query_metadata(self):
        """
        Get package metadata from PyPI

        :returns: metadata text

        """

        if self.version:
            return self.pypi.release_data(self.package_name, self.version)
        else:
            (pn, vers) = self.pypi.query_versions_pypi(self.package_name)
            return self.pypi.release_data(self.package_name, get_highest_version(vers))
Exemple #7
0
    def query_metadata(self):
        """
        Get package metadata from PyPI

        :returns: metadata text

        """

        if self.version:
            return self.pypi.release_data(self.package_name, self.version)
        else:
            (pn, vers) = self.pypi.query_versions_pypi(self.package_name)
            return self.pypi.release_data(self.package_name,
                                          get_highest_version(vers))
Exemple #8
0
def get_fresh_updates(package_name="", version=""):
    ret = []
    pypi = CheeseShop()
    for pkg in get_pkglist():
        for (dist, active) in get_distributions("all", pkg,
                                                get_highest_installed(pkg)):
            (project_name,
             versions) = pypi.query_versions_pypi(dist.project_name)
            if versions:
                newest = get_highest_version(versions)
                if newest != dist.version:
                    if pkg_resources.parse_version(
                            dist.version) < pkg_resources.parse_version(
                                newest):
                        ret.append([project_name, dist.version, newest])

    return ret
    def __check_pypi(self, name, current):
        """
        Queries PyPi for updates
        """
        (package, versions) = self.pypi.query_versions_pypi(name)

        if versions:
            newest = get_highest_version(versions)
            if newest != current:
                if parse_version(current) < parse_version(newest):
                    print " * Updates for %s are available. You have %s and the latest is %s." % (
                        package,
                        current,
                        newest,
                    )
                else:
                    print " * No updates are available for %s." % (package)
            Update.objects.create(package=package, installed=current, available=newest)
Exemple #10
0
    def show_updates(self):
        """
        Check installed packages for available updates on PyPI

        @param project_name: optional package name to check; checks every
                             installed pacakge if none specified
        @type project_name: string

        @returns: None
        """
        dists = Distributions()
        if self.project_name:
            #Check for a single package
            pkg_list = [self.project_name]
        else:
            #Check for every installed package
            pkg_list = get_pkglist()
        found = None
        for pkg in pkg_list:
            for (dist, active) in dists.get_distributions("all", pkg,
                    dists.get_highest_installed(pkg)):
                (project_name, versions) = \
                        self.pypi.query_versions_pypi(dist.project_name)
                if versions:

                    #PyPI returns them in chronological order,
                    #but who knows if its guaranteed in the API?
                    #Make sure we grab the highest version:

                    newest = get_highest_version(versions)
                    if newest != dist.version:

                        #We may have newer than what PyPI knows about

                        if pkg_resources.parse_version(dist.version) < \
                            pkg_resources.parse_version(newest):
                            found = True
                            print " %s %s (%s)" % (project_name, dist.version,
                                    newest)
        if not found and self.project_name:
            self.logger.info("You have the latest version installed.")
        elif not found:
            self.logger.info("No newer packages found at The Cheese Shop")
        return 0
Exemple #11
0
    def show_updates(self):
        """
        Check installed packages for available updates on PyPI

        @param project_name: optional package name to check; checks every
                             installed pacakge if none specified
        @type project_name: string

        @returns: None
        """
        dists = Distributions()
        if self.project_name:
            #Check for a single package
            pkg_list = [self.project_name]
        else:
            #Check for every installed package
            pkg_list = get_pkglist()
        found = None
        for pkg in pkg_list:
            for (dist, active) in dists.get_distributions(
                    "all", pkg, dists.get_highest_installed(pkg)):
                (project_name, versions) = \
                        self.pypi.query_versions_pypi(dist.project_name)
                if versions:

                    #PyPI returns them in chronological order,
                    #but who knows if its guaranteed in the API?
                    #Make sure we grab the highest version:

                    newest = get_highest_version(versions)
                    if newest != dist.version:

                        #We may have newer than what PyPI knows about

                        if pkg_resources.parse_version(dist.version) < \
                            pkg_resources.parse_version(newest):
                            found = True
                            print " %s %s (%s)" % (project_name, dist.version,
                                                   newest)
        if not found and self.project_name:
            self.logger.info("You have the latest version installed.")
        elif not found:
            self.logger.info("No newer packages found at The Cheese Shop")
        return 0
Exemple #12
0
    def do_ebuild(self):
        """
        Get SRC_URI using PyPI and attempt to create ebuild

        :returns: tuple with exit code and pkg_resources requirement

        """
        #Get proper case for project name:
        (self.package_name,
         versions) = self.pypi.query_versions_pypi(self.package_name)

        if not versions:
            log.error("No package %s on PyPi." % self.package_name)
            return

        if self.version and (self.version not in versions):
            log.error("No package %s for version %s on PyPi." %
                      (self.package_name, self.version))
            return
        else:
            self.version = get_highest_version(versions)

        # TODO: self.options.uri only for first ebuild
        # TODO: make find_uri method configurable
        download_url = self.find_uri()

        log.info('Generating ebuild: %s %s', self.package_name, self.version)
        log.debug('URI from PyPi: %s', download_url)

        self.options.configs['argparse']['uri'] = download_url
        self.options.configs['argparse']['up_pn'] = self.package_name
        self.options.configs['argparse']['up_pv'] = self.version

        ebuild = Ebuild(self.options)
        ebuild.set_metadata(self.query_metadata())

        if self.options.command == 'echo':
            ebuild.print_formatted()
        else:
            ebuild.create()
        return ebuild.requires
Exemple #13
0
    def do_ebuild(self):
        """
        Get SRC_URI using PyPI and attempt to create ebuild

        :returns: tuple with exit code and pkg_resources requirement

        """
        #Get proper case for project name:
        (self.package_name, versions) = self.pypi.query_versions_pypi(self.package_name)

        if not versions:
            log.error("No package %s on PyPi." % self.package_name)
            return

        if self.version and (self.version not in versions):
            log.error("No package %s for version %s on PyPi." % (self.package_name, self.version))
            return
        else:
            self.version = get_highest_version(versions)

        # TODO: self.options.uri only for first ebuild
        # TODO: make find_uri method configurable
        download_url = self.find_uri()

        log.info('Generating ebuild: %s %s', self.package_name, self.version)
        log.debug('URI from PyPi: %s', download_url)

        self.options.configs['argparse']['uri'] = download_url
        self.options.configs['argparse']['up_pn'] = self.package_name
        self.options.configs['argparse']['up_pv'] = self.version

        ebuild = Ebuild(self.options)
        ebuild.set_metadata(self.query_metadata())

        if self.options.command == 'echo':
            ebuild.print_formatted()
        else:
            ebuild.create()
        return ebuild.requires
Exemple #14
0
def _updates(names, pypi, user_installs_only):
    """Return updates."""
    from multiprocessing.pool import ThreadPool

    exception = None

    def worker_function(pkg):
        for (dist, active) in yolklib.get_distributions(
                'all', pkg,
                yolklib.get_highest_installed(pkg)):

            if exception:
                return

            width = terminal_width()
            if width:
                print('\rChecking {}'.format(dist.project_name).ljust(width),
                      end='',
                      file=sys.stderr)

            (project_name, versions) = pypi.query_versions_pypi(
                dist.project_name)
        return (pkg, dist, project_name, versions)

    import multiprocessing
    pool = ThreadPool(multiprocessing.cpu_count())

    try:
        results = pool.map(worker_function, names)
    except IOError as _exception:
        exception = _exception

    print('\r', end='', file=sys.stderr)

    if exception:
        raise YolkException(exception)

    for (pkg, dist, project_name, versions) in results:
        try:
            if (
                user_installs_only and
                not dist.location.startswith(site.getusersitepackages())
            ):
                continue
        except AttributeError:
            # Probably inside a virtualenv.
            pass

        if versions:
            # PyPI returns them in chronological order,
            # but who knows if its guaranteed in the API?
            # Make sure we grab the highest version:

            newest = yolklib.get_highest_version(versions)
            if newest != dist.version:
                # We may have newer than what PyPI knows about.
                if (
                    pkg_resources.parse_version(dist.version) <
                    pkg_resources.parse_version(newest)
                ):
                    yield (project_name, dist.version, newest)