File: config.py

package info (click to toggle)
software-center 2.0.7debian7
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 4,404 kB
  • ctags: 1,229
  • sloc: python: 7,922; xml: 317; makefile: 17; sh: 14
file content (45 lines) | stat: -rw-r--r-- 1,571 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# Copyright (C) 2009 Canonical
#
# Authors:
#  Andrew Higginson
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; version 3.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import ConfigParser
import os

from paths import *

class SoftwareCenterConfig(ConfigParser.SafeConfigParser):
    def __init__(self, config):
        ConfigParser.SafeConfigParser.__init__(self)
        if not os.path.exists(os.path.dirname(config)):
            os.makedirs(os.path.dirname(config))
        self.configfile = config
        self.read(self.configfile)
    def write(self):
        tmpname = self.configfile+".new"
        f=open(tmpname, "w")
        ConfigParser.SafeConfigParser.write(self, f)
        f.close()
        os.rename(tmpname, self.configfile)
    
_software_center_config = None    
def get_config():
    """ get the global config class """
    global _software_center_config
    if not _software_center_config:
        _software_center_config = SoftwareCenterConfig(SOFTWARE_CENTER_CONFIG_FILE)
    return _software_center_config