How to use the pulp.common.util.encode_unicode function in PuLP

To help you get started, we’ve selected a few PuLP examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pulp / pulp_rpm / plugins / pulp_rpm / repo_auth / repo_cert_utils.py View on Github external
        @type  file_prefix: str

        @param cert_dir: absolute path to the location in which the cert bundle should
                         be written; cannot be None
        @type  cert_dir: str

        @param bundle: cert bundle (see module docs for more information on format)
        @type  bundle: dict {str, str}

        @raises ValueError: if bundle is invalid (see validate_cert_bundle)

        @return: mapping of cert bundle item (see module docs) to the absolute path
                 to where it is stored on disk
        '''
        file_prefix = encode_unicode(file_prefix)
        cert_dir = encode_unicode(cert_dir)

        WRITE_LOCK.acquire()

        try:
            # Create the cert directory if it doesn't exist
            if not os.path.exists(cert_dir):
                os.makedirs(cert_dir)

            # For each item in the cert bundle, save it to disk using the given prefix
            # to identify the type of bundle it belongs to. If the value is None, the
            # item is being deleted.
            cert_files = {}
            for key, value in bundle.items():
                filename = os.path.join(cert_dir, '%s.%s' % (file_prefix, key))

                try:
github pulp / pulpcore / server / pulp / server / webservices / views / util.py View on Github external
"""
    Recursively traverse any input structures and ensure any strings are
    encoded as utf-8.

    :param input: input data

    :return: input data with strings encoded as utf-8
    """

    if isinstance(input, (list, set, tuple)):
        return [_ensure_input_encoding(i) for i in input]
    if isinstance(input, dict):
        return dict((_ensure_input_encoding(k), _ensure_input_encoding(v))
                    for k, v in input.items())
    try:
        return encode_unicode(decode_unicode(input))
    except (UnicodeDecodeError, UnicodeEncodeError):
        raise InputEncodingError(input), None, sys.exc_info()[2]
github pulp / pulp / rpm-support / src / pulp_rpm / repo_auth / repo_cert_utils.py View on Github external
        @type  file_prefix: str

        @param cert_dir: absolute path to the location in which the cert bundle should
                         be written; cannot be None
        @type  cert_dir: str

        @param bundle: cert bundle (see module docs for more information on format)
        @type  bundle: dict {str, str}

        @raises ValueError: if bundle is invalid (see validate_cert_bundle)

        @return: mapping of cert bundle item (see module docs) to the absolute path
                 to where it is stored on disk
        '''
        file_prefix = encode_unicode(file_prefix)
        cert_dir = encode_unicode(cert_dir)

        WRITE_LOCK.acquire()

        try:
            # Create the cert directory if it doesn't exist
            if not os.path.exists(cert_dir):
                os.makedirs(cert_dir)

            # For each item in the cert bundle, save it to disk using the given prefix
            # to identify the type of bundle it belongs to. If the value is None, the
            # item is being deleted.
            cert_files = {}
            for key, value in bundle.items():
                filename = os.path.join(cert_dir, '%s.%s' % (file_prefix, key))

                try:
github pulp / pulp / platform / src / pulp / server / api / synchronizers.py View on Github external
def add_packages_from_dir(self, dir, repo_id, skip=None):
        repo = self.repo_api._get_existing_repo(repo_id)
        added_packages = {}
        if "yum" not in repo['content_types']:
            return added_packages
        if not skip:
            skip = {}
        if not skip.has_key('packages') or skip['packages'] != 1:
            startTime = time.time()
            log.debug("Begin to add packages from %s into %s" % (encode_unicode(dir), encode_unicode(repo['id'])))
            unfiltered_pkglist = pulp.server.util.get_repo_packages(dir)
            # Process repo filters if any
            if repo['filters']:
                log.info("Repo filters : %s" % repo['filters'])
                whitelist_packages = self.repo_api.find_combined_whitelist_packages(repo['filters'])
                blacklist_packages = self.repo_api.find_combined_blacklist_packages(repo['filters'])
                log.info("combined whitelist packages = %s" % whitelist_packages)
                log.info("combined blacklist packages = %s" % blacklist_packages)
            else:
                whitelist_packages = []
                blacklist_packages = []

            package_list = self._find_filtered_package_list(unfiltered_pkglist, whitelist_packages, blacklist_packages, dst_repo_dir=self.repo_dir)
            log.debug("Processing %s potential packages" % (len(package_list)))
            for package in package_list:
                pkg_path = "%s/%s/%s/%s/%s/%s/%s" % (pulp.server.util.top_package_location(), package.name, package.version, \
github pulp / pulpcore / rpm-support / src / pulp_rpm / extension / admin / repo.py View on Github external
# Add a note to indicate this is a Puppet repository
        notes[constants.REPO_NOTE_KEY] = constants.REPO_NOTE_RPM

        try:
            importer_config = args_to_importer_config(kwargs)
            yum_distributor_config = args_to_yum_distributor_config(kwargs)
            iso_distributor_config = args_to_iso_distributor_config(kwargs)
        except InvalidConfig, e:
            self.prompt.render_failure_message(str(e))
            return

        # During create (but not update), if the relative path isn't specified
        # it is derived from the feed_url
        if 'relative_url' not in yum_distributor_config:
            if 'feed_url' in importer_config:
                url_parse = urlparse(encode_unicode(importer_config['feed_url']))

                if url_parse[2] in ('', '/'):
                    relative_path = '/' + repo_id
                else:
                    relative_path = url_parse[2]
                yum_distributor_config['relative_url'] = relative_path
            else:
                yum_distributor_config['relative_url'] = repo_id

        # Both http and https must be specified in the distributor config, so
        # make sure they are initially set here (default to only https)
        if 'http' not in yum_distributor_config and 'https' not in yum_distributor_config:
            yum_distributor_config['https'] = True
            yum_distributor_config['http'] = False

        # Make sure both are referenced
github pulp / pulp / platform / src / pulp / server / api / scheduled_sync.py View on Github external
def find_scheduled_task(id, method_name):
    """
    Look up a schedule task in the task sub-system for a given method
    @type id: str
    @param id: argument to the task
    @rtype: None or L{pulp.server.tasking.task.Task}
    @return: the sync task, None if no task is found
    """
    # NOTE this is very inefficient in the worst case: DO NOT CALL OFTEN!!
    # the number of sync tasks * (mean # arguments + mean # keyword arguments)
    for task in async.find_async(method_name=method_name):
        if task.args and encode_unicode(id) in task.args or \
                task.kwargs and encode_unicode(id) in task.kwargs.values():
            return task
    return None
github pulp / pulp_rpm / plugins / pulp_rpm / repo_auth / repo_cert_utils.py View on Github external
        @type  file_prefix: str

        @param cert_dir: absolute path to the location in which the cert bundle should
                         be written; cannot be None
        @type  cert_dir: str

        @param bundle: cert bundle (see module docs for more information on format)
        @type  bundle: dict {str, str}

        @raises ValueError: if bundle is invalid (see validate_cert_bundle)

        @return: mapping of cert bundle item (see module docs) to the absolute path
                 to where it is stored on disk
        '''
        file_prefix = encode_unicode(file_prefix)
        cert_dir = encode_unicode(cert_dir)

        WRITE_LOCK.acquire()

        try:
            # Create the cert directory if it doesn't exist
            if not os.path.exists(cert_dir):
                os.makedirs(cert_dir)

            # For each item in the cert bundle, save it to disk using the given prefix
            # to identify the type of bundle it belongs to. If the value is None, the
            # item is being deleted.
            cert_files = {}
            for key, value in bundle.items():
                filename = os.path.join(cert_dir, '%s.%s' % (file_prefix, key))

                try:
github pulp / pulp / server / pulp / server / webservices / controllers / base.py View on Github external
def _ensure_input_encoding(self, input):
        """
        Recursively traverse any input structures and ensure any strings are
        encoded as utf-8
        @param input: input data
        @return: input data with strings encoded as utf-8
        """
        if isinstance(input, (list, set, tuple)):
            return [self._ensure_input_encoding(i) for i in input]
        if isinstance(input, dict):
            return dict((self._ensure_input_encoding(k), self._ensure_input_encoding(v)) for k, v in input.items())
        try:
            return encode_unicode(decode_unicode(input))
        except (UnicodeDecodeError, UnicodeEncodeError):
            raise InputEncodingError(input), None, sys.exc_info()[2]
github pulp / pulp / platform / src / pulp / server / api / repo.py View on Github external
for pkg in pkgobjs:
            if pkg['id'] not in repo['packages']:
                log.debug("Attempted to remove a package<%s> that isn't part of repo[%s]" % (pkg["filename"], repoid))
                errors.append(pkg)
                continue
            repo['packages'].remove(pkg['id'])
            repo['package_count'] = repo['package_count'] - 1
            if repoid in pkg['repoids']:
                del pkg['repoids'][pkg['repoids'].index(repoid)]
                pkg_collection.save(pkg, safe=True)
            # Remove package from repo location on file system
            pkg_repo_path = pulp.server.util.get_repo_package_path(
                repo['relative_path'], pkg["filename"])
            if os.path.exists(encode_unicode(pkg_repo_path)):
                log.debug("Delete package %s at %s" % (pkg["filename"], pkg_repo_path))
                os.remove(encode_unicode(pkg_repo_path))
        self.collection.save(repo, safe=True)
        repo_path = os.path.join(
            pulp.server.util.top_repos_location(), repo['relative_path'])
        if not os.path.exists(encode_unicode(repo_path)):
            pulp.server.util.makedirs(encode_unicode(repo_path))
        return errors