~nataliabidart/software-center/lost-in-translation

« back to all changes in this revision

Viewing changes to softwarecenter/config.py

  • Committer: Kiwinote
  • Date: 2012-03-15 22:36:31 UTC
  • mfrom: (2867 trunk)
  • mto: This revision was merged to the branch mainline in revision 2881.
  • Revision ID: kiwinote@gmail.com-20120315223631-lvea6t5sydpkkqni
mergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# py3 compat
20
20
try:
21
21
    from configparser import SafeConfigParser
22
 
    SafeConfigParser # pyflakes
 
22
    SafeConfigParser  # pyflakes
23
23
except ImportError:
24
24
    from ConfigParser import SafeConfigParser
25
25
import os
26
26
 
27
27
from paths import SOFTWARE_CENTER_CONFIG_FILE
28
28
 
 
29
 
29
30
class SoftwareCenterConfig(SafeConfigParser):
 
31
 
30
32
    def __init__(self, config):
31
33
        SafeConfigParser.__init__(self)
32
34
        if not os.path.exists(os.path.dirname(config)):
37
39
        except:
38
40
            # don't crash on a corrupted config file
39
41
            pass
 
42
 
40
43
    def write(self):
41
 
        tmpname = self.configfile+".new"
42
 
        f=open(tmpname, "w")
 
44
        tmpname = self.configfile + ".new"
 
45
        f = open(tmpname, "w")
43
46
        SafeConfigParser.write(self, f)
44
47
        f.close()
45
48
        os.rename(tmpname, self.configfile)
46
 
    
47
 
_software_center_config = None    
 
49
 
 
50
 
 
51
_software_center_config = None
 
52
 
 
53
 
48
54
def get_config(filename=SOFTWARE_CENTER_CONFIG_FILE):
49
55
    """ get the global config class """
50
56
    global _software_center_config
51
57
    if not _software_center_config:
52
58
        _software_center_config = SoftwareCenterConfig(filename)
53
59
    return _software_center_config
54