--- /dev/null
+******
+Config
+******
+
+.. program-output:: lftools config --help
+
+Commands
+========
+
+.. contents:: Config Commands
+ :local:
+
+get
+---
+
+.. program-output:: lftools config get --help
+
+set
+----
+
+.. program-output:: lftools config set --help
.. toctree::
:maxdepth: 2
+ config
deploy
license
nexus
import click
+from lftools.cli.config import config_sys
from lftools.cli.deploy import deploy
from lftools.cli.jenkins import jenkins_cli
from lftools.cli.license import license
pass
+cli.add_command(config_sys)
cli.add_command(deploy)
cli.add_command(jenkins_cli, name='jenkins')
cli.add_command(license)
--- /dev/null
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+"""CLI interface for config subsystem."""
+
+__author__ = 'Thanh Ha'
+
+
+import click
+
+from lftools import config
+
+
+@click.group(name='config')
+@click.pass_context
+def config_sys(ctx):
+ """Configuration subsystem."""
+ pass
+
+
+@click.command(name='get')
+@click.argument('section', type=str)
+@click.argument('option', type=str, required=False)
+@click.pass_context
+def get_setting(ctx, section, option):
+ """Print section or setting from config file."""
+ result = config.get_setting(section, option)
+ if isinstance(result, list):
+ for i in result:
+ print('{}: {}'.format(i, config.get_setting(section, i)))
+ else:
+ print(result)
+
+
+@click.command(name='set')
+@click.argument('section')
+@click.argument('option')
+@click.argument('value')
+@click.pass_context
+def set_setting(ctx, section, option, value):
+ """Set a setting in the config file."""
+ config.set_setting(section, option, value)
+
+
+config_sys.add_command(get_setting)
+config_sys.add_command(set_setting)
--- /dev/null
+# -*- coding: utf-8 -*-
+# SPDX-License-Identifier: EPL-1.0
+##############################################################################
+# Copyright (c) 2018 The Linux Foundation and others.
+#
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Eclipse Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/epl-v10.html
+##############################################################################
+"""Configuration subsystem for lftools."""
+
+__author__ = 'Thanh Ha'
+
+import sys
+
+from six.moves import configparser
+from xdg import XDG_CONFIG_HOME
+
+LFTOOLS_CONFIG_FILE = '/'.join([XDG_CONFIG_HOME, 'lftools', 'lftools.ini'])
+
+
+def get_config():
+ """Get the config object."""
+ config = configparser.ConfigParser()
+ config.read(LFTOOLS_CONFIG_FILE)
+ return config
+
+
+def get_setting(section, option=None):
+ """Get a configuration from a section."""
+ config = get_config()
+
+ if option:
+ try:
+ return config.get(section, option)
+ except configparser.NoOptionError:
+ print('ERROR: Config option does not exist.')
+ sys.exit(1)
+ except configparser.NoSectionError:
+ print('ERROR: Config section does not exist.')
+ sys.exit(1)
+
+ else:
+ try:
+ return config.options(section)
+ except configparser.NoSectionError:
+ print('ERROR: Config section does not exist.')
+ sys.exit(1)
+
+
+def set_setting(section, option, value):
+ """Save a configuration setting to config file."""
+ config = get_config()
+ config.set(section, option, value)
+
+ with open(LFTOOLS_CONFIG_FILE, 'w') as configfile:
+ config.write(configfile)
pyyaml
requests~=2.18.0
setuptools>=36.5.0
+six~=1.11.0
python-jenkins~=1.1.0
+xdg~=1.0.7;python_version<'3'
+xdg~=3.0.0;python_version>='3'
# workarounds to prevent upstream from breaking us
netifaces==0.10.5