[BUILD] Promote artifacts from strings to their own type

This commit is contained in:
Andrew Raines 2014-06-02 13:21:10 -05:00
parent 5b13ef55f5
commit fc9c6e33c3
1 changed files with 28 additions and 15 deletions

View File

@ -329,21 +329,33 @@ def find_release_version(src_branch):
return match.group(1)
raise RuntimeError('Could not find release version in branch %s' % src_branch)
def artifact_names(release, path = ''):
return [os.path.join(path, 'elasticsearch-%s.%s' % (release, t)) for t in ['deb', 'tar.gz', 'zip']]
class Artifact:
def __init__(self, path, name, ext):
self.path = path # path/to
self.name = name # elasticsearch-9.9.99
self.ext = ext # tar.gz
self.fullpath = None
def fullpath(self):
if not self.fullpath:
self.fullpath = os.path.join(self.path, "%s.%s" % (self.name, self.ext))
return self.fullpath
def artifacts(release, path = ''):
return [Artifact(path, "elasticsearch-%s" % release, t) for t in ['deb', 'tar.gz', 'zip']]
def get_artifacts(release):
common_artifacts = artifact_names(release, 'target/releases/')
for f in common_artifacts:
if not os.path.isfile(f):
raise RuntimeError('Could not find required artifact at %s' % f)
common_artifacts = artifacts(release, 'target/releases/')
for a in common_artifacts:
if not os.path.isfile(a.fullpath):
raise RuntimeError('Could not find required artifact at %s' % a.fullpath)
rpm = os.path.join('target/rpm/elasticsearch/RPMS/noarch/', 'elasticsearch-%s-1.noarch.rpm' % release)
if os.path.isfile(rpm):
log('RPM [%s] contains: ' % rpm)
run('rpm -pqli %s' % rpm)
# this is an oddness of RPM that is attches -1 so we have to rename it
renamed_rpm = os.path.join('target/rpm/elasticsearch/RPMS/noarch/', 'elasticsearch-%s.noarch.rpm' % release)
shutil.move(rpm, renamed_rpm)
renamed_rpm = Artifact('target/rpm/elasticsearch/RPMS/noarch/', 'elasticsearch-%s' % release, 'noarch.rpm')
shutil.move(rpm, renamed_rpm.fullpath)
common_artifacts.append(renamed_rpm)
else:
raise RuntimeError('Could not find required artifact at %s' % rpm)
@ -352,16 +364,17 @@ def get_artifacts(release):
# Generates sha1 checsums for all files
# and returns the checksum files as well
# as the given files in a list
def generate_checksums(files):
def generate_checksums(artifacts):
res = []
for release_file in files:
directory = os.path.dirname(release_file)
file = os.path.basename(release_file)
checksum_file = '%s.sha1.txt' % file
for a in artifacts:
directory = os.path.dirname(a.fullpath)
file = os.path.basename(a.fullpath)
ext = 'sha1.txt'
checksum_file = '%s.%s' % (file, ext)
if os.system('cd %s; shasum %s > %s' % (directory, file, checksum_file)):
raise RuntimeError('Failed to generate checksum for file %s' % release_file)
res = res + [os.path.join(directory, checksum_file), release_file]
raise RuntimeError('Failed to generate checksum for file %s' % a)
res = res + [Artifact(directory, file, ext), a]
return res
def download_and_verify(release, files, plugins=None, base_url='https://download.elasticsearch.org/elasticsearch/elasticsearch'):