Exemple #1
0
    def delete_dns_info(self, dns):
        if self.old_contents is None:
            # just log it, don't fail
            log.err("NamedManager old_contents is None")
            return

        real_path = os.path.realpath(self.resolvconf_path)
        save_file(real_path, self.old_contents)
        self.old_contents = None
Exemple #2
0
def get_wvdial_conf_file(conf, context, serial_port):
    """
    Returns the path of the generated wvdial.conf

    :param conf: `DialerConf` instance
    :param serial_port: The port to use
    :rtype: str
    """
    text = _generate_wvdial_conf(conf, context, serial_port)
    dirpath = tempfile.mkdtemp('', APP_NAME, '/tmp')
    path = tempfile.mkstemp('wvdial.conf', APP_NAME, dirpath, True)[1]
    save_file(path, text)
    return path
Exemple #3
0
    def test_save_file(self):
        """
        Tests that saving a random file works with ``save_file``
        """
        text = os.urandom(2000)
        path = '/tmp/file.foo'

        save_file(path, text)

        fobj = open(path, 'r')
        data = fobj.read()
        fobj.close()

        self.assertEqual(text, data)
        os.unlink(path)
Exemple #4
0
    def _generate_wvdial_ppp_options(self):
        if not self.conf.refuse_chap:
            wvdial_ppp_options = CHAP_TEMPLATE
        elif not self.conf.refuse_pap:
            wvdial_ppp_options = PAP_TEMPLATE
        else:
            # this could be a NOOP, but the user might have modified
            # the stock /etc/ppp/peers/wvdial file, so the safest option
            # is to overwrite with our known good options.
            wvdial_ppp_options = DEFAULT_TEMPLATE

        # There are some patched pppd implementations
        # Most systems offer 'replacedefaultroute', but not Fedora
        osobj = get_os_object()
        if hasattr(osobj, 'get_additional_wvdial_ppp_options'):
            wvdial_ppp_options += osobj.get_additional_wvdial_ppp_options()

        save_file(WVDIAL_PPPD_OPTIONS, wvdial_ppp_options)
Exemple #5
0
    def add_dns_info(self, dns):
        if self.old_contents is not None:
            # just log it, don't fail
            msg = "NamedManager old_contents not empty: %s"
            log.err(msg % self.old_contents)
            return

        # backup old data
        real_path = os.path.realpath(self.resolvconf_path)
        self.old_contents = get_file_data(real_path)
        # set new DNS data
        to_write = []
        if dns:
            to_write.append("# Generated by Wader")
            for d in dns:
                to_write.append("nameserver %s" % d)
            to_write.append('')

        save_file(real_path, '\n'.join(to_write))