Allow user to set a ~/.pungirc for some defaults

Merges: #64
Signed-off-by: Pat Riehecky <riehecky@fnal.gov>
This commit is contained in:
Pat Riehecky 2015-10-08 13:51:16 -05:00 committed by Lubomír Sedlář
parent 1a16d94dda
commit 10b93796bd
2 changed files with 13 additions and 3 deletions

View File

@ -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()

View File

@ -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))