Example #1
0
 def save(self):
     d = basedir.save_config_path(config_site, config_prog)
     # XXX
     f = file(os.path.join(d, 'trust'), 'w')
     for key in self.keys:
         print >> f, key
     f.close()
Example #2
0
def save_interface(interface):
    path = basedir.save_config_path(config_site, config_prog, 'user_overrides')
    path = os.path.join(path, escape(interface.uri))
    #print "Save to", path

    impl = minidom.getDOMImplementation()
    doc = impl.createDocument(XMLNS_IFACE, 'interface', None)

    root = doc.documentElement
    root.setAttributeNS(XMLNS_NAMESPACE, 'xmlns', XMLNS_IFACE)
    root.setAttribute('uri', interface.uri)

    if interface.stability_policy:
        root.setAttribute('stability-policy', str(interface.stability_policy))

    if interface.last_checked:
        root.setAttribute('last-checked', str(interface.last_checked))

    impls = interface.implementations.values()
    impls.sort()
    for impl in impls:
        add_impl(root, impl)

    doc.writexml(file(path + '.new', 'w'), addindent=" ", newl='\n')
    os.rename(path + '.new', path)
Example #3
0
    def save(self):
        from xml.dom import minidom
        import tempfile

        doc = minidom.Document()
        root = doc.createElementNS(XMLNS_TRUST, 'trusted-keys')
        root.setAttribute('xmlns', XMLNS_TRUST)
        doc.appendChild(root)

        for fingerprint in self.keys:
            keyelem = doc.createElementNS(XMLNS_TRUST, 'key')
            root.appendChild(keyelem)
            keyelem.setAttribute('fingerprint', fingerprint)
            for domain in self.keys[fingerprint]:
                domainelem = doc.createElementNS(XMLNS_TRUST, 'domain')
                domainelem.setAttribute('value', domain)
                keyelem.appendChild(domainelem)

        d = basedir.save_config_path(config_site, config_prog)
        fd, tmpname = tempfile.mkstemp(dir=d, prefix='trust-')
        tmp = os.fdopen(fd, 'wb')
        doc.writexml(tmp, indent="", addindent="  ", newl="\n")
        tmp.close()

        os.rename(tmpname, os.path.join(d, 'trustdb.xml'))
Example #4
0
    def import_new_interface(self, interface, new_xml):
        upstream_dir = basedir.save_config_path(config_site, config_prog,
                                                'interfaces')
        cached = os.path.join(upstream_dir, escape(interface.uri))

        if os.path.exists(cached):
            old_xml = file(cached).read()
            if old_xml == new_xml:
                debug("No change")
                return
            else:
                self.confirm_diff(old_xml, new_xml, interface.uri)

        stream = file(cached + '.new', 'w')
        stream.write(new_xml)
        stream.close()
        new_mtime = reader.check_readable(interface.uri, cached + '.new')
        assert new_mtime
        if interface.last_modified:
            if new_mtime < interface.last_modified:
                raise SafeException(
                    "New interface's modification time is before old "
                    "version!"
                    "\nOld time: " + pretty_time(interface.last_modified) +
                    "\nNew time: " + pretty_time(new_mtime) +
                    "\nRefusing update (leaving new copy as " + cached +
                    ".new)")
            if new_mtime == interface.last_modified:
                raise SafeException(
                    "Interface has changed, but modification time "
                    "hasn't! Refusing update.")
        os.rename(cached + '.new', cached)
        debug("Saved as " + cached)

        reader.update_from_cache(interface)
Example #5
0
	def save(self):
		from xml.dom import minidom
		import tempfile

		doc = minidom.Document()
		root = doc.createElementNS(XMLNS_TRUST, 'trusted-keys')
		root.setAttribute('xmlns', XMLNS_TRUST)
		doc.appendChild(root)

		for fingerprint in self.keys:
			keyelem = doc.createElementNS(XMLNS_TRUST, 'key')
			root.appendChild(keyelem)
			keyelem.setAttribute('fingerprint', fingerprint)
			for domain in self.keys[fingerprint]:
				domainelem = doc.createElementNS(XMLNS_TRUST, 'domain')
				domainelem.setAttribute('value', domain)
				keyelem.appendChild(domainelem)

		d = basedir.save_config_path(config_site, config_prog)
		fd, tmpname = tempfile.mkstemp(dir = d, prefix = 'trust-')
		tmp = os.fdopen(fd, 'wb')
		doc.writexml(tmp, indent = "", addindent = "  ", newl = "\n")
		tmp.close()

		os.rename(tmpname, os.path.join(d, 'trustdb.xml'))
Example #6
0
 def keys_changed(*unused):
     site, program, name = _save_name
     if site:
         d = basedir.save_config_path(site, program)
         path = os.path.join(d, name)
     else:
         path = choices.save(program, name)
     if path:
         try:
             g.accel_map_save(path)
         except AttributeError:
             print "Error saving keybindings to", path
Example #7
0
File: Menu.py Project: boube/minino
 def keys_changed(*unused):
     site, program, name = _save_name
     if site:
         d = basedir.save_config_path(site, program)
         path = os.path.join(d, name)
     else:
         path = choices.save(program, name)
     if path:
         try:
             g.accel_map_save(path)
         except AttributeError:
             print "Error saving keybindings to", path
Example #8
0
    def save_config(self):
        config = ConfigParser.ConfigParser()
        config.add_section('global')

        config.set('global', 'help_with_testing', self.help_with_testing)
        config.set('global', 'network_use', self.network_use)
        config.set('global', 'freshness', self.freshness)

        path = basedir.save_config_path(config_site, config_prog)
        path = os.path.join(path, 'global')
        config.write(file(path + '.new', 'w'))
        os.rename(path + '.new', path)