Beispiel #1
0
def dumpRpmRdf(rpm):
    if 'rdf' not in config.options or \
        config.options['rdf_resources'] == 0:
	return -1
    if 'rdf_dir' not in config.options or \
        config.options['rdf_dir'] == None:
	return -1

    rdf_dir = config.options['rdf_dir']
    dir = rpm['dir']

    filename = rpm['path']
    rpmdir = dir['rpmdir']
    if rpmdir[-1] == '/':
	rpmdir = rpmdir[0:-1]
    l = len(rpmdir)
    if filename[0:l] == rpmdir:
	filename = filename[l:]
	subdir=dir['subdir']
	index = string.rfind(filename, '/')
	if index > 0:
	    psubdir = filename[0:index]
	    if psubdir[0] == '/':
		psubdir=psubdir[1:]
	else:
	    psubdir = ''
	ftp = dir['ftp']
	if filename[0] != '/' and ftp[-1] != '/':
	    filename = '/' + filename
    else:
        print("Package %s outside of dist subdir %s" % (filename, rpmdir))
	return -1

    if dir['subdir'] != None:
        if rpm['subdir'] != None:
	    buf = "%s/%s/%s" % (rdf_dir, dir['subdir'], rpm['subdir'])
	else:
	    buf = "%s/%s" % (rdf_dir, dir['subdir'])
    else:
        if rpm['subdir'] != None:
	    buf = "%s/%s" % (rdf_dir, rpm['subdir'])
	else:
	    buf = "%s" % (rdf_dir)
    rpmopen.createDirectory(buf)
    buf = buf + "/" + rpmName(rpm) + ".rdf"

    try:
	rdf = open(buf, "w")
	print("Writing %s" % buf)
    except:
        print("Couldn't save to file %s" % (buf))
        return -1

    deep = string.count(rpm['subdir'], '/') + string.count(dir['subdir'], '/')
    dotdot = "../" * deep

    rdf.write("<?xml version=\"1.0\"?>\n")
    rdf.write("<rdf:RDF xmlns:RDF=\"http://www.w3.org/TR/WD-rdf-syntax#\" xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" xmlns:RPM=\"http://www.rpm.org/\">\n")

    rdf.write("  <rdf:Description about=\"%s%s\">\n" % (ftp, filename))
    rdf.write("    <RPM:Name>%s</RPM:Name>\n" % (rpm['name']))
    rdf.write("    <RPM:Version>%s</RPM:Version>\n" % (rpm['version']))
    rdf.write("    <RPM:Release>%s</RPM:Release>\n" % (rpm['release']))
    if 'url' in rpm and rpm['url'] != None:
	rdf.write("    <RPM:URL>%s</RPM:URL>\n" % (rpm['url']))
    rdf.write("    <RPM:Arch>%s</RPM:Arch>\n" % (rpm['arch']))
    rdf.write("    <RPM:Os>%s</RPM:Os>\n" % (rpm['os']))
    if 'distribution' in rpm and rpm['distribution'] != None:
	rdf.write("    <RPM:Distribution>%s</RPM:Distribution>\n" % (
	          convertXML(rpm['distribution'])))
    else:
	rdf.write("    <RPM:Distribution>Unknown</RPM:Distribution>\n")
    if 'packager' in rpm and rpm['packager'] != None:
	rdf.write("    <RPM:Vendor>%s</RPM:Vendor>\n" % (
	          convertXML(rpm['packager'])))
    else:
	rdf.write("    <RPM:Vendor>Unknown</RPM:Vendor>\n")
    if 'group' in rpm and rpm['group'] != None:
	rdf.write("    <RPM:Group>%s</RPM:Group>\n" % (
	          convertXML(string.strip(rpm['group']))))
    else:
	rdf.write("    <RPM:Group>Unknown</RPM:Group>\n")
    if 'summary' in rpm and rpm['summary'] != None:
	rdf.write("    <RPM:Summary>%s</RPM:Summary>\n" % (
	          convertXML(string.strip(rpm['summary']))))
    else:
	rdf.write("    <RPM:Summary></RPM:Summary>\n")
    if 'description' in rpm and rpm['description'] != None:
	rdf.write("    <RPM:Description>%s</RPM:Description>\n" % (
	          convertXML(string.strip(rpm['description']))))
    else:
	rdf.write("    <RPM:Description></RPM:Description>\n")
    if 'copyright' in rpm and rpm['copyright'] != None:
	rdf.write("    <RPM:Copyright>%s</RPM:Copyright>\n" % (
	          convertXML(string.strip(rpm['copyright']))))
    else:
	rdf.write("    <RPM:Copyright>Unknown</RPM:Copyright>\n")
    if 'changelog' in rpm and rpm['changelog'] != None:
	rdf.write("    <RPM:Changelog>%s</RPM:Changelog>\n" % (
	          convertXML(string.strip(rpm['changelog']))))
    else:
	rdf.write("    <RPM:Changelog>Unknown</RPM:Changelog>\n")
    if 'srcrpm' in rpm and rpm['srcrpm'] != None:
	rdf.write("    <RPM:Sources>%s</RPM:Sources>\n" % (
	          rpm['srcrpm']))
    buf = time.strftime("%c", time.localtime((rpm['time'])))
    rdf.write("    <RPM:BuildDate>%s</RPM:BuildDate>\n" % (buf))
    rdf.write("    <RPM:Date>%s</RPM:Date>\n" % (rpm['time']))
    rdf.write("    <RPM:Size>%s</RPM:Size>\n" % (rpm['size']))
    if 'host' in rpm and rpm['host'] != None:
	rdf.write("    <RPM:BuildHost>%s</RPM:BuildHost>\n" % (
	          convertXML(rpm['host'])))

    if 'files' in rpm and rpm['files'] != None:
	rdf.write("    <RPM:Files>")
	for file in rpm['files']:
	    rdf.write("%s\n" % (convertXML(file)))
	rdf.write("</RPM:Files>\n")
    rdf.write("  </rdf:Description>\n")
    rdf.write("</rdf:RDF>\n")
    rdf.close()
Beispiel #2
0
def dumpRpmHtml(rpm):
    if config.options['html'] == 0:
        return

    dir = rpm['dir']

    if dir['subdir'] != None:
        if rpm['subdir'] != None:
	    buf = "%s/%s/%s" % (dir['dir'], dir['subdir'], rpm['subdir'])
	else:
	    buf = "%s/%s" % (dir['dir'], dir['subdir'])
    else:
        if rpm['subdir'] != None:
	    buf = "%s/%s" % (dir['dir'], rpm['subdir'])
	else:
	    buf = "%s" % (dir['dir'])
    rpmopen.createDirectory(buf)
    buf = buf + "/" + rpmName(rpm) + ".html"

    try:
	html = open(buf, "w")
	print("Writing %s" % buf)
    except:
        print("Couldn't save to file %s" % (buf))
        return

    buf = "%s RPM" % (rpmName(rpm))
    generateHtmlHeader(html, buf, None)
    generateLinks(html)

    if rpm['subdir'] != None:
	html.write("<h1 align=center><a href=\"%s/%s/%s\">\n" % (
	    dir['ftp'], rpm['subdir'], rpm['filename']))
    else:
	html.write("<h1 align=center><a href=\"%s/%s\">\n" % (
	    dir['ftp'], rpm['filename']))
    
    if rpm['arch']:
        if rpm['arch'] == "src":
	    html.write("%s-%s-%s Source RPM</a></h1>\n" % (
	            rpm['name'], rpm['version'], rpm['release']))
        else:
	    html.write("%s-%s-%s RPM for %s</a></h1>\n" % (
		rpm['name'], rpm['version'], rpm['release'], rpm['arch']))
    else:
	html.write("%s-%s-%s RPM</a></h1>\n" % (
            rpm['name'], rpm['version'], rpm['release']))
    

    if dir['ftp']:
        html.write("<h3 align=center>%s <a href=\"%s\">%s</a></h3>\n" % (
	      localizedStrings['LANG_FROM'],
	      dir['ftp'], dir['name']))
    

    html.write("<table align=center border=5 cellspacing=5 cellpadding=5 bgcolor=\"%s\">" % ( dir['color']))
    html.write("<tbody>\n")
    html.write("<tr><td>%s: %s</td>\n" % (
	    localizedStrings['LANG_NAME'],
            rpm['name']))
    html.write("<td>%s: <a href=\"%s/%s\">%s</a></td></tr>\n" % (
	    localizedStrings['LANG_DISTRIBUTION'], config.options['url'],
            distribName(rpm['distribution']),
	    convertHTML(rpm['distribution'])))
    html.write("<tr><td>%s: %s</td>\n" % (
	    localizedStrings['LANG_VERSION'],
            rpm['version']))
    html.write("<td>%s: <a href=\"%s/%s\">%s</a></td></tr>\n" % (
	    localizedStrings['LANG_VENDOR'], config.options['url'],
            vendorName(rpm['vendor']), convertHTML(rpm['vendor'])))
    buf = time.strftime("%c", time.localtime((rpm['time'])))
    html.write("<tr><td>%s: %s</td>\n<td>%s: %s</td></tr>\n" % (
	    localizedStrings['LANG_RELEASE'],
	    rpm['release'],
	    localizedStrings['LANG_BUILD_DATE'],
	    buf))
    
    if config.options['url'] != None:
	html.write("<tr><td>%s: <a href=\"%s/%s\">%s</a></td>\n" % (
		localizedStrings['LANG_GROUP'], config.options['url'],
		groupName(rpm['group']), convertHTML(rpm['group'])))
    else:
	html.write("<tr><td>%s: <a href=\"%s\">%s</a></td>\n" % (
		localizedStrings['LANG_GROUP'],
		groupName(rpm['group']), convertHTML(rpm['group'])))
    html.write("<td>%s: %s</td></tr>\n" % (
	    localizedStrings['LANG_BUILD_HOST'], rpm['host']))
    html.write("<tr><td>%s: %d</td>\n" % (
	    localizedStrings['LANG_SIZE'],
            rpm['size']))
    if dir['ftpsrc']:
	html.write("<td>%s: <a href=\"%s/%s\">%s</a></td></tr>\n" % (
	        localizedStrings['LANG_RPM_SRC'],
		dir['ftpsrc'], rpm['srcrpm'], rpm['srcrpm']))
    else:
	html.write("<td>%s: %s</td></tr>\n" % (
	        localizedStrings['LANG_RPM_SRC'],
		rpm['srcrpm']))
    
    if rpm['packager']:
        email = extractEMail(rpm['packager'])
	if email == None:
	    html.write("<tr><td colspan=\"2\">%s: %s</td></tr>\n" % (
		    localizedStrings['LANG_PACKAGER'],
		    convertHTML(rpm['packager'])))
        else:
	    html.write("<tr><td colspan=\"2\">%s: <a href=\"mailto:%s\">%s</a></td></tr>\n" % (
		    localizedStrings['LANG_PACKAGER'],
		    email, convertHTML(rpm['packager'])))
    
    if rpm['url'] != None:
	html.write("<tr><td colspan=\"2\">%s: <a href=\"%s\">%s</a></td></tr>\n" % (
		localizedStrings['LANG_URL'],
		rpm['url'], rpm['url']))
    html.write("<tr><td colspan=\"2\">%s: %s</td></tr>\n" % (
	    localizedStrings['LANG_SUMMARY'],
            convertHTML(rpm['summary'])))
    html.write("</tbody>\n</table>\n")
    html.write("<pre>%s\n</pre>\n" % ( convertHTML(rpm['description'])))
    if rpm['provides'] != None:
        provides = rpm['provides']
	if len(provides) > 0:
	    html.write("<h3>%s</h3>\n" % (localizedStrings['LANG_PROVIDES']))
	    html.write("<ul>\n")
	    for provide in provides:
		if rpm2html_search != None:
		    html.write("<li><a href=\"%s?query=%s\">%s</a>\n" % (
			rpm2html_search, escapeName(provide), provide))
		elif config.options['url'] != None:
		    html.write("<li><a href=\"%s/%s\">%s</a>\n" % (
			config.options['url'], resourceName(provide), provide))
		else:
		    html.write("<li><a href=\"%s\">%s</a>\n" % (
			   resourceName(provide), provide))
	    html.write("</ul>\n")
	
    if rpm['requires'] != None:
        requires = rpm['requires']
	if len(requires) > 0:
	    html.write("<h3>%s</h3>\n" % (localizedStrings['LANG_REQUIRES']))
	    html.write("<ul>\n")
	    for reqs in requires:
	        (require, cmp, version) = reqs
		if len(require) >= 8 and require[0:7] == 'rpmlib(':
		    continue
		if string.find(require, '(GLIBC') >= 0:
		    continue
		if rpm2html_search != None:
		    html.write("<li><a href=\"%s?query=%s\">%s</a>" % (
			rpm2html_search, escapeName(require), require))
		elif config.options['url'] != None:
		    html.write("<li><a href=\"%s/%s\">%s</a>" % (
			config.options['url'], resourceName(require), require))
		else:
		    html.write("<li><a href=\"%s\">%s</a>" % (
			   resourceName(require), require))
		if cmp != None and version != None:
		    html.write(" %s %s\n" % (html_flags[cmp], version))
		else:
		    html.write("\n")
	    html.write("</ul>\n")


    if rpm['copyright']:
        html.write("<h3>%s</h3>\n" %
	    localizedStrings['LANG_COPYRIGHT'])
	html.write("<pre>%s\n</pre>\n" % (convertHTML(rpm['copyright'])))

    if rpm['md5']:
        html.write("<h3>%s</h3>\n" % (localizedStrings['LANG_SIGNATURES']))
	html.write("<pre>internal MD5: %s</pre>\n" % (rpm['md5']))

    if rpm['changelog']:
        html.write("<h3>%s</h3>\n" % (localizedStrings['LANG_CHANGELOG']))
	html.write("<pre>%s\n</pre>\n" % convertHTML(rpm['changelog']))
    
    html.write("<h3>%s</h3>\n" % (localizedStrings['LANG_FILES']))
    if rpm['files'] == None:
	html.write("<bold>%s</bold>\n" % localizedStrings['LANG_NO_FILES'])
    else:
	html.write("<pre>");
	for file in rpm['files']:
	    html.write("%s\n" % (file))
	html.write("</pre>\n");
    
    generateHtmlFooter(html)
    html.close()