mirror of
https://github.com/wassname/IndicoIo-python.git
synced 2026-08-11 11:12:45 +08:00
Configparser for indico config file
This commit is contained in:
+27
-3
@@ -1,5 +1,29 @@
|
||||
import os
|
||||
|
||||
def get_api_root():
|
||||
return os.environ.get("INDICO_PRIVATE_CLOUD_URL") or "http://apiv1.indico.io/"
|
||||
api_root = get_api_root()
|
||||
import ConfigParser
|
||||
|
||||
settings = ConfigParser.ConfigParser()
|
||||
|
||||
settings_paths = [
|
||||
os.path.expanduser("~/.indicorc"),
|
||||
os.path.join(os.getcwd(), '.indicorc')
|
||||
]
|
||||
|
||||
settings.read(settings_paths)
|
||||
|
||||
def get_section(parser, section):
|
||||
try:
|
||||
return dict(parser.items(section))
|
||||
except ConfigParser.NoSectionError:
|
||||
return {}
|
||||
|
||||
auth_settings = get_section(settings, 'auth')
|
||||
private_cloud_settings = get_section(settings, 'private_cloud')
|
||||
|
||||
api_root = (
|
||||
os.getenv("INDICO_PRIVATE_CLOUD_URL") or
|
||||
private_cloud_settings.get('url_root') or
|
||||
"http://apiv1.indico.io/"
|
||||
)
|
||||
|
||||
auth = (auth_settings.get('username'), auth_settings.get('password'))
|
||||
|
||||
Reference in New Issue
Block a user