summaryrefslogtreecommitdiffstats
path: root/git-interface
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2016-08-03 20:21:40 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2016-08-05 12:05:22 +0200
commit2f5f5583bec2a0a04424d6bedd763855f308bce6 (patch)
tree11728e9e0405899f1aab60af5daec7aa3e99a0c7 /git-interface
parent2915abb9d35308150ec107c5f4664e116daaf1de (diff)
downloadaurweb-2f5f5583bec2a0a04424d6bedd763855f308bce6.tar.xz
git-interface: Factor out configuration file parsing
Add a new module that automatically locates the configuration file and provides methods to obtain the values of configuration options. Use the new module instead of ConfigParser everywhere. Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
Diffstat (limited to 'git-interface')
-rw-r--r--git-interface/config.py27
-rw-r--r--git-interface/db.py7
-rwxr-xr-xgit-interface/git-auth.py6
-rwxr-xr-xgit-interface/git-serve.py5
-rwxr-xr-xgit-interface/git-update.py5
5 files changed, 32 insertions, 18 deletions
diff --git a/git-interface/config.py b/git-interface/config.py
new file mode 100644
index 0000000..cd6495b
--- /dev/null
+++ b/git-interface/config.py
@@ -0,0 +1,27 @@
+import configparser
+import os
+
+_parser = None
+
+
+def _get_parser():
+ global _parser
+
+ if not _parser:
+ _parser = configparser.RawConfigParser()
+ path = os.path.dirname(os.path.realpath(__file__)) + "/../conf/config"
+ _parser.read(path)
+
+ return _parser
+
+
+def get(section, option):
+ return _get_parser().get(section, option)
+
+
+def getboolean(section, option):
+ return _get_parser().getboolean(section, option)
+
+
+def getint(section, option):
+ return _get_parser().getint(section, option)
diff --git a/git-interface/db.py b/git-interface/db.py
index d3e1e69..c4c7d31 100644
--- a/git-interface/db.py
+++ b/git-interface/db.py
@@ -1,15 +1,12 @@
-import configparser
import mysql.connector
-import os
+
+import config
class Connection:
_conn = None
def __init__(self):
- config = configparser.RawConfigParser()
- config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config")
-
aur_db_host = config.get('database', 'host')
aur_db_name = config.get('database', 'name')
aur_db_user = config.get('database', 'user')
diff --git a/git-interface/git-auth.py b/git-interface/git-auth.py
index 7cd033c..ebdc75c 100755
--- a/git-interface/git-auth.py
+++ b/git-interface/git-auth.py
@@ -1,11 +1,10 @@
#!/usr/bin/python3
-import configparser
import shlex
-import os
import re
import sys
+import config
import db
@@ -24,9 +23,6 @@ def format_command(env_vars, command, ssh_opts, ssh_key):
return msg
-config = configparser.RawConfigParser()
-config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config")
-
valid_keytypes = config.get('auth', 'valid-keytypes').split()
username_regex = config.get('auth', 'username-regex')
git_serve_cmd = config.get('auth', 'git-serve-cmd')
diff --git a/git-interface/git-serve.py b/git-interface/git-serve.py
index ab612f0..6377ffc 100755
--- a/git-interface/git-serve.py
+++ b/git-interface/git-serve.py
@@ -1,16 +1,13 @@
#!/usr/bin/python3
-import configparser
import os
import re
import shlex
import sys
+import config
import db
-config = configparser.RawConfigParser()
-config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config")
-
repo_path = config.get('serve', 'repo-path')
repo_regex = config.get('serve', 'repo-regex')
git_shell_cmd = config.get('serve', 'git-shell-cmd')
diff --git a/git-interface/git-update.py b/git-interface/git-update.py
index b7199e6..9a127a9 100755
--- a/git-interface/git-update.py
+++ b/git-interface/git-update.py
@@ -1,6 +1,5 @@
#!/usr/bin/python3
-import configparser
import os
import pygit2
import re
@@ -10,11 +9,9 @@ import sys
import srcinfo.parse
import srcinfo.utils
+import config
import db
-config = configparser.RawConfigParser()
-config.read(os.path.dirname(os.path.realpath(__file__)) + "/../conf/config")
-
notify_cmd = config.get('notifications', 'notify-cmd')
repo_path = config.get('serve', 'repo-path')