writer.py :  » Installer » Zero-Install » zeroinstall-injector-0.47 » zeroinstall » injector » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Installer » Zero Install 
Zero Install » zeroinstall injector 0.47 » zeroinstall » injector » writer.py
"""
Save per-interface configuration information.
"""

# Copyright (C) 2009, Thomas Leonard
# See the README file for details, or visit http://0install.net.

from zeroinstall import _
import os
from xml.dom import minidom,XMLNS_NAMESPACE

from zeroinstall.support import basedir

from zeroinstall.injector.model import escape
from zeroinstall.injector.namespaces import config_site,config_prog,XMLNS_IFACE
from zeroinstall.injector.iface_cache import iface_cache

def _add_impl(parent, impl):
  if impl.user_stability:
    doc = parent.ownerDocument
    node = doc.createElementNS(XMLNS_IFACE, 'implementation')
    parent.appendChild(node)
    node.setAttribute('user-stability', str(impl.user_stability))
    node.setAttribute('id', impl.id)

def save_feed(feed):
  # This is wrong. Feed and interface settings should be saved in separate files.
  save_interface(iface_cache.get_interface(feed.url))

def save_interface(interface):
  user_overrides = basedir.save_config_path(config_site, config_prog, 'user_overrides')

  impl = minidom.getDOMImplementation()
  doc = impl.createDocument(XMLNS_IFACE, 'interface-preferences', 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)
  
  for feed in interface.extra_feeds:
    if feed.user_override:
      elem = doc.createElementNS(XMLNS_IFACE, 'feed')
      root.appendChild(elem)
      elem.setAttribute('src', feed.uri)
      if feed.arch:
        elem.setAttribute('arch', feed.arch)

  import tempfile
  tmp_fd, tmp_name = tempfile.mkstemp(dir = user_overrides)
  try:
    tmp_file = os.fdopen(tmp_fd, 'w')
    doc.writexml(tmp_file, addindent = " ", newl = '\n')
    tmp_file.close()
    path = os.path.join(user_overrides, escape(interface.uri))
    os.rename(tmp_name, path)
  except:
    os.unlink(tmp_name)
    raise
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.