Exemplo n.º 1
0
def idn_ascii_to_puny(hostname):
    """ Convert domain name to Punycode (RFC3492). Hostname can be instance of string or Unicode """
    if hostname is None:
        return None
    else:
        hostname = ustr(hostname)
        return ustr(hostname.encode('idna'))
Exemplo n.º 2
0
    def write_log(self, s):

        log_name = self.cfg["logFile"] or "/var/log/up2date"
        log_file = open(log_name, 'a')
        msg = u"%s %s\n" % (ustr(self.log_info), ustr(s))
        log_file.write(sstr(msg))
        log_file.flush()
        log_file.close()
Exemplo n.º 3
0
 def __init__(self, args):
     Error.__init__(self, "")
     self.args = args
     for key in self.args.keys():
         self.args[key] = ustr(self.args[key])
         self.value = self.value + "%s failed because of %s\n" % (
             key, self.args[key])
     self.data = self.args
Exemplo n.º 4
0
def get_hal_system_and_smbios():
    try:
        if using_gudev:
            props = get_computer_info()
        else:
            computer = get_hal_computer()
            props = computer.GetAllProperties()
    except Exception:
        log = up2dateLog.initLog()
        msg = "Error reading system and smbios information: %s\n" % (
            sys.exc_info()[1])
        log.log_debug(msg)
        return {}
    system_and_smbios = {}

    for key in props:
        if key.startswith('system'):
            system_and_smbios[ustr(key)] = ustr(props[key])

    system_and_smbios.update(get_smbios())
    return system_and_smbios
Exemplo n.º 5
0
    def __init__(self, channel, opts):
        super(SpacewalkRepo, self).__init__(ustr(channel['label']),
                                            opts.get('conf'))
        # dnf stuff
        self.name = ustr(channel['name'])
        self.baseurl = [url + '/GET-REQ/' + self.id for url in channel['url']]
        self.sslcacert = opts.get('sslcacert')
        self.proxy = opts.get('proxy')
        try:
            self.gpgkey = get_gpg_key_urls(channel['gpg_key_url'])
        except InvalidGpgKeyLocation as e:
            logger.warning(GPG_KEY_REJECTED, dnf.i18n.ucd(e))
            self.gpgkey = []
        if channel['version'] != opts.get('cached_version'):
            self.metadata_expire = 1

        # spacewalk stuff
        self.login_info = opts.get('login_info')
        self.keepalive = 0
        self.bandwidth = 0
        self.retries = 1
        self.throttle = 0
        self.timeout = opts.get('timeout')
        self.gpgcheck = opts.get('gpgcheck')
        self.force_http = opts.get('force_http')

        if opts.get('enabled'):
            self.enable()
        else:
            self.disable()

        if hasattr(self, 'set_http_headers'):
            # dnf > 4.0.9  on RHEL 8, Fedora 29/30
            http_headers = self.create_http_headers()
            if http_headers:
                self.set_http_headers(http_headers)
Exemplo n.º 6
0
    def log_me(self, *args):
        """General logging function.
        Eg: log_me("I am a banana.")

        """
        self.log_info = "[%s] %s" % (time.ctime(time.time()), self.app)
        s = u""
        for i in args:
            # we really need unicode(str(i)) here, because i can be anything
            # from string or int to list, dict or even class
            i = ustr(str(i))
            s += i
        if self.cfg["debug"] > 1:
            print(s)
        self.write_log(s)
Exemplo n.º 7
0
def _encode_characters(*args):
    """ All the data we gathered from dmi, bios, gudev are in utf-8,
            we need to convert characters beyond ord(127) - e.g \xae to unicode.
        """
    result = []
    for item in args:
        item_type = type(item)
        if item_type == StringType:
            item = ustr(item)
        elif item_type == TupleType:
            item = tuple(_encode_characters(i) for i in item)
        elif item_type == ListType:
            item = [_encode_characters(i) for i in item]
        elif item_type == DictType or item_type == DictionaryType:
            item = dict([(_encode_characters(name, val))
                         for name, val in item.items()])
        # else: numbers or UnicodeType - are safe
        result.append(item)
    if len(result) == 1:
        return result[0]
    else:
        return tuple(result)
Exemplo n.º 8
0
 def __init__(self, errmsg):
     errmsg = ustr(errmsg)
     PmBaseError.__init__(self, errmsg)
     self.value = 'rhn-plugin: ' + self.premsg + errmsg
     self.log = up2dateLog.initLog()
Exemplo n.º 9
0
 def __init__(self, msg):
     msg = ustr(msg)
     self.value = self.premsg + msg
Exemplo n.º 10
0
 def testConfigString(self):
     "Verify that Config loads a string as a string"
     cfg = config.initUp2dateConfig(test_up2date)
     assert type(cfg['systemIdPath']) == type(ustr(''))