aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp/scripts/config.py
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-04-01 20:29:22 +0200
committerGuido Günther <agx@sigxcpu.org>2014-04-01 22:42:13 +0200
commit4c6b06773876a35f55f8f5667af65a917f823757 (patch)
tree8623bdccf7d7d1a0d559bdb8f38dae4af0e652f0 /gbp/scripts/config.py
parent03ada72d54480917c75e05568844e3f596e2cb64 (diff)
Add minimal 'config' command
This only allows to print single config values so far. Closes: #733470
Diffstat (limited to 'gbp/scripts/config.py')
-rwxr-xr-xgbp/scripts/config.py87
1 files changed, 87 insertions, 0 deletions
diff --git a/gbp/scripts/config.py b/gbp/scripts/config.py
new file mode 100755
index 00000000..19966fe9
--- /dev/null
+++ b/gbp/scripts/config.py
@@ -0,0 +1,87 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2014 Guido Guenther <agx@sigxcpu.org>
+# 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, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""Query and display config file values"""
+
+import ConfigParser
+import sys
+import os, os.path
+from gbp.config import (GbpOptionParser, GbpOptionGroup)
+from gbp.errors import GbpError
+import gbp.log
+
+def parse_args(argv):
+ try:
+ parser = GbpOptionParser(command=os.path.basename(argv[0]), prefix='',
+ usage='%prog [options] - display configuration settings')
+ except ConfigParser.ParsingError as err:
+ gbp.log.err(err)
+ return None, None
+
+ parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
+ help="verbose command execution")
+ parser.add_config_file_option(option_name="color", dest="color", type='tristate')
+ parser.add_config_file_option(option_name="color-scheme",
+ dest="color_scheme")
+ return parser.parse_args(argv)
+
+
+def parse_config(command):
+ parser = GbpOptionParser(command)
+ parser.parse_config_files()
+ return parser
+
+
+def print_single_value(query, printer):
+ try:
+ cmd, option = query.split('.')
+ except ValueError:
+ return 2
+
+ parser = parse_config(cmd)
+ value = parser.get_config_file_value(option)
+ printer(value)
+ return 0 if value else 1
+
+
+def single_value_printer(value):
+ if (value):
+ print(value)
+
+
+def main(argv):
+ retval = 0
+
+ (options, args) = parse_args(argv)
+ gbp.log.setup(options.color, options.verbose, options.color_scheme)
+
+ if not args:
+ gbp.log.error("No command given")
+ return 2
+ elif len(args) != 2:
+ gbp.log.error("Can only print a single value")
+ return 2
+ else:
+ query = args[1]
+
+ retval = print_single_value(query, single_value_printer)
+ return retval
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
+
+# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: