mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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>
This commit is contained in:
parent
2915abb9d3
commit
2f5f5583be
5 changed files with 32 additions and 18 deletions
27
git-interface/config.py
Normal file
27
git-interface/config.py
Normal file
|
@ -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)
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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')
|
||||
|
|
Loading…
Add table
Reference in a new issue