Add an hacked up option parser

Start on a yum object
This commit is contained in:
jkeating@localhost.localdomain 2006-10-10 18:08:38 -04:00 committed by Jesse Keating
parent 7307757c2e
commit 35a57f82e2

View File

@ -14,26 +14,52 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
import sys import sys
import yum.comps import yum
from optparse import OptionParser
def get_arguments():
# hack job for now, I'm sure this could be better for our uses
usage = "usage: %s [options]" % sys.argv[0]
parser = OptionParser(usage=usage)
parser.add_option("--destdir", default=".", dest="destdir",
help='destination directory (defaults to current directory)')
parser.add_option("--comps", default="comps.xml", dest="comps",
help='comps file to use')
parser.add_option("--yumconf", default="yum.conf", dest="yumconf",
help='yum config file to use')
(opts, args) = parser.parse_args()
#if len(opts) < 1:
# parser.print_help()
# sys.exit(0)
return (opts, args)
def get_packagelist(myComps): def get_packagelist(myComps):
# Get the list of packages from the comps file
pkglist = [] pkglist = []
for group in myComps.groups: for group in myComps.groups:
pkglist += group.packages pkglist += group.packages
return pkglist return pkglist
def create_yumobj(yumconf):
# Create a yum object to act upon
myYum = yum.yumBase()
myYum.doConfigSetup(fn=yumconf)
myYum.doRepoSetup()
return myYum
def main(): def main():
(opts, args) = get_arguments()
try: try:
print sys.argv[1]
compsobj = yum.comps.Comps() compsobj = yum.comps.Comps()
for srcfile in sys.argv[1:]: compsobj.add(opts.comps)
compsobj.add(srcfile)
print get_packagelist(compsobj) print get_packagelist(compsobj)
except IOError: except IOError:
print >> sys.stderr, "gather.py: No such file:\'%s\'" % sys.argv[1] print >> sys.stderr, "gather.py: No such file:\'%s\'" % opts.comps
sys.exit(1) sys.exit(1)
if __name__ == '__main__': if __name__ == '__main__':