]>
git.ipfire.org Git - ipfire-3.x.git/blob - pyfire/src/config.py
2 # simpleconifg.py - representation of a simple configuration file (sh-like)
4 # Matt Wilson <msw@redhat.com>
5 # Jeremy Katz <katzj@redhat.com>
7 # Copyright 1999-2002 Red Hat, Inc.
9 # This software may be freely redistributed under the terms of the GNU
10 # library public license.
12 # You should have received a copy of the GNU Library Public License
13 # along with this program; if not, write to the Free Software
14 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 # use our own ASCII only uppercase function to avoid locale issues
21 # not going to be fast but not important
22 def uppercase_ASCII_string(str):
24 for i
in range(0,len(str)):
25 if str[i
] in string
.lowercase
:
26 newstr
+= chr(ord(str[i
])-32)
35 keys
= self
.info
.keys ()
38 # FIXME - use proper escaping
39 if type(self
.info
[key
]) == type(""):
40 s
= s
+ key
+ "=\"" + self
.info
[key
] + "\"\n"
43 def __init__ (self
, filename
):
45 self
.filename
= filename
48 def write(self
, filename
=None):
50 filename
= self
.filename
51 f
= open(filename
, "w")
52 f
.write(self
.__str
__())
55 def read(self
, filename
=None):
57 filename
= self
.filename
58 if not os
.access(filename
, os
.R_OK
):
61 f
= open(filename
, "r")
66 fields
= line
[:-1].split('=', 2)
68 # how am I supposed to know what to do here?
70 key
= uppercase_ASCII_string(fields
[0])
73 value
= value
.replace('"', '')
74 value
= value
.replace("'", '')
75 self
.info
[key
] = value
78 for (key
, data
) in args
:
79 self
.info
[uppercase_ASCII_string(key
)] = data
81 def unset(self
, *keys
):
83 key
= uppercase_ASCII_string(key
)
84 if self
.info
.has_key (key
):
88 key
= uppercase_ASCII_string(key
)
89 if self
.info
.has_key (key
):