Skip to content

Instantly share code, notes, and snippets.

@edubxb
Last active August 29, 2015 14:20
Show Gist options
  • Save edubxb/c19281e53939354913c7 to your computer and use it in GitHub Desktop.
Save edubxb/c19281e53939354913c7 to your computer and use it in GitHub Desktop.
Simple program to read ini files and export values
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Eduardo Bellido Bellido
#
# 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 3 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 <http://www.gnu.org/licenses/>.
import argparse
import ConfigParser
def main():
parser = argparse.ArgumentParser(description='Bla')
parser.add_argument('-f', '--file', action='store', dest='ini_file',
metavar='INI FILE',
help='INI config file to read')
parser.add_argument('-n', '--name', action='store_true',
help='Show property name, not only the value')
parser.add_argument('properties_list', action='store')
args = parser.parse_args()
config = ConfigParser.RawConfigParser()
config.read(args.ini_file)
for prop in args.properties_list.split(','):
section, name = prop.split(":")
value = config.get(section, name)
if args.name:
print name + '=' + value
else:
print value
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment