X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=src%2Fallmydata%2Futil%2Fconfigutil.py;fp=src%2Fallmydata%2Futil%2Fconfigutil.py;h=19f712dce219d725a3bd4c0d5647244379a5a6e7;hb=297271fb2f0f9cb18e69e387994c73c18a7e6ec1;hp=0000000000000000000000000000000000000000;hpb=1913d6d3a4dab0c584c5999ae60bc7b9a4f6d563;p=tahoe-lafs%2Ftahoe-lafs.git diff --git a/src/allmydata/util/configutil.py b/src/allmydata/util/configutil.py new file mode 100644 index 00000000..19f712dc --- /dev/null +++ b/src/allmydata/util/configutil.py @@ -0,0 +1,29 @@ + +from ConfigParser import SafeConfigParser + + +def get_config(tahoe_cfg): + config = SafeConfigParser() + f = open(tahoe_cfg, "rb") + try: + # Skip any initial Byte Order Mark. Since this is an ordinary file, we + # don't need to handle incomplete reads, and can assume seekability. + if f.read(3) != '\xEF\xBB\xBF': + f.seek(0) + config.readfp(f) + finally: + f.close() + return config + +def set_config(config, section, option, value): + if not config.has_section(section): + config.add_section(section) + config.set(section, option, value) + assert config.get(section, option) == value + +def write_config(tahoe_cfg, config): + f = open(tahoe_cfg, "wb") + try: + config.write(f) + finally: + f.close()