From 10b93796bd69b081b6826e7d4e4e6b898d18c1c4 Mon Sep 17 00:00:00 2001 From: Pat Riehecky Date: Thu, 8 Oct 2015 13:51:16 -0500 Subject: [PATCH] Allow user to set a ~/.pungirc for some defaults Merges: #64 Signed-off-by: Pat Riehecky --- bin/pungi | 10 ++++++++-- pungi/config.py | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bin/pungi b/bin/pungi index 484494ce..a4ee635c 100755 --- a/bin/pungi +++ b/bin/pungi @@ -21,14 +21,18 @@ import selinux def main(): config = pungi.config.Config() + (opts, args) = get_arguments(config) + # Read the config to create "new" defaults + # reparse command line options so they take precedence + config = pungi.config.Config(pungirc=opts.pungirc) (opts, args) = get_arguments(config) # You must be this high to ride if you're going to do root tasks if os.geteuid () != 0 and (opts.do_all or opts.do_buildinstall): print >> sys.stderr, "You must run pungi as root" return 1 - + if opts.do_all or opts.do_buildinstall: try: enforcing = selinux.security_getenforce() @@ -297,7 +301,9 @@ if __name__ == '__main__': action="callback", callback=set_config, callback_args=(config, ), help='Which files are the release notes -- GPL EULA') parser.add_option("--nomacboot", action="store_true", dest="nomacboot", help='disable setting up macboot as no hfs support ') - + parser.add_option("--pungirc", dest="pungirc", default='~/.pungirc', + action="callback", callback=set_config, callback_args=(config, ), + help='Read pungi options from config file ') (opts, args) = parser.parse_args() diff --git a/pungi/config.py b/pungi/config.py index 417e4a37..e615a25f 100644 --- a/pungi/config.py +++ b/pungi/config.py @@ -31,7 +31,7 @@ MULTILIBCONF = (os.path.join(os.path.dirname(here), 'share', 'multilib') class Config(SafeConfigParser): - def __init__(self): + def __init__(self, pungirc=None): SafeConfigParser.__init__(self) self.add_section('pungi') @@ -67,3 +67,7 @@ class Config(SafeConfigParser): self.set('pungi', 'resolve_deps', "True") self.set('pungi', 'no_dvd', "False") self.set('pungi', 'nomacboot', "False") + + # if missing, self.read() is a noop, else change 'defaults' + if pungirc: + self.read(os.path.expanduser(pungirc))