8 from optparse import OptionParser
11 # pass in dir to make tempdirs in
12 # make tempdir for this worker
13 # create 3 files in that tempdir
14 # return how many pkgs
15 # return on stderr where things went to hell
17 #TODO - take most of read_in_package from createrepo and duplicate it here
18 # so we can do downloads, etc.
19 # then replace callers of read_in_package with forked callers of this
20 # and reassemble at the end
23 parser = OptionParser()
24 parser.add_option('--tmpmdpath', default=None,
25 help="path where the outputs should be dumped for this worker")
26 parser.add_option("--pkgoptions", default=[], action='append',
27 help="pkgoptions in the format of key=value")
28 parser.add_option("--quiet", default=False, action='store_true',
29 help="only output errors and a total")
30 parser.add_option("--verbose", default=False, action='store_true',
31 help="output errors and a total")
32 parser.add_option("--globalopts", default=[], action='append',
33 help="general options in the format of key=value")
36 opts, pkgs = parser.parse_args(args)
37 external_data = {'_packagenumber': 1}
39 if not opts.tmpmdpath:
40 print >> sys.stderr, "tmpmdpath required for destination files"
44 for strs in opts.pkgoptions:
46 if v in ['True', 'true', 'yes', '1', 1]:
48 elif v in ['False', 'false', 'no', '0', 0]:
50 elif v in ['None', 'none', '']:
54 for strs in opts.globalopts:
56 if v in ['True', 'true', 'yes', '1', 1]:
58 elif v in ['False', 'false', 'no', '0', 0]:
60 elif v in ['None', 'none', '']:
65 reldir = external_data['_reldir']
66 ts = rpmUtils.transaction.initReadOnlyTransaction()
67 pri = open(opts.tmpmdpath + '/primary.xml' , 'w')
68 fl = open(opts.tmpmdpath + '/filelists.xml' , 'w')
69 other = open(opts.tmpmdpath + '/other.xml' , 'w')
73 pkgpath = reldir + '/' + pkgfile
74 if not os.path.exists(pkgpath):
75 print >> sys.stderr, "File not found: %s" % pkgpath
79 if not opts.quiet and opts.verbose:
80 print "reading %s" % (pkgfile)
82 pkg = createrepo.yumbased.CreateRepoPackage(ts, package=pkgpath,
83 external_data=external_data)
84 pri.write(pkg.xml_dump_primary_metadata())
85 fl.write(pkg.xml_dump_filelists_metadata())
86 other.write(pkg.xml_dump_other_metadata(clog_limit=
87 globalopts.get('clog_limit', None)))
88 except yum.Errors.YumBaseError, e:
89 print >> sys.stderr, "Error: %s" % e
92 external_data['_packagenumber']+=1
98 if __name__ == "__main__":