additional fixes for archive import

This commit is contained in:
Mike Bonnet 2007-09-13 14:11:29 -04:00 committed by Mike Bonnet
parent d327821a2a
commit 06a5c125da
4 changed files with 25 additions and 14 deletions

View file

@ -1645,7 +1645,7 @@ def handle_import_archive(options, session, args):
print _("This action requires admin privileges")
return 1
needs_create = True
needs_create = False
buildinfo = session.getBuild(args[0])
if not buildinfo:
@ -1667,11 +1667,15 @@ def handle_import_archive(options, session, args):
print _("No Maven information available to create build for %s, please specify a POM file with --pom" % args[0])
return 1
else:
needs_create = 1
needs_create = True
if needs_create:
if not buildinfo:
buildinfo = koji.parse_NVR(args[0])
if buildinfo['epoch'] == '':
buildinfo['epoch'] = None
else:
buildinfo['epoch'] = int(buildinfo['epoch'])
pominfo = koji.parse_pom(suboptions.pom)
session.createMavenBuild(buildinfo, pominfo['groupId'], pominfo['artifactId'])

View file

@ -650,7 +650,7 @@ CREATE TABLE archivefiles (
archive_id INTEGER NOT NULL REFERENCES archiveinfo (id),
filename TEXT NOT NULL,
size INTEGER NOT NULL,
md5sum TEXT NOT NULL,
md5sum TEXT,
PRIMARY KEY (filename, archive_id)
) WITHOUT OIDS;
CREATE INDEX archivefiles_by_archive_id on archivefiles (archive_id);

View file

@ -3137,16 +3137,15 @@ def import_archive(filepath, buildinfo, buildroot_id=None):
buildinfo: dict of information about the build to associate the archive with (as returned by getBuild())
buildroot_id: the id of the buildroot the archive was built in (may be null)
"""
maveninfo = get_maven_build(buildinfo)
if not maveninfo:
raise koji.GenericError, 'no Maven info for build: %s' % koji.buildLabel(buildinfo)
buildinfo = get_build(buildinfo, strict=True)
maveninfo = get_maven_build(buildinfo, strict=True)
filepath = '%s/%s' % (koji.pathinfo.work(), filepath)
if not os.path.exists(filepath):
raise koji.GenericError, 'no such file: %s' % filepath
filename = koji.fixEncoding(os.path.basename(filepath))
expected = '%(name)s-%(version)s-%(release)s' % build
expected = '%(name)s-%(version)s-%(release)s' % buildinfo
if expected != os.path.splitext(filename)[0]:
raise koji.GenericError, 'filename is not in name-version-release format: %s' % filename
archivetype = get_archive_type(filename, strict=True)
@ -3185,9 +3184,12 @@ def import_zip_archive(archive_id, filepath, buildinfo, maveninfo):
for entry in archive.infolist():
filename = koji.fixEncoding(entry.filename)
size = entry.file_size
m = md5.new()
m.update(archive.read(entry.filename))
md5sum = m.hexdigest()
if size > 0:
m = md5.new()
m.update(archive.read(entry.filename))
md5sum = m.hexdigest()
else:
md5sum = None
insert = """INSERT INTO archivefiles (archive_id, filename, size, md5sum)
VALUES
(%(archive_id)i, %(filename)s, %(size)i, %(md5sum)s)"""

View file

@ -732,9 +732,14 @@ class POMHandler(xml.sax.handler.ContentHandler):
self.tag_content += content
def endElement(self, name):
if len(self.tag_stack) == 2 and self.tag_stack[-2] == 'project' and \
self.tag_stack[-1] in fields:
self.values[self.tag_stack[-1]] = self.tag_content
if len(self.tag_stack) in (2, 3) and self.tag_stack[-1] in self.fields:
if self.tag_stack[-2] == 'parent':
# Only set a value from the "parent" tag if we don't already have
# that value set
if not self.values.has_key(self.tag_stack[-1]):
self.values[self.tag_stack[-1]] = self.tag_content
elif self.tag_stack[-2] == 'project':
self.values[self.tag_stack[-1]] = self.tag_content
self.tag_content = ''
self.tag_stack.pop()
@ -751,7 +756,7 @@ def parse_pom(pomfile):
"""
fields = ('groupId', 'artifactId', 'name', 'version')
values = {}
handler = POMHandler(values)
handler = POMHandler(values, fields)
xml.sax.parse(pomfile, handler, fields)
for field in fields:
if field not in values.keys():