Add utils.

This commit is contained in:
Chmouel Boudjnah 2013-03-28 18:25:13 +01:00
parent 14bdfd42f3
commit 34fd36a503
1 changed files with 24 additions and 10 deletions

View File

@ -1,5 +1,19 @@
# -*- encoding: utf-8 -*-
__author__ = "Chmouel Boudjnah <chmouel@chmouel.com>"
# -*- coding: utf-8 -*-
# Copyright (C) 2013 eNovance SAS <licensing@enovance.com>
#
# Author: Chmouel Boudjnah <chmouel@enovance.com>
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import ConfigParser
@ -13,12 +27,16 @@ class ConfigurationError(Exception):
pass
def parse_ini(inifile=INIFILE):
if not os.path.exists(inifile):
raise ConfigurationError("Error while parsing inifile")
def parse_ini(inifile):
if os.path.exists(inifile):
fp = open(inifile)
elif type(inifile) is file:
fp = inifile
else:
raise ConfigurationError("Cannot found inifile")
config = ConfigParser.RawConfigParser()
config.read(inifile)
config.readfp(fp)
return config
@ -39,7 +57,3 @@ def get_config(section, option, default=None):
else:
raise ConfigurationError("Invalid configuration, missing "
"section/option: %s/%s" % (section, option))
if __name__ == '__main__':
get_config("foo", "bar")