You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by se...@apache.org on 2018/05/19 12:52:41 UTC

[incubator-ponymail] branch master updated: New module to read config file

This is an automated email from the ASF dual-hosted git repository.

sebb pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail.git


The following commit(s) were added to refs/heads/master by this push:
     new 4930c77  New module to read config file
4930c77 is described below

commit 4930c77e2fba3110ed98436da5a5ab7daed93af1
Author: Sebb <se...@apache.org>
AuthorDate: Sat May 19 13:52:40 2018 +0100

    New module to read config file
    
    Assumes ponymail.cfg is in the same (tools/) directory rather
    than in the current directory.
---
 tools/ponymailconfig.py | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/tools/ponymailconfig.py b/tools/ponymailconfig.py
new file mode 100755
index 0000000..a2e45f9
--- /dev/null
+++ b/tools/ponymailconfig.py
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+
+"""
+    common config parsing
+    reads the file ponymail.cfg from the same directory as this file
+
+    How to use:
+
+    from ponymailconfig import PonymailConfig
+    config=PonymailConfig()
+    if config.has_option('elasticsearch', 'user'):
+        ...
+"""
+
+import os.path
+from configparser import RawConfigParser
+
+class PonymailConfig(RawConfigParser):
+
+    def __init__(self,*args, **kwargs):
+        super(self.__class__, self).__init__(*args, **kwargs)
+        path = os.path.dirname(os.path.realpath(__file__))
+        RawConfigParser.read(self, "%s/ponymail.cfg" % path)

-- 
To stop receiving notification emails like this one, please contact
sebb@apache.org.