예제 #1
0
파일: export.py 프로젝트: sigiesec/conan
def cmd_export(conanfile_path, name, version, user, channel, keep_source,
               output, client_cache):
    """ Export the recipe
    param conanfile_path: the original source directory of the user containing a
                       conanfile.py
    param user: user under this package will be exported
    param channel: string (stable, testing,...)
    """
    logger.debug("Exporting %s" % conanfile_path)

    conan_linter(conanfile_path, output)
    conanfile = _load_export_conanfile(conanfile_path, output, name, version)
    conan_ref = ConanFileReference(conanfile.name, conanfile.version, user,
                                   channel)
    conan_ref_str = str(conan_ref)
    # Maybe a platform check could be added, but depends on disk partition
    refs = search_recipes(client_cache, conan_ref_str, ignorecase=True)
    if refs and conan_ref not in refs:
        raise ConanException(
            "Cannot export package with same name but different case\n"
            "You exported '%s' but already existing '%s'" %
            (conan_ref_str, " ".join(str(s) for s in refs)))
    output = ScopedOutput(str(conan_ref), output)
    with client_cache.conanfile_write_lock(conan_ref):
        _export_conanfile(conanfile_path, output, client_cache, conanfile,
                          conan_ref, keep_source)
예제 #2
0
파일: export.py 프로젝트: mattgodbolt/conan
def cmd_export(conanfile_path, conanfile, reference, keep_source, output,
               client_cache, plugin_manager):
    """ Export the recipe
    param conanfile_path: the original source directory of the user containing a
                       conanfile.py
    """
    plugin_manager.execute("pre_export",
                           conanfile=conanfile,
                           conanfile_path=conanfile_path,
                           reference=reference)
    logger.debug("Exporting %s" % conanfile_path)
    output.highlight("Exporting package recipe")

    conan_linter(conanfile_path, output)
    # Maybe a platform check could be added, but depends on disk partition
    conan_ref_str = str(reference)
    refs = search_recipes(client_cache, conan_ref_str, ignorecase=True)
    if refs and reference not in refs:
        raise ConanException(
            "Cannot export package with same name but different case\n"
            "You exported '%s' but already existing '%s'" %
            (conan_ref_str, " ".join(str(s) for s in refs)))

    with client_cache.conanfile_write_lock(reference):
        _export_conanfile(conanfile_path, conanfile.output, client_cache,
                          conanfile, reference, keep_source)
    conanfile_cache_path = client_cache.conanfile(reference)
    plugin_manager.execute("post_export",
                           conanfile=conanfile,
                           conanfile_path=conanfile_cache_path,
                           reference=reference)
예제 #3
0
    def _collects_refs_to_upload(self, package_id, reference_or_pattern,
                                 confirm):
        """ validate inputs and compute the refs (without revisions) to be uploaded
        """
        if package_id and not check_valid_ref(reference_or_pattern,
                                              strict_mode=False):
            raise ConanException(
                "-p parameter only allowed with a valid recipe reference, "
                "not with a pattern")

        if package_id or check_valid_ref(reference_or_pattern):
            # Upload package
            ref = ConanFileReference.loads(reference_or_pattern)
            if ref.revision and not self._cache.config.revisions_enabled:
                raise ConanException(
                    "Revisions not enabled in the client, specify a "
                    "reference without revision")
            refs = [
                ref,
            ]
            confirm = True
        else:
            refs = search_recipes(self._cache, reference_or_pattern)
            if not refs:
                raise NotFoundException(
                    ("No packages found matching pattern '%s'" %
                     reference_or_pattern))
        return refs, confirm
예제 #4
0
    def search_recipes(self, pattern, remote_name=None, case_sensitive=False):
        ignorecase = not case_sensitive

        references = OrderedDict()
        if not remote_name:
            references[None] = search_recipes(self._client_cache, pattern,
                                              ignorecase)
            return references

        if remote_name == 'all':
            remotes = self._registry.remotes
            # We have to check if there is a remote called "all"
            # Deprecate: 2.0 can remove this check
            if 'all' not in (r.name for r in remotes):
                for remote in remotes:
                    refs = self._remote_manager.search_recipes(
                        remote, pattern, ignorecase)
                    if refs:
                        references[remote.name] = refs
                return references
        # single remote
        remote = self._registry.remote(remote_name)
        refs = self._remote_manager.search_recipes(remote, pattern, ignorecase)
        references[remote.name] = refs
        return references
예제 #5
0
파일: export.py 프로젝트: zhuhaow/conan
def cmd_export(conanfile_path, conanfile, reference, keep_source, output,
               client_cache):
    """ Export the recipe
    param conanfile_path: the original source directory of the user containing a
                       conanfile.py
    """
    logger.debug("Exporting %s" % conanfile_path)
    output.highlight("Exporting package recipe")

    conan_linter(conanfile_path, output)
    for field in ["url", "license", "description"]:
        field_value = getattr(conanfile, field, None)
        if not field_value:
            output.warn("Conanfile doesn't have '%s'.\n"
                        "It is recommended to add it as attribute" % field)

    conan_ref_str = str(reference)
    # Maybe a platform check could be added, but depends on disk partition
    refs = search_recipes(client_cache, conan_ref_str, ignorecase=True)
    if refs and reference not in refs:
        raise ConanException(
            "Cannot export package with same name but different case\n"
            "You exported '%s' but already existing '%s'" %
            (conan_ref_str, " ".join(str(s) for s in refs)))

    with client_cache.conanfile_write_lock(reference):
        _export_conanfile(conanfile_path, conanfile.output, client_cache,
                          conanfile, reference, keep_source)
예제 #6
0
 def _resolve_local(self, search_ref, version_range):
     local_found = search_recipes(self._client_cache, search_ref)
     if local_found:
         resolved_version = self._resolve_version(version_range,
                                                  local_found)
         if resolved_version:
             return resolved_version
예제 #7
0
 def _resolve_local(self, search_ref, version_range):
     local_found = search_recipes(self._cache, search_ref)
     local_found = [
         ref for ref in local_found if ref.user == search_ref.user
         and ref.channel == search_ref.channel
     ]
     if local_found:
         return self._resolve_version(version_range, local_found)
예제 #8
0
파일: export.py 프로젝트: yfxu1990/conan
def check_casing_conflict(cache, ref):
    # Check for casing conflict
    # Maybe a platform check could be added, but depends on disk partition
    refs = search_recipes(cache, ref, ignorecase=True)
    if refs and ref not in [r.copy_clear_rev() for r in refs]:
        raise ConanException("Cannot export package with same name but different case\n"
                             "You exported '%s' but already existing '%s'"
                             % (str(ref), " ".join(str(s) for s in refs)))
예제 #9
0
    def case_insensitive_test(self):
        with chdir(self.paths.store):
            root_folder2 = "sdl/1.5/lasote/stable"
            conan_ref2 = ConanFileReference.loads("sdl/1.5@lasote/stable")
            os.makedirs("%s/%s" % (root_folder2, EXPORT_FOLDER))

            root_folder3 = "assimp/0.14/phil/testing"
            conan_ref3 = ConanFileReference.loads("assimp/0.14@phil/testing")
            os.makedirs("%s/%s" % (root_folder3, EXPORT_FOLDER))

            root_folder4 = "sdl/2.10/lasote/stable"
            conan_ref4 = ConanFileReference.loads("sdl/2.10@lasote/stable")
            os.makedirs("%s/%s" % (root_folder4, EXPORT_FOLDER))

            root_folder5 = "SDL_fake/1.10/lasote/testing"
            conan_ref5 = ConanFileReference.loads(
                "SDL_fake/1.10@lasote/testing")
            os.makedirs("%s/%s" % (root_folder5, EXPORT_FOLDER))
            # Case insensitive searches

            reg_conans = sorted(
                [str(_reg) for _reg in search_recipes(self.paths, "*")])
            self.assertEqual(reg_conans, [
                str(conan_ref5),
                str(conan_ref3),
                str(conan_ref2),
                str(conan_ref4)
            ])

            reg_conans = sorted([
                str(_reg)
                for _reg in search_recipes(self.paths, pattern="sdl*")
            ])
            self.assertEqual(
                reg_conans,
                [str(conan_ref5),
                 str(conan_ref2),
                 str(conan_ref4)])

            # Case sensitive search
            self.assertEqual(
                str(
                    search_recipes(self.paths,
                                   pattern="SDL*",
                                   ignorecase=False)[0]), str(conan_ref5))
예제 #10
0
파일: export.py 프로젝트: sshyran/conan
def check_casing_conflict(cache, ref):
    # Check for casing conflict
    # Maybe a platform check could be added, but depends on disk partition
    refs = search_recipes(cache, ref, ignorecase=True)
    refs2 = [ConanFileReference(r.name, r.version, r.user if ref.user else None,
                                r.channel if ref.channel else None, validate=False) for r in refs]

    if refs and ref not in refs2:
        raise ConanException("Cannot export package with same name but different case\n"
                             "You exported '%s' but already existing '%s'"
                             % (str(ref), " ".join(str(s) for s in refs)))
예제 #11
0
    def pattern_test(self):
        refs = [
            "opencv/2.4.%s@lasote/testing" % ref for ref in ("1", "2", "3")
        ]
        refs = [ConanFileReference.loads(ref) for ref in refs]
        for ref in refs:
            root_folder = str(ref).replace("@", "/")
            reg1 = "%s/%s" % (root_folder, EXPORT_FOLDER)
            os.makedirs(reg1)

        recipes = search_recipes(self.paths, "opencv/*@lasote/testing")
        self.assertEqual(recipes, refs)
예제 #12
0
파일: service.py 프로젝트: mathieu/conan
 def search(self, pattern=None, ignorecase=True):
     """ Get all the info about any package
         Attributes:
             pattern = wildcards like opencv/*
     """
     references = search_recipes(self._paths, pattern, ignorecase)
     filtered = []
     # Filter out restricted items
     for conan_ref in references:
         try:
             self._authorizer.check_read_conan(self._auth_user, conan_ref)
             filtered.append(conan_ref)
         except ForbiddenException:
             pass
     return filtered
예제 #13
0
    def upload(self, recorder, reference_or_pattern, package_id=None, all_packages=None,
               force=False, confirm=False, retry=0, retry_wait=0, skip_upload=False,
               integrity_check=False, no_overwrite=None, remote_name=None,
               query=None):
        """If package_id is provided, conan_reference_or_pattern is a ConanFileReference"""

        if package_id and not _is_a_reference(reference_or_pattern):
            raise ConanException("-p parameter only allowed with a valid recipe reference, "
                                 "not with a pattern")
        t1 = time.time()
        if package_id or _is_a_reference(reference_or_pattern):  # Upload package
            ref = ConanFileReference.loads(reference_or_pattern)
            references = [ref, ]
            confirm = True
        else:
            references = search_recipes(self._client_cache, reference_or_pattern)
            if not references:
                raise NotFoundException(("No packages found matching pattern '%s'" %
                                         reference_or_pattern))

        for conan_ref in references:
            upload = True
            if not confirm:
                msg = "Are you sure you want to upload '%s'?" % str(conan_ref)
                upload = self._user_io.request_boolean(msg)
            if upload:
                try:
                    conanfile_path = self._client_cache.conanfile(conan_ref)
                    conan_file = self._loader.load_class(conanfile_path)
                except NotFoundException:
                    raise NotFoundException(("There is no local conanfile exported as %s" %
                                             str(conan_ref)))
                if all_packages:
                    packages_ids = self._client_cache.conan_packages(conan_ref)
                elif query:
                    packages = search_packages(self._client_cache, conan_ref, query)
                    packages_ids = list(packages.keys())
                elif package_id:
                    packages_ids = [package_id, ]
                else:
                    packages_ids = []
                self._upload(conan_file, conan_ref, force, packages_ids, retry, retry_wait,
                             skip_upload, integrity_check, no_overwrite, remote_name, recorder)

        logger.debug("====> Time manager upload: %f" % (time.time() - t1))
예제 #14
0
    def search_recipes(self, pattern, remote_name=None, case_sensitive=False):
        ignorecase = not case_sensitive

        references = OrderedDict()
        if not remote_name:
            references[None] = search_recipes(self._cache, pattern, ignorecase)
            return references

        if remote_name == 'all':
            # We have to check if there is a remote called "all"
            # Deprecate: 2.0 can remove this check
            if 'all' not in self._remotes:
                for remote in self._remotes.values():
                    refs = self._remote_manager.search_recipes(
                        remote, pattern, ignorecase)
                    if refs:
                        references[remote.name] = sorted(refs)
                return references
        # single remote
        remote = self._remotes[remote_name]
        refs = self._remote_manager.search_recipes(remote, pattern, ignorecase)
        references[remote.name] = sorted(refs)
        return references
예제 #15
0
파일: remover.py 프로젝트: mathieu/conan
    def remove(self,
               pattern,
               remote,
               src=None,
               build_ids=None,
               package_ids_filter=None,
               force=False,
               packages_query=None,
               outdated=False):
        """ Remove local/remote conans, package folders, etc.
        @param src: Remove src folder
        @param pattern: it could be OpenCV* or OpenCV or a ConanFileReference
        @param build_ids: Lists with ids or empty for all. (Its a filter)
        @param package_ids_filter: Lists with ids or empty for all. (Its a filter)
        @param force: if True, it will be deleted without requesting anything
        @param packages_query: Only if src is a reference. Query settings and options
        """

        if remote and (build_ids is not None or src):
            raise ConanException(
                "Remotes don't have 'build' or 'src' folder, just packages")

        if remote:
            remote = self._registry.remote(remote)
            references = self._remote_manager.search_recipes(remote, pattern)
        else:
            references = search_recipes(self._client_cache, pattern)
        if not references:
            self._user_io.out.warn("No package recipe matches '%s'" %
                                   str(pattern))
            return

        deleted_refs = []
        for reference in references:
            assert isinstance(reference, ConanFileReference)
            package_ids = package_ids_filter
            if packages_query or outdated:
                # search packages
                if remote:
                    packages = self._remote_manager.search_packages(
                        remote, reference, packages_query)
                else:
                    packages = search_packages(self._client_cache, reference,
                                               packages_query)
                if outdated:
                    if remote:
                        recipe_hash = self._remote_manager.get_conan_manifest(
                            reference, remote).summary_hash
                    else:
                        recipe_hash = self._client_cache.load_manifest(
                            reference).summary_hash
                    packages = filter_outdated(packages, recipe_hash)
                if package_ids_filter:
                    package_ids = [
                        p for p in packages if p in package_ids_filter
                    ]
                else:
                    package_ids = list(packages.keys())
                if not package_ids:
                    self._user_io.out.warn(
                        "No matching packages to remove for %s" %
                        str(reference))
                    continue

            if self._ask_permission(reference, src, build_ids, package_ids,
                                    force):
                deleted_refs.append(reference)
                if remote:
                    self._remote_remove(reference, package_ids, remote)
                else:
                    deleted_refs.append(reference)
                    self._local_remove(reference, src, build_ids, package_ids)

        if not remote:
            self._client_cache.delete_empty_dirs(deleted_refs)
예제 #16
0
    def remove(self,
               pattern,
               remote_name,
               src=None,
               build_ids=None,
               package_ids_filter=None,
               force=False,
               packages_query=None,
               outdated=False):
        """ Remove local/remote conans, package folders, etc.
        @param src: Remove src folder
        @param pattern: it could be OpenCV* or OpenCV or a ConanFileReference
        @param build_ids: Lists with ids or empty for all. (Its a filter)
        @param package_ids_filter: Lists with ids or empty for all. (Its a filter)
        @param force: if True, it will be deleted without requesting anything
        @param packages_query: Only if src is a reference. Query settings and options
        """

        if remote_name and (build_ids is not None or src):
            raise ConanException(
                "Remotes don't have 'build' or 'src' folder, just packages")

        is_reference = check_valid_ref(pattern)
        input_ref = ConanFileReference.loads(pattern) if is_reference else None

        if not input_ref and packages_query is not None:
            raise ConanException(
                "query parameter only allowed with a valid recipe "
                "reference as the search pattern.")

        if input_ref and package_ids_filter and not input_ref.revision:
            for package_id in package_ids_filter:
                if "#" in package_id:
                    raise ConanException(
                        "Specify a recipe revision if you specify a package "
                        "revision")

        if remote_name:
            remote = self._remotes[remote_name]
            if input_ref:
                if not self._cache.config.revisions_enabled and input_ref.revision:
                    raise ConanException(
                        "Revisions not enabled in the client, cannot remove "
                        "revisions in the server")
                refs = [input_ref]
            else:
                refs = self._remote_manager.search_recipes(remote, pattern)
        else:
            if input_ref:
                refs = []
                if self._cache.installed_as_editable(input_ref):
                    raise ConanException(
                        self._message_removing_editable(input_ref))
                if not self._cache.package_layout(input_ref).recipe_exists():
                    raise RecipeNotFoundException(
                        input_ref,
                        print_rev=self._cache.config.revisions_enabled)
                refs.append(input_ref)
            else:
                refs = search_recipes(self._cache, pattern)
                if not refs:
                    self._user_io.out.warn("No package recipe matches '%s'" %
                                           str(pattern))
                    return

        if input_ref and not input_ref.revision:
            # Ignore revisions for deleting if the input was not with a revision
            # (Removing all the recipe revisions from a reference)
            refs = [r.copy_clear_rev() for r in refs]

        deleted_refs = []
        for ref in refs:
            assert isinstance(ref, ConanFileReference)
            package_layout = self._cache.package_layout(ref)
            package_ids = package_ids_filter
            if packages_query or outdated:
                # search packages
                if remote_name:
                    packages = self._remote_manager.search_packages(
                        remote, ref, packages_query)
                else:
                    packages = search_packages(package_layout, packages_query)
                if outdated:
                    if remote_name:
                        manifest, ref = self._remote_manager.get_recipe_manifest(
                            ref, remote)
                        recipe_hash = manifest.summary_hash
                    else:
                        recipe_hash = package_layout.recipe_manifest(
                        ).summary_hash
                    packages = filter_outdated(packages, recipe_hash)
                if package_ids_filter:
                    package_ids = [
                        p for p in packages if p in package_ids_filter
                    ]
                else:
                    package_ids = list(packages.keys())
                if not package_ids:
                    self._user_io.out.warn(
                        "No matching packages to remove for %s" %
                        ref.full_str())
                    continue

            if self._ask_permission(ref, src, build_ids, package_ids, force):
                try:
                    if remote_name:
                        self._remote_remove(ref, package_ids, remote)
                    else:
                        self._local_remove(ref, src, build_ids, package_ids)
                except NotFoundException:
                    # If we didn't specify a pattern but a concrete ref, fail if there is no
                    # ref to remove
                    if input_ref:
                        raise
                else:
                    deleted_refs.append(ref)

        if not remote_name:
            self._cache.delete_empty_dirs(deleted_refs)