diff options
author | Jeremy Katz <katzj@redhat.com> | 2009-06-30 16:02:34 -0400 |
---|---|---|
committer | Jeremy Katz <katzj@redhat.com> | 2009-07-01 10:21:37 -0400 |
commit | db6476fb40dd04e13c9a8973b2d00d7c1a74154d (patch) | |
tree | e1b837e5803b9475b2a284669c26ae31bf1570e3 | |
parent | 730ced61e467e10ed620c2a6ee18c7695837a6b8 (diff) | |
download | anaconda-db6476fb40dd04e13c9a8973b2d00d7c1a74154d.tar.gz anaconda-db6476fb40dd04e13c9a8973b2d00d7c1a74154d.tar.xz anaconda-db6476fb40dd04e13c9a8973b2d00d7c1a74154d.zip |
Move simpleconfig (back) into anaconda from rhpl
-rw-r--r-- | desktop.py | 3 | ||||
-rw-r--r-- | instdata.py | 3 | ||||
-rw-r--r-- | language.py | 2 | ||||
-rw-r--r-- | network.py | 4 | ||||
-rw-r--r-- | simpleconfig.py | 88 |
5 files changed, 92 insertions, 8 deletions
diff --git a/desktop.py b/desktop.py index fe34a5ad3..49b7bbefd 100644 --- a/desktop.py +++ b/desktop.py @@ -20,8 +20,7 @@ # import string - -from rhpl.simpleconfig import SimpleConfigFile +from simpleconfig import SimpleConfigFile import logging log = logging.getLogger("anaconda") diff --git a/instdata.py b/instdata.py index 30bdaf69f..07984d5be 100644 --- a/instdata.py +++ b/instdata.py @@ -39,8 +39,7 @@ import users import shlex from flags import * from constants import * - -from rhpl.simpleconfig import SimpleConfigFile +from simpleconfig import SimpleConfigFile import rhpl.keyboard as keyboard from pykickstart.version import versionToString, DEVEL diff --git a/language.py b/language.py index 130790932..78c86ad83 100644 --- a/language.py +++ b/language.py @@ -25,7 +25,7 @@ import string import locale import gettext -from rhpl.simpleconfig import SimpleConfigFile +from simpleconfig import SimpleConfigFile import logging log = logging.getLogger("anaconda") diff --git a/network.py b/network.py index 7cfb39966..5c08e182b 100644 --- a/network.py +++ b/network.py @@ -32,11 +32,9 @@ import socket import struct import os import time -import rhpl import dbus from flags import flags - -from rhpl.simpleconfig import SimpleConfigFile +from simpleconfig import SimpleConfigFile import gettext _ = lambda x: gettext.ldgettext("anaconda", x) diff --git a/simpleconfig.py b/simpleconfig.py new file mode 100644 index 000000000..b3e6c9078 --- /dev/null +++ b/simpleconfig.py @@ -0,0 +1,88 @@ +# +# simpleconifg.py - representation of a simple configuration file (sh-like) +# +# Matt Wilson <msw@redhat.com> +# Jeremy Katz <katzj@redhat.com> +# +# Copyright 1999-2002 Red Hat, Inc. +# +# This software may be freely redistributed under the terms of the GNU +# library public license. +# +# You should have received a copy of the GNU Library Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +import string +import os + +# use our own ASCII only uppercase function to avoid locale issues +# not going to be fast but not important +def uppercase_ASCII_string(str): + newstr = "" + for i in range(0,len(str)): + if str[i] in string.lowercase: + newstr += chr(ord(str[i])-32) + else: + newstr += str[i] + + return newstr + +class SimpleConfigFile: + def __str__ (self): + s = "" + keys = self.info.keys () + keys.sort () + for key in keys: + # FIXME - use proper escaping + if type (self.info[key]) == type(""): + s = s + key + "=\"" + self.info[key] + "\"\n" + return s + + def __init__ (self): + self.info = {} + + def write(self, file): + f = open(file, "w") + f.write(self.__str__()) + f.close() + + def read(self, file): + if not os.access(file, os.R_OK): + return + + f = open(file, "r") + lines = f.readlines() + f.close() + + for line in lines: + fields = line[:-1].split('=', 2) + if len(fields) < 2: + # how am I supposed to know what to do here? + continue + key = uppercase_ASCII_string(fields[0]) + value = fields[1] + # XXX hack + value = value.replace('"', '') + value = value.replace("'", '') + self.info[key] = value + + def set (self, *args): + for (key, data) in args: + self.info[uppercase_ASCII_string(key)] = data + + def unset (self, *keys): + for key in keys: + key = uppercase_ASCII_string(key) + if self.info.has_key (key): + del self.info[key] + + def get (self, key): + key = uppercase_ASCII_string(key) + if self.info.has_key (key): + return self.info[key] + else: + return "" + + |