Add functions to find apk and tarball paths

This commit is contained in:
Daniel Martí 2013-10-19 12:18:48 +02:00
parent b75d8b7271
commit a9a947af86
2 changed files with 39 additions and 20 deletions

View file

@ -311,8 +311,8 @@ def build_server(app, thisbuild, vcs, build_dir, output_dir, sdk_path, force):
ftp.chdir('/home/vagrant/tmp') ftp.chdir('/home/vagrant/tmp')
else: else:
ftp.chdir('/home/vagrant/unsigned') ftp.chdir('/home/vagrant/unsigned')
apkfile = app['id'] + '_' + thisbuild['vercode'] + '.apk' apkfile = common.getapkname(app,thisbuild)
tarball = app['id'] + '_' + thisbuild['vercode'] + '_src' + '.tar.gz' tarball = common.getsrcname(app,thisbuild)
try: try:
ftp.get(apkfile, os.path.join(output_dir, apkfile)) ftp.get(apkfile, os.path.join(output_dir, apkfile))
ftp.get(tarball, os.path.join(output_dir, tarball)) ftp.get(tarball, os.path.join(output_dir, tarball))
@ -397,9 +397,8 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
# Build the source tarball right before we build the release... # Build the source tarball right before we build the release...
print "Creating source tarball..." print "Creating source tarball..."
tarname = app['id'] + '_' + thisbuild['vercode'] + '_src' tarname = common.getsrcname(app,thisbuild)
tarball = tarfile.open(os.path.join(tmp_dir, tarball = tarfile.open(os.path.join(tmp_dir, tarname), "w:gz")
tarname + '.tar.gz'), "w:gz")
def tarexc(f): def tarexc(f):
for vcs_dir in ['.svn', '.git', '.hg', '.bzr']: for vcs_dir in ['.svn', '.git', '.hg', '.bzr']:
if f.endswith(vcs_dir): if f.endswith(vcs_dir):
@ -625,15 +624,13 @@ def build_local(app, thisbuild, vcs, build_dir, output_dir, srclib_dir, extlib_d
# Copy the unsigned apk to our destination directory for further # Copy the unsigned apk to our destination directory for further
# processing (by publish.py)... # processing (by publish.py)...
dest = os.path.join(output_dir, app['id'] + '_' + dest = common.getapkname(app,thisbuild)
thisbuild['vercode'] + '.apk')
shutil.copyfile(src, dest) shutil.copyfile(src, dest)
# Move the source tarball into the output directory... # Move the source tarball into the output directory...
if output_dir != tmp_dir: if output_dir != tmp_dir:
tarfilename = tarname + '.tar.gz' shutil.move(os.path.join(tmp_dir, tarname),
shutil.move(os.path.join(tmp_dir, tarfilename), os.path.join(output_dir, tarname))
os.path.join(output_dir, tarfilename))
def trybuild(app, thisbuild, build_dir, output_dir, also_check_dir, srclib_dir, extlib_dir, def trybuild(app, thisbuild, build_dir, output_dir, also_check_dir, srclib_dir, extlib_dir,
@ -644,17 +641,16 @@ def trybuild(app, thisbuild, build_dir, output_dir, also_check_dir, srclib_dir,
Returns True if the build was done, False if it wasn't necessary. Returns True if the build was done, False if it wasn't necessary.
""" """
dest = os.path.join(output_dir, app['id'] + '_' + dest_apk = common.getapkname(app,thisbuild)
thisbuild['vercode'] + '.apk')
dest_repo = os.path.join(repo_dir, app['id'] + '_' + dest = os.path.join(output_dir, dest_apk)
thisbuild['vercode'] + '.apk') dest_repo = os.path.join(repo_dir, dest_apk)
if os.path.exists(dest) or (not test and os.path.exists(dest_repo)): if os.path.exists(dest) or (not test and os.path.exists(dest_repo)):
return False return False
if also_check_dir and not test: if also_check_dir and not test:
dest_also = os.path.join(also_check_dir, app['id'] + '_' + dest_also = os.path.join(also_check_dir, dest_apk)
thisbuild['vercode'] + '.apk')
if os.path.exists(dest_also): if os.path.exists(dest_also):
return False return False

View file

@ -464,9 +464,18 @@ def parse_metadata(metafile, **kw):
thisbuild = {} thisbuild = {}
thisbuild['origlines'] = lines thisbuild['origlines'] = lines
thisbuild['version'] = parts[0] thisbuild['version'] = parts[0]
ver = parts[1].split('-')
if len(ver) == 1:
thisbuild['vercode'] = parts[1] thisbuild['vercode'] = parts[1]
thisbuild['subvercode'] = None
elif len(ver) == 2:
thisbuild['vercode'] = ver[0]
thisbuild['subvercode'] = ver[1]
else:
raise MetaDataException("Invalid version code for build in " + metafile.name)
try: try:
testvercode = int(thisbuild['vercode']) testvercode = int(thisbuild['vercode'])
testsubvercode = int(thisbuild['subvercode'])
except: except:
raise MetaDataException("Invalid version code for build in " + metafile.name) raise MetaDataException("Invalid version code for build in " + metafile.name)
thisbuild['commit'] = parts[2] thisbuild['commit'] = parts[2]
@ -623,6 +632,17 @@ def parse_metadata(metafile, **kw):
return thisinfo return thisinfo
def getvercode(build):
if build['subvercode'] is None:
return build['vercode']
return "%s-%s" % (build['vercode'], build['subvercode'])
def getapkname(app, build):
return "%s_%s.apk" % (app['id'], getvercode(build))
def getsrcname(app, build):
return "%s_%s_src.tar.gz" % (app['id'], getvercode(build))
# Write a metadata file. # Write a metadata file.
# #
# 'dest' - The path to the output file # 'dest' - The path to the output file
@ -675,6 +695,7 @@ def write_metadata(dest, app):
writefield('Repo Type') writefield('Repo Type')
writefield('Repo') writefield('Repo')
mf.write('\n') mf.write('\n')
keystoignore = ['version', 'vercode', 'subvercode', 'commit']
for build in app['builds']: for build in app['builds']:
writecomments('build:' + build['version']) writecomments('build:' + build['version'])
mf.write('Build Version:') mf.write('Build Version:')
@ -682,10 +703,12 @@ def write_metadata(dest, app):
# Keeping the original formatting if we loaded it from a file... # Keeping the original formatting if we loaded it from a file...
mf.write('\\\n'.join(build['origlines']) + '\n') mf.write('\\\n'.join(build['origlines']) + '\n')
else: else:
mf.write(build['version'] + ',' + build['vercode'] + ',' + mf.write("%s,%s,%s" % (
build['commit']) build['version'],
getvercode(build),
build['commit']))
for key,value in build.iteritems(): for key,value in build.iteritems():
if key not in ['version', 'vercode', 'commit']: if key not in keystoignore:
mf.write(',' + key + '=' + value) mf.write(',' + key + '=' + value)
mf.write('\n') mf.write('\n')
if len(app['builds']) > 0: if len(app['builds']) > 0: