Trees | Indices | Help |
---|
|
1 # -*- Mode: Python; fill-column: 80 -*- 2 # vi:si:et:sw=4:sts=4:ts=4 3 4 # Flumotion - a streaming media server 5 # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 6 # Copyright (C) 2010,2011 Flumotion Services, S.A. 7 # All rights reserved. 8 # 9 # This file may be distributed and/or modified under the terms of 10 # the GNU Lesser General Public License version 2.1 as published by 11 # the Free Software Foundation. 12 # This file is distributed without any warranty; without even the implied 13 # warranty of merchantability or fitness for a particular purpose. 14 # See "LICENSE.LGPL" in the source distribution for more information. 15 # 16 # Headers in this file shall remain intact. 17 18 19 """Save and restore the settings of the mainwindow""" 20 21 import os 22 from xml.dom import minidom, Node 23 from xml.parsers.expat import ExpatError 24 25 from flumotion.common import log 26 from flumotion.configure import configure 27 28 __version__ = "$Rev$" 29 3032 """ 33 Sets up the settings. Expects a filename where settings 34 will be stored 35 """ 3685 8638 if filename is None: 39 self._filename = os.path.join( 40 configure.cachedir, 41 'gtk-admin-state') 42 else: 43 self._filename = filename 44 self._values = {} 45 self.read()4648 try: 49 tree = minidom.parse(self._filename) 50 node = tree.getElementsByTagName('gtk-admin-state')[0] 51 for elem in node.childNodes: 52 self._values[elem.nodeName] = elem.firstChild.data 53 except (IOError, IndexError, ExpatError), e: 54 log.warning('Cannot read gtl-admin-state %s', 55 log.getExceptionMessage(e))5658 try: 59 f = open(self._filename, 'w') 60 doc = minidom.Document() 61 root = doc.createElement('gtk-admin-state') 62 doc.appendChild(root) 63 for key, value in self._values.iteritems(): 64 self._append(doc, root, key, value) 65 doc.writexml(f) 66 f.close() 67 except IOError, e: 68 log.warning('Cannot find gtk-admin-state: %s', 69 log.getExceptionMessage(e))7072 element = doc.createElement(key) 73 root.appendChild(element) 74 value = doc.createTextNode(value) 75 element.appendChild(value)76 7981 return self._values.get(key, default)8288 return Settings()89
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Tue Aug 13 06:17:17 2013 | http://epydoc.sourceforge.net |