From ad5ab71551b8d085d138a9fed3ccd18ad48c878a Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Tue, 21 Nov 2017 16:06:44 -0800 Subject: [PATCH] Move ComposerConfig into pylorax.api.config module --- src/pylorax/api/config.py | 56 +++++++++++++++++++++++++++++++++++++++ src/sbin/lorax-composer | 41 +--------------------------- 2 files changed, 57 insertions(+), 40 deletions(-) create mode 100644 src/pylorax/api/config.py diff --git a/src/pylorax/api/config.py b/src/pylorax/api/config.py new file mode 100644 index 00000000..879692a2 --- /dev/null +++ b/src/pylorax/api/config.py @@ -0,0 +1,56 @@ +# +# Copyright (C) 2017 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# +import ConfigParser +import os + +class ComposerConfig(ConfigParser.SafeConfigParser): + def get_default(self, section, option, default): + try: + return self.get(section, option) + except ConfigParser.Error: + return default + + +def configure(conf_file="/etc/lorax/composer.conf"): + """lorax-composer configuration""" + conf = ComposerConfig() + + # set defaults + conf.add_section("composer") + conf.set("composer", "yum_conf", "/var/lib/lorax/composer/yum.conf") + conf.set("composer", "repo_dir", "/var/lib/lorax/composer/repos.d/") + conf.set("composer", "cache_dir", "/var/cache/lorax/composer/yum/") + + conf.add_section("users") + conf.set("users", "root", "1") + + # Enable all available repo files by default + conf.add_section("repos") + conf.set("repos", "use_system_repos", "1") + conf.set("repos", "enabled", "*") + + # read the config file + if os.path.isfile(conf_file): + conf.read(conf_file) + + # Create any missing directories + for section, key in [("composer", "yum_conf"), ("composer", "repo_dir"), ("composer", "cache_dir")]: + path = conf.get(section, key) + if not os.path.isdir(os.path.dirname(path)): + os.makedirs(os.path.dirname(path)) + + return conf diff --git a/src/sbin/lorax-composer b/src/sbin/lorax-composer index dc3b5f91..0b74a674 100755 --- a/src/sbin/lorax-composer +++ b/src/sbin/lorax-composer @@ -24,13 +24,13 @@ pylorax_log = logging.getLogger("pylorax") server_log = logging.getLogger("server") import argparse -import ConfigParser import os import sys from threading import Lock from gevent.wsgi import WSGIServer from pylorax import vernum +from pylorax.api.config import configure from pylorax.api.recipes import open_or_create_repo, commit_recipe_directory from pylorax.api.server import server, GitLock, YumLock from pylorax.api.yumbase import get_base_object @@ -95,45 +95,6 @@ def setup_logging(logfile): server_log.addHandler(fh) -class ComposerConfig(ConfigParser.SafeConfigParser): - def get_default(self, section, option, default): - try: - return self.get(section, option) - except ConfigParser.Error: - return default - - -def configure(conf_file="/etc/lorax/composer.conf"): - """lorax-composer configuration""" - conf = ComposerConfig() - - # set defaults - conf.add_section("composer") - conf.set("composer", "yum_conf", "/var/lib/lorax/composer/yum.conf") - conf.set("composer", "repo_dir", "/var/lib/lorax/composer/repos.d/") - conf.set("composer", "cache_dir", "/var/cache/lorax/composer/yum/") - - conf.add_section("users") - conf.set("users", "root", "1") - - # Enable all available repo files by default - conf.add_section("repos") - conf.set("repos", "use_system_repos", "1") - conf.set("repos", "enabled", "*") - - # read the config file - if os.path.isfile(conf_file): - conf.read(conf_file) - - # Create any missing directories - for section, key in [("composer", "yum_conf"), ("composer", "repo_dir"), ("composer", "cache_dir")]: - path = conf.get(section, key) - if not os.path.isdir(os.path.dirname(path)): - os.makedirs(os.path.dirname(path)) - - return conf - - class LogWrapper(object): """Wrapper for the WSGIServer which only calls write()""" def __init__(self, log_obj):