Commit 2f5f5583 authored by Lukas Fleischer's avatar Lukas Fleischer
Browse files

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's avatarLukas Fleischer <lfleischer@archlinux.org>
parent 2915abb9
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)
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')
......
#!/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')
......
#!/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')
......
#!/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')
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment