Ejemplo n.º 1
0
def _handle_host_urls(repo, url_list, mirror_list_filename):
    """
    Handles the processing of the host URLs sent for a repo. If a mirror list file is
    needed, it will be created and saved to disk as part of this call. The repo
    object will be updated with the appropriate parameter for the repo URL.
    """

    if len(url_list) > 1:

        # The mirror list file isn't loaded; if this call was made as part of a
        # repo update the file should be written new given the URLs passed in
        mirror_list_file = MirrorListFile(mirror_list_filename)
        mirror_list_file.add_entries(url_list)
        mirror_list_file.save()

        repo['mirrorlist'] = 'file:' + mirror_list_filename
        repo['baseurl'] = None  # make sure to zero this out in case of an update

        log.info('Created mirrorlist for repo [%s] at [%s]' % (repo.id, mirror_list_filename))
    else:

        # On a repo update, the mirror list may have existed but is no longer used.
        # If we're in this block there shouldn't be a mirror list file for the repo,
        # so delete it if it's there.
        if os.path.exists(mirror_list_filename):
            os.remove(mirror_list_filename)

        repo['baseurl'] = url_list[0]
        repo['mirrorlist'] = None  # make sure to zero this out in case of an update

        log.info(
            'Configuring repo [%s] to use baseurl [%s]' % (decode_unicode(repo.id), url_list[0]))
Ejemplo n.º 2
0
def _handle_host_urls(repo, url_list, mirror_list_filename):
    """
    Handles the processing of the host URLs sent for a repo. If a mirror list file is
    needed, it will be created and saved to disk as part of this call. The repo
    object will be updated with the appropriate parameter for the repo URL.
    """

    if len(url_list) > 1:

        # The mirror list file isn't loaded; if this call was made as part of a
        # repo update the file should be written new given the URLs passed in
        mirror_list_file = MirrorListFile(mirror_list_filename)
        mirror_list_file.add_entries(url_list)
        mirror_list_file.save()

        repo['mirrorlist'] = 'file:' + mirror_list_filename
        repo['baseurl'] = None # make sure to zero this out in case of an update

        log.info('Created mirrorlist for repo [%s] at [%s]' % (repo.id, mirror_list_filename))
    else:

        # On a repo update, the mirror list may have existed but is no longer used.
        # If we're in this block there shouldn't be a mirror list file for the repo,
        # so delete it if it's there.
        if os.path.exists(mirror_list_filename):
            os.remove(mirror_list_filename)

        repo['baseurl'] = url_list[0]
        repo['mirrorlist'] = None # make sure to zero this out in case of an update

        log.info('Configuring repo [%s] to use baseurl [%s]' % (decode_unicode(repo.id), url_list[0]))
Ejemplo n.º 3
0
    def GET(self, event_listener_id):
        manager = manager_factory.event_listener_manager()

        event_listener_id = decode_unicode(event_listener_id)

        listener = manager.get(event_listener_id) # will raise MissingResource
        href = link.current_link_obj()
        listener.update(href)

        return self.ok(listener)
Ejemplo n.º 4
0
    def GET(self, event_listener_id):
        manager = manager_factory.event_listener_manager()

        event_listener_id = decode_unicode(event_listener_id)

        listener = manager.get(event_listener_id)  # will raise MissingResource
        href = link.current_link_obj()
        listener.update(href)

        return self.ok(listener)
Ejemplo n.º 5
0
 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]
Ejemplo n.º 6
0
 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]
Ejemplo n.º 7
0
def _create_repo(dir, groups=None, checksum_type=DEFAULT_CHECKSUM):
    if not groups:
        cmd = "createrepo --database --checksum %s --update %s " % (checksum_type, dir)
    else:
        try:
            cmd = "createrepo --database --checksum %s -g %s --update %s " % (checksum_type, groups, dir)
        except UnicodeDecodeError:
            groups = decode_unicode(groups)
            cmd = "createrepo --database --checksum %s -g %s --update %s " % (checksum_type, groups, dir)
    # shlex now can handle unicode strings as well
    cmd = encode_unicode(cmd)
    try:
        cmd = shlex.split(cmd.encode('ascii', 'ignore'))
    except:
        cmd = shlex.split(cmd)

    _LOG.info("started repo metadata update: %s" % (cmd))
    handle = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    return handle