extras-repoclosure substrepo,NONE,1.1

Michael Schwendt mschwendt at fedoraproject.org
Fri Sep 19 08:53:36 UTC 2008


Author: mschwendt

Update of /cvs/fedora/extras-repoclosure
In directory cvs1.fedora.phx.redhat.com:/tmp/cvs-serv20791

Added Files:
	substrepo 
Log Message:
add this small helper tool to avoid sed e.g.


--- NEW FILE substrepo ---
#!/usr/bin/python
# -*- mode: Python; indent-tabs-mode: nil; -*-
#
# Small convenience helper to substitute arbitrary variables in
# a Yum .repo definition file and print the result to stdout.
# Author: Michael Schwendt / Licence: GPLv2+

import sys, errno
from optparse import OptionParser
import yum.parser

usage = "Usage: %s [options] [file]" % sys.argv[0]
parser = OptionParser(usage=usage)
parser.add_option("-s", "--subst", default=[], action='append',
                  help="a 'key:value' pair to substitute")
(opts, args) = parser.parse_args()

if not len(args):
    infile = sys.stdin
elif len(args)>1:
    print "ERROR: invalid arguments"
    sys.exit(errno.EINVAL)
else:
    infile = file( args[0] )

vars = {}
for kv in opts.subst:
    key, val = kv.split(':')
    vars[key] = val

for line in infile.readlines():
    sys.stdout.write( yum.parser.varReplace(line,vars) )
infile.close()
sys.exit(0)




More information about the fedora-extras-commits mailing list